comparison src/audio/SDL_audio.c @ 4001:6831b8723a85 SDL-1.2

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.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 05 Jul 2007 02:24:36 +0000
parents 8582c6a5ca16
children 000a99b4be87
comparison
equal deleted inserted replaced
4000:9776ab9063de 4001:6831b8723a85
114 &EPOCAudio_bootstrap, 114 &EPOCAudio_bootstrap,
115 #endif 115 #endif
116 NULL 116 NULL
117 }; 117 };
118 SDL_AudioDevice *current_audio = NULL; 118 SDL_AudioDevice *current_audio = NULL;
119
120 /*
121 * If non-zero, use legacy behaviour (memset the callback buffer before call).
122 * Changed to NOT initializing the buffer before the callback in 1.2.12.
123 * Set environment SDL_AUDIO_MUST_INIT_BUFFERS=1 to get old behaviour.
124 */
125 static int must_init_callback_buffer = 0;
119 126
120 /* Various local functions */ 127 /* Various local functions */
121 int SDL_AudioInit(const char *driver_name); 128 int SDL_AudioInit(const char *driver_name);
122 void SDL_AudioQuit(void); 129 void SDL_AudioQuit(void);
123 130
188 stream = audio->GetAudioBuf(audio); 195 stream = audio->GetAudioBuf(audio);
189 if ( stream == NULL ) { 196 if ( stream == NULL ) {
190 stream = audio->fake_stream; 197 stream = audio->fake_stream;
191 } 198 }
192 } 199 }
193 SDL_memset(stream, silence, stream_len); 200
201 if ( must_init_callback_buffer ) {
202 SDL_memset(stream, silence, stream_len);
203 }
194 204
195 if ( ! audio->paused ) { 205 if ( ! audio->paused ) {
196 SDL_mutexP(audio->mixer_lock); 206 SDL_mutexP(audio->mixer_lock);
197 (*fill)(udata, stream, stream_len); 207 (*fill)(udata, stream, stream_len);
198 SDL_mutexV(audio->mixer_lock); 208 SDL_mutexV(audio->mixer_lock);
298 308
299 int SDL_AudioInit(const char *driver_name) 309 int SDL_AudioInit(const char *driver_name)
300 { 310 {
301 SDL_AudioDevice *audio; 311 SDL_AudioDevice *audio;
302 int i = 0, idx; 312 int i = 0, idx;
313 const char *envr = SDL_getenv("SDL_AUDIO_MUST_INIT_BUFFERS");
314
315 must_init_callback_buffer = ((envr != NULL) && (SDL_atoi(envr)));
303 316
304 /* Check to make sure we don't overwrite 'current_audio' */ 317 /* Check to make sure we don't overwrite 'current_audio' */
305 if ( current_audio != NULL ) { 318 if ( current_audio != NULL ) {
306 SDL_AudioQuit(); 319 SDL_AudioQuit();
307 } 320 }