From 768eb2b47d78ad2c51e0d9492fe12b36d54edca0 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 16 Jul 2002 17:39:48 +0000 Subject: [PATCH] Date: Mon, 08 Jul 2002 20:14:52 +0300 From: Martin_Storsj? 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 | 2 ++ mixer.c | 46 +++++++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/CHANGES b/CHANGES index 0ed35a08..9e31e74d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,7 @@ 1.2.5: +Martin Storsjö - Tue Jul 16 10:38:12 PDT 2002 + * Fixed to start playing another sample immediately when one finishes Martin Storsjö - Tue May 28 13:08:29 PDT 2002 * Fixed a volume bug when calling Mix_HaltChannel() on unused channel Xavier Wielemans - Wed Jun 12 14:28:14 EDT 2002 diff --git a/mixer.c b/mixer.c index 57aeabad..72da8567 100644 --- a/mixer.c +++ b/mixer.c @@ -188,37 +188,49 @@ static void mix_channels(void *udata, Uint8 *stream, int len) } } if ( mix_channel[i].playing > 0 ) { - volume = (mix_channel[i].volume*mix_channel[i].chunk->volume) / MIX_MAX_VOLUME; - mixable = mix_channel[i].playing; - if ( mixable > len ) { - mixable = len; - } + int index = 0; + int remaining = len; + while (mix_channel[i].playing > 0 && index < len) { + remaining = len - index; + volume = (mix_channel[i].volume*mix_channel[i].chunk->volume) / MIX_MAX_VOLUME; + mixable = mix_channel[i].playing; + if ( mixable > remaining ) { + mixable = remaining; + } + + mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable); + SDL_MixAudio(stream+index,mix_input,mixable,volume); + if (mix_input != mix_channel[i].samples) + free(mix_input); - mix_input = Mix_DoEffects(i, mix_channel[i].samples, mixable); - SDL_MixAudio(stream,mix_input,mixable,volume); - if (mix_input != mix_channel[i].samples) - free(mix_input); + mix_channel[i].samples += mixable; + mix_channel[i].playing -= mixable; + index += mixable; + + /* rcg06072001 Alert app if channel is done playing. */ + if (!mix_channel[i].playing && !mix_channel[i].looping) { + _Mix_channel_done_playing(i); + } + } - mix_channel[i].samples += mixable; - mix_channel[i].playing -= mixable; /* If looping the sample and we are at its end, make sure we will still return a full buffer */ - while ( mix_channel[i].looping && mixable < len ) { - int remaining = len - mixable; + while ( mix_channel[i].looping && index < len ) { int alen = mix_channel[i].chunk->alen; + remaining = len - index; if (remaining > alen) { remaining = alen; } mix_input = Mix_DoEffects(i, mix_channel[i].chunk->abuf, remaining); - SDL_MixAudio(stream+mixable, mix_input, remaining, volume); + SDL_MixAudio(stream+index, mix_input, remaining, volume); if (mix_input != mix_channel[i].chunk->abuf) free(mix_input); --mix_channel[i].looping; mix_channel[i].samples = mix_channel[i].chunk->abuf + remaining; mix_channel[i].playing = mix_channel[i].chunk->alen - remaining; - mixable += remaining; + index += remaining; } if ( ! mix_channel[i].playing && mix_channel[i].looping ) { if ( --mix_channel[i].looping ) { @@ -227,10 +239,6 @@ static void mix_channels(void *udata, Uint8 *stream, int len) } } - /* rcg06072001 Alert app if channel is done playing. */ - if (!mix_channel[i].playing) { - _Mix_channel_done_playing(i); - } } } }