From e0fe48032d6e27445a9c963e70cf82bf57b5fd5a Mon Sep 17 00:00:00 2001 From: Alejandro Marzini Date: Sun, 20 Jun 2010 20:19:53 +0000 Subject: Made _sampleRate constant again in Audio::MixerImpl. (And Committing "common/timer.h" that should have been included in r50095) svn-id: r50097 --- backends/mixer/sdl/sdl-mixer.cpp | 56 +++++++++++++++++++++------------------- backends/mixer/sdl/sdl-mixer.h | 3 +++ 2 files changed, 33 insertions(+), 26 deletions(-) (limited to 'backends/mixer') diff --git a/backends/mixer/sdl/sdl-mixer.cpp b/backends/mixer/sdl/sdl-mixer.cpp index e56b64f8ec..490489718d 100644 --- a/backends/mixer/sdl/sdl-mixer.cpp +++ b/backends/mixer/sdl/sdl-mixer.cpp @@ -39,7 +39,33 @@ SdlMixerImpl::SdlMixerImpl(OSystem *system) _soundMutex(0), _soundCond(0), _soundThread(0), _soundThreadIsRunning(false), _soundThreadShouldQuit(false), #endif - MixerImpl(system, SAMPLES_PER_SEC) { + MixerImpl(system, getSamplesPerSec()) { + if (_openAudio) { + setReady(true); + +#if MIXER_DOUBLE_BUFFERING + initThreadedMixer(_obtainedRate.samples * 4); +#endif + + // start the sound system + SDL_PauseAudio(0); + } + else { + setReady(false); + } +} + +SdlMixerImpl::~SdlMixerImpl() { + setReady(false); + + SDL_CloseAudio(); + +#if MIXER_DOUBLE_BUFFERING + deinitThreadedMixer(); +#endif +} + +uint SdlMixerImpl::getSamplesPerSec() { SDL_AudioSpec desired; // Determine the desired output sampling frequency. @@ -67,38 +93,16 @@ SdlMixerImpl::SdlMixerImpl(OSystem *system) if (SDL_OpenAudio(&desired, &_obtainedRate) != 0) { warning("Could not open audio device: %s", SDL_GetError()); - - setSampleRate(samplesPerSec); - - setReady(false); + _openAudio = false; } else { // Note: This should be the obtained output rate, but it seems that at // least on some platforms SDL will lie and claim it did get the rate // even if it didn't. Probably only happens for "weird" rates, though. samplesPerSec = _obtainedRate.freq; debug(1, "Output sample rate: %d Hz", samplesPerSec); - - setSampleRate(samplesPerSec); - - setReady(true); - -#if MIXER_DOUBLE_BUFFERING - initThreadedMixer(_obtainedRate.samples * 4); -#endif - - // start the sound system - SDL_PauseAudio(0); + _openAudio = true; } -} - -SdlMixerImpl::~SdlMixerImpl() { - setReady(false); - - SDL_CloseAudio(); - -#if MIXER_DOUBLE_BUFFERING - deinitThreadedMixer(); -#endif + return samplesPerSec; } #if MIXER_DOUBLE_BUFFERING diff --git a/backends/mixer/sdl/sdl-mixer.h b/backends/mixer/sdl/sdl-mixer.h index 272c3934a6..a21dcfd188 100644 --- a/backends/mixer/sdl/sdl-mixer.h +++ b/backends/mixer/sdl/sdl-mixer.h @@ -51,6 +51,9 @@ public: protected: SDL_AudioSpec _obtainedRate; + bool _openAudio; + + uint getSamplesPerSec(); static void mixSdlCallback(void *s, byte *samples, int len); -- cgit v1.2.3