Don't initialize the audio buffer passed to the application's audio callback, SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Thu, 05 Jul 2007 02:24:36 +0000
branchSDL-1.2
changeset 40016831b8723a85
parent 4000 9776ab9063de
child 4002 e905bb5d9bc3
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.
src/audio/SDL_audio.c
     1.1 --- a/src/audio/SDL_audio.c	Wed Jul 04 15:22:47 2007 +0000
     1.2 +++ b/src/audio/SDL_audio.c	Thu Jul 05 02:24:36 2007 +0000
     1.3 @@ -117,6 +117,13 @@
     1.4  };
     1.5  SDL_AudioDevice *current_audio = NULL;
     1.6  
     1.7 +/*
     1.8 + * If non-zero, use legacy behaviour (memset the callback buffer before call).
     1.9 + * Changed to NOT initializing the buffer before the callback in 1.2.12.
    1.10 + * Set environment SDL_AUDIO_MUST_INIT_BUFFERS=1 to get old behaviour.
    1.11 + */
    1.12 +static int must_init_callback_buffer = 0;
    1.13 +
    1.14  /* Various local functions */
    1.15  int SDL_AudioInit(const char *driver_name);
    1.16  void SDL_AudioQuit(void);
    1.17 @@ -190,7 +197,10 @@
    1.18  				stream = audio->fake_stream;
    1.19  			}
    1.20  		}
    1.21 -		SDL_memset(stream, silence, stream_len);
    1.22 +
    1.23 +		if ( must_init_callback_buffer ) {
    1.24 +			SDL_memset(stream, silence, stream_len);
    1.25 +		}
    1.26  
    1.27  		if ( ! audio->paused ) {
    1.28  			SDL_mutexP(audio->mixer_lock);
    1.29 @@ -300,6 +310,9 @@
    1.30  {
    1.31  	SDL_AudioDevice *audio;
    1.32  	int i = 0, idx;
    1.33 +	const char *envr = SDL_getenv("SDL_AUDIO_MUST_INIT_BUFFERS");
    1.34 +
    1.35 +	must_init_callback_buffer = ((envr != NULL) && (SDL_atoi(envr)));
    1.36  
    1.37  	/* Check to make sure we don't overwrite 'current_audio' */
    1.38  	if ( current_audio != NULL ) {