From 2a9137296f620018f0a49df04e34f47ed86cdedb Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 5 Jul 2007 02:24:36 +0000 Subject: [PATCH] Don't initialize the audio buffer passed to the application's audio callback, since they are expected to entirely fill it with data or silence. For legacy apps that might expect the buffer to already have silence and thus may not fill the buffer in the callback, there's an environment variable to expose the old behaviour. Fixes Bugzilla #416. --HG-- branch : SDL-1.2 extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402411 --- src/audio/SDL_audio.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 2e736323f..e279aad80 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -117,6 +117,13 @@ static AudioBootStrap *bootstrap[] = { }; SDL_AudioDevice *current_audio = NULL; +/* + * If non-zero, use legacy behaviour (memset the callback buffer before call). + * Changed to NOT initializing the buffer before the callback in 1.2.12. + * Set environment SDL_AUDIO_MUST_INIT_BUFFERS=1 to get old behaviour. + */ +static int must_init_callback_buffer = 0; + /* Various local functions */ int SDL_AudioInit(const char *driver_name); void SDL_AudioQuit(void); @@ -190,7 +197,10 @@ int SDLCALL SDL_RunAudio(void *audiop) stream = audio->fake_stream; } } - SDL_memset(stream, silence, stream_len); + + if ( must_init_callback_buffer ) { + SDL_memset(stream, silence, stream_len); + } if ( ! audio->paused ) { SDL_mutexP(audio->mixer_lock); @@ -300,6 +310,9 @@ int SDL_AudioInit(const char *driver_name) { SDL_AudioDevice *audio; int i = 0, idx; + const char *envr = SDL_getenv("SDL_AUDIO_MUST_INIT_BUFFERS"); + + must_init_callback_buffer = ((envr != NULL) && (SDL_atoi(envr))); /* Check to make sure we don't overwrite 'current_audio' */ if ( current_audio != NULL ) {