Date: Mon, 08 Jul 2002 20:14:52 +0300
authorSam Lantinga <slouken@libsdl.org>
Tue, 16 Jul 2002 17:39:48 +0000
changeset 18823c83aaa7373
parent 187 f9cc4c0a0957
child 189 983b27be0ec8
Date: Mon, 08 Jul 2002 20:14:52 +0300
From: Martin_Storsj´┐Ż <martin@martin.st>
Subject: Patch for SDL_mixer

Hi

I made a small patch for SDL_mixer. It enables me to start playing
another sample immediately when one finishes (using the channel_finished
callback) without any small (but hearable) gap. This shouldn't break
anything (I hope). ;)
CHANGES
mixer.c
     1.1 --- a/CHANGES	Wed Jun 26 20:41:47 2002 +0000
     1.2 +++ b/CHANGES	Tue Jul 16 17:39:48 2002 +0000
     1.3 @@ -1,5 +1,7 @@
     1.4  
     1.5  1.2.5:
     1.6 +Martin Storsj÷ - Tue Jul 16 10:38:12 PDT 2002
     1.7 + * Fixed to start playing another sample immediately when one finishes
     1.8  Martin Storsj÷ - Tue May 28 13:08:29 PDT 2002
     1.9   * Fixed a volume bug when calling Mix_HaltChannel() on unused channel
    1.10  Xavier Wielemans - Wed Jun 12 14:28:14 EDT 2002
     2.1 --- a/mixer.c	Wed Jun 26 20:41:47 2002 +0000
     2.2 +++ b/mixer.c	Tue Jul 16 17:39:48 2002 +0000
     2.3 @@ -188,37 +188,49 @@
     2.4  				}
     2.5  			}
     2.6  			if ( mix_channel[i].playing > 0 ) {
     2.7 -				volume = (mix_channel[i].volume*mix_channel[i].chunk->volume) / MIX_MAX_VOLUME;
     2.8 -				mixable = mix_channel[i].playing;
     2.9 -				if ( mixable > len ) {
    2.10 -					mixable = len;
    2.11 +				int index = 0;
    2.12 +				int remaining = len;
    2.13 +				while (mix_channel[i].playing > 0 && index < len) {
    2.14 +					remaining = len - index;
    2.15 +					volume = (mix_channel[i].volume*mix_channel[i].chunk->volume) / MIX_MAX_VOLUME;
    2.16 +					mixable = mix_channel[i].playing;
    2.17 +					if ( mixable > remaining ) {
    2.18 +						mixable = remaining;
    2.19 +					}
    2.20 +
    2.21 +					mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable);
    2.22 +					SDL_MixAudio(stream+index,mix_input,mixable,volume);
    2.23 +					if (mix_input != mix_channel[i].samples)
    2.24 +						free(mix_input);
    2.25 +
    2.26 +					mix_channel[i].samples += mixable;
    2.27 +					mix_channel[i].playing -= mixable;
    2.28 +					index += mixable;
    2.29 +
    2.30 +					/* rcg06072001 Alert app if channel is done playing. */
    2.31 +					if (!mix_channel[i].playing && !mix_channel[i].looping) {
    2.32 +						_Mix_channel_done_playing(i);
    2.33 +					}
    2.34  				}
    2.35  
    2.36 -				mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable);
    2.37 -				SDL_MixAudio(stream,mix_input,mixable,volume);
    2.38 -				if (mix_input != mix_channel[i].samples)
    2.39 -					free(mix_input);
    2.40 -
    2.41 -				mix_channel[i].samples += mixable;
    2.42 -				mix_channel[i].playing -= mixable;
    2.43  				/* If looping the sample and we are at its end, make sure
    2.44  				   we will still return a full buffer */
    2.45 -				while ( mix_channel[i].looping && mixable < len ) {
    2.46 -				    	int remaining = len - mixable;
    2.47 +				while ( mix_channel[i].looping && index < len ) {
    2.48  					int alen = mix_channel[i].chunk->alen;
    2.49 +					remaining = len - index;
    2.50  				    	if (remaining > alen) {
    2.51  						remaining = alen;
    2.52  				    	}
    2.53  
    2.54  					mix_input = Mix_DoEffects(i, mix_channel[i].chunk->abuf, remaining);
    2.55 -					SDL_MixAudio(stream+mixable, mix_input, remaining, volume);
    2.56 +					SDL_MixAudio(stream+index, mix_input, remaining, volume);
    2.57  					if (mix_input != mix_channel[i].chunk->abuf)
    2.58  						free(mix_input);
    2.59  
    2.60  					--mix_channel[i].looping;
    2.61  					mix_channel[i].samples = mix_channel[i].chunk->abuf + remaining;
    2.62  					mix_channel[i].playing = mix_channel[i].chunk->alen - remaining;
    2.63 -					mixable += remaining;
    2.64 +					index += remaining;
    2.65  				}
    2.66  				if ( ! mix_channel[i].playing && mix_channel[i].looping ) {
    2.67  					if ( --mix_channel[i].looping ) {
    2.68 @@ -227,10 +239,6 @@
    2.69  					}
    2.70  				}
    2.71  
    2.72 -				/* rcg06072001 Alert app if channel is done playing. */
    2.73 -				if (!mix_channel[i].playing) {
    2.74 -					_Mix_channel_done_playing(i);
    2.75 -				}
    2.76  			}
    2.77  		}
    2.78  	}