Date: Tue, 17 Feb 2009 14:00:25 +0100
authorSam Lantinga <slouken@libsdl.org>
Mon, 23 Mar 2009 05:21:40 +0000
changeset 3096ae4e80dbe330
parent 3095 75483112b97f
child 3097 0d12e8f1de3c
Date: Tue, 17 Feb 2009 14:00:25 +0100
From: Stefan Klug
Subject: [SDL] Possible bug, paused audio playing garbage

On my WinCE device a paused audio device plays random garbage.
This might also be the issue in the thread "sound cracks with SDL_mixer
and AUDIO_S16LSB"

I don't have that much knowledge of the SDL audio part, but the attached
patch fixes it for me, and collapses two redundant ifs.

I'm not sure if this is the correct way to fix this.
Shouldn't the complete stream conversion part of the RunAudio loop be
dependent on the paused property of the device? (not only the call to
(*fill)(udata, istream, istream_len).

Anyways. Would be great if the patch or a fix could find its way to SVN ;-)

Cheers
Stefan
src/audio/SDL_audio.c
     1.1 --- a/src/audio/SDL_audio.c	Mon Mar 23 02:02:30 2009 +0000
     1.2 +++ b/src/audio/SDL_audio.c	Mon Mar 23 05:21:40 2009 +0000
     1.3 @@ -472,16 +472,12 @@
     1.4                  SDL_StreamRead(&device->streamer, stream, stream_len);
     1.5  
     1.6                  /* Ready current buffer for play and change current buffer */
     1.7 -                if (stream != device->fake_stream) {
     1.8 +                if (stream != device->fake_stream && !device->paused) {
     1.9                      current_audio.impl.PlayDevice(device);
    1.10 -                }
    1.11 -
    1.12 -                /* Wait for an audio buffer to become available */
    1.13 -                if (stream == device->fake_stream) {
    1.14 -                    SDL_Delay((device->spec.samples * 1000) /
    1.15 -                              device->spec.freq);
    1.16 +                    /* Wait for an audio buffer to become available */
    1.17 +                    current_audio.impl.WaitDevice(device);
    1.18                  } else {
    1.19 -                    current_audio.impl.WaitDevice(device);
    1.20 +                    SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
    1.21                  }
    1.22              }
    1.23  
    1.24 @@ -524,15 +520,12 @@
    1.25              }
    1.26  
    1.27              /* Ready current buffer for play and change current buffer */
    1.28 -            if (stream != device->fake_stream) {
    1.29 +            if (stream != device->fake_stream && !device->paused) {
    1.30                  current_audio.impl.PlayDevice(device);
    1.31 -            }
    1.32 -
    1.33 -            /* Wait for an audio buffer to become available */
    1.34 -            if (stream == device->fake_stream) {
    1.35 -                SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
    1.36 +                /* Wait for an audio buffer to become available */
    1.37 +                current_audio.impl.WaitDevice(device);
    1.38              } else {
    1.39 -                current_audio.impl.WaitDevice(device);
    1.40 +            	SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
    1.41              }
    1.42          }
    1.43      }