diff options
-rw-r--r-- | backends/mixer/sdl/sdl-mixer.cpp | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/backends/mixer/sdl/sdl-mixer.cpp b/backends/mixer/sdl/sdl-mixer.cpp index dc0c853808..6afeeaefc6 100644 --- a/backends/mixer/sdl/sdl-mixer.cpp +++ b/backends/mixer/sdl/sdl-mixer.cpp @@ -78,34 +78,49 @@ void SdlMixerManager::init() { if (SDL_OpenAudio(&fmt, &_obtained) != 0) { warning("Could not open audio device: %s", SDL_GetError()); + // The mixer is not marked as ready _mixer = new Audio::MixerImpl(g_system, desired.freq); - assert(_mixer); - _mixer->setReady(false); - } else { - debug(1, "Output sample rate: %d Hz", _obtained.freq); - if (_obtained.freq != desired.freq) - warning("SDL mixer output sample rate: %d differs from desired: %d", _obtained.freq, desired.freq); + return; + } + + // The obtained sample format is not supported by the mixer, call + // SDL_OpenAudio again with NULL as the second argument to force + // SDL to do resampling to the desired audio spec. + if (_obtained.format != desired.format) { + debug(1, "SDL mixer sound format: %d differs from desired: %d", _obtained.format, desired.format); + SDL_CloseAudio(); + + if (SDL_OpenAudio(&fmt, NULL) != 0) { + warning("Could not open audio device: %s", SDL_GetError()); + + // The mixer is not marked as ready + _mixer = new Audio::MixerImpl(g_system, desired.freq); + return; + } - debug(1, "Output buffer size: %d samples", _obtained.samples); - if (_obtained.samples != desired.samples) - warning("SDL mixer output buffer size: %d differs from desired: %d", _obtained.samples, desired.samples); + _obtained = desired; + } + + debug(1, "Output sample rate: %d Hz", _obtained.freq); + if (_obtained.freq != desired.freq) + warning("SDL mixer output sample rate: %d differs from desired: %d", _obtained.freq, desired.freq); - if (_obtained.format != desired.format) - warning("SDL mixer sound format: %d differs from desired: %d", _obtained.format, desired.format); + debug(1, "Output buffer size: %d samples", _obtained.samples); + if (_obtained.samples != desired.samples) + warning("SDL mixer output buffer size: %d differs from desired: %d", _obtained.samples, desired.samples); #ifndef __SYMBIAN32__ - // The SymbianSdlMixerManager does stereo->mono downmixing, - // but otherwise we require stereo output. - if (_obtained.channels != 2) - error("SDL mixer output requires stereo output device"); + // The SymbianSdlMixerManager does stereo->mono downmixing, + // but otherwise we require stereo output. + if (_obtained.channels != 2) + error("SDL mixer output requires stereo output device"); #endif - _mixer = new Audio::MixerImpl(g_system, _obtained.freq); - assert(_mixer); - _mixer->setReady(true); + _mixer = new Audio::MixerImpl(g_system, _obtained.freq); + assert(_mixer); + _mixer->setReady(true); - startAudio(); - } + startAudio(); } SDL_AudioSpec SdlMixerManager::getAudioSpec(uint32 outputRate) { |