Let the music-finished hook start a new track without a skip in the audio.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 15 Jun 2011 03:41:31 -0400
changeset 509777497efacaa
parent 508 de8e7a4f5936
child 510 3a4c352a9a00
Let the music-finished hook start a new track without a skip in the audio.

Previously, there'd be no more music mixed until the next SDL audio callback
fired. Now if the hook (re)starts a track, it'll start mixing right away,
into whatever space is left in the callback where the hook was called.

This is useful if you have an mp3 that, after one playthrough, is replaced
with a looping mp3 that contains the rest of the song on repeat. No more gap
between the two.
music.c
     1.1 --- a/music.c	Sun Jun 05 15:32:32 2011 +0300
     1.2 +++ b/music.c	Wed Jun 15 03:41:31 2011 -0400
     1.3 @@ -253,10 +253,10 @@
     1.4  			}
     1.5  		}
     1.6  		
     1.7 -		if (music_halt_or_loop() == 0)
     1.8 +		music_halt_or_loop();
     1.9 +		if (!music_internal_playing())
    1.10  			return;
    1.11 -		
    1.12 -		
    1.13 +
    1.14  		switch (music_playing->type) {
    1.15  #ifdef CMD_MUSIC
    1.16  			case MUS_CMD:
    1.17 @@ -324,8 +324,10 @@
    1.18  
    1.19  skip:
    1.20  	/* Handle seamless music looping */
    1.21 -	if (left > 0 && left < len && music_halt_or_loop()) {
    1.22 -		music_mixer(udata, stream+(len-left), left);
    1.23 +	if (left > 0 && left < len) {
    1.24 +		music_halt_or_loop();
    1.25 +		if (music_internal_playing())
    1.26 +			music_mixer(udata, stream+(len-left), left);
    1.27  	}
    1.28  }
    1.29