comparison src/audio/SDL_audio.c @ 2144:665c2669e6a3

Merged r3138:3139 from branches/SDL-1.2: Don't init audio callback buffer. (This already had a concession for devices opened via the 1.2 entry points, I've changed it to respect the environment variable and do it for all devices now.)
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 05 Jul 2007 02:30:10 +0000
parents e1a70460c354
children a5f11bc178b4
comparison
equal deleted inserted replaced
2143:e906da4414a3 2144:665c2669e6a3
142 &DART_bootstrap, 142 &DART_bootstrap,
143 #endif 143 #endif
144 NULL 144 NULL
145 }; 145 };
146 146
147 /*
148 * If non-zero, use legacy behaviour (memset the callback buffer before call).
149 * Changed to NOT initializing the buffer before the callback in 1.2.12.
150 * Set environment SDL_AUDIO_MUST_INIT_BUFFERS=1 to get old behaviour.
151 */
152 static int must_init_callback_buffer = 0;
153
147 static SDL_AudioDevice * 154 static SDL_AudioDevice *
148 get_audio_device(SDL_AudioDeviceID id) 155 get_audio_device(SDL_AudioDeviceID id)
149 { 156 {
150 id--; 157 id--;
151 if ((id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL)) { 158 if ((id >= SDL_arraysize(open_devices)) || (open_devices[id] == NULL)) {
256 /* The general mixing thread function */ 263 /* The general mixing thread function */
257 int SDLCALL 264 int SDLCALL
258 SDL_RunAudio(void *devicep) 265 SDL_RunAudio(void *devicep)
259 { 266 {
260 SDL_AudioDevice *device = (SDL_AudioDevice *) devicep; 267 SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
261 const int legacy_device = (device == open_devices[0]);
262 Uint8 *stream; 268 Uint8 *stream;
263 int stream_len; 269 int stream_len;
264 void *udata; 270 void *udata;
265 void (SDLCALL * fill) (void *userdata, Uint8 * stream, int len); 271 void (SDLCALL * fill) (void *userdata, Uint8 * stream, int len);
266 int silence; 272 int silence;
301 stream = device->fake_stream; 307 stream = device->fake_stream;
302 } 308 }
303 } 309 }
304 310
305 /* New code should fill buffer or set it to silence themselves. */ 311 /* New code should fill buffer or set it to silence themselves. */
306 if (legacy_device) { 312 if ( must_init_callback_buffer ) {
307 SDL_memset(stream, silence, stream_len); 313 SDL_memset(stream, silence, stream_len);
308 } 314 }
309 315
310 if (!device->paused) { 316 if (!device->paused) {
311 SDL_mutexP(device->mixer_lock); 317 SDL_mutexP(device->mixer_lock);
388 SDL_AudioInit(const char *driver_name) 394 SDL_AudioInit(const char *driver_name)
389 { 395 {
390 int i = 0; 396 int i = 0;
391 int initialized = 0; 397 int initialized = 0;
392 int tried_to_init = 0; 398 int tried_to_init = 0;
399 const char *envr = SDL_getenv("SDL_AUDIO_MUST_INIT_BUFFERS");
400
401 must_init_callback_buffer = ((envr != NULL) && (SDL_atoi(envr)));
393 402
394 if (SDL_WasInit(SDL_INIT_AUDIO)) { 403 if (SDL_WasInit(SDL_INIT_AUDIO)) {
395 SDL_AudioQuit(); /* shutdown driver if already running. */ 404 SDL_AudioQuit(); /* shutdown driver if already running. */
396 } 405 }
397 406