Merged r3138:3139 from branches/SDL-1.2: Don't init audio callback buffer.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 05 Jul 2007 02:30:10 +0000
changeset 2144665c2669e6a3
parent 2143 e906da4414a3
child 2145 5c14978b1e97
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.)
src/audio/SDL_audio.c
     1.1 --- a/src/audio/SDL_audio.c	Wed Jul 04 08:01:04 2007 +0000
     1.2 +++ b/src/audio/SDL_audio.c	Thu Jul 05 02:30:10 2007 +0000
     1.3 @@ -144,6 +144,13 @@
     1.4      NULL
     1.5  };
     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  static SDL_AudioDevice *
    1.15  get_audio_device(SDL_AudioDeviceID id)
    1.16  {
    1.17 @@ -258,7 +265,6 @@
    1.18  SDL_RunAudio(void *devicep)
    1.19  {
    1.20      SDL_AudioDevice *device = (SDL_AudioDevice *) devicep;
    1.21 -    const int legacy_device = (device == open_devices[0]);
    1.22      Uint8 *stream;
    1.23      int stream_len;
    1.24      void *udata;
    1.25 @@ -303,7 +309,7 @@
    1.26          }
    1.27  
    1.28          /* New code should fill buffer or set it to silence themselves. */
    1.29 -        if (legacy_device) {
    1.30 +        if ( must_init_callback_buffer ) {
    1.31              SDL_memset(stream, silence, stream_len);
    1.32          }
    1.33  
    1.34 @@ -390,6 +396,9 @@
    1.35      int i = 0;
    1.36      int initialized = 0;
    1.37      int tried_to_init = 0;
    1.38 +    const char *envr = SDL_getenv("SDL_AUDIO_MUST_INIT_BUFFERS");
    1.39 +
    1.40 +    must_init_callback_buffer = ((envr != NULL) && (SDL_atoi(envr)));
    1.41  
    1.42      if (SDL_WasInit(SDL_INIT_AUDIO)) {
    1.43          SDL_AudioQuit();        /* shutdown driver if already running. */