aboutsummaryrefslogtreecommitdiff
path: root/backends/mixer/sdl
diff options
context:
space:
mode:
authorBastien Bouclet2015-03-08 13:13:50 +0100
committerBastien Bouclet2015-12-15 20:10:19 +0100
commitf985a039d5dd8ef3d2d5700f4a32928d221836d8 (patch)
tree01edfaedfec93d342562bcb5c21a3a139d848bbb /backends/mixer/sdl
parentb9a107499911873a0f5e5452d292f6541f0f001a (diff)
downloadscummvm-rg350-f985a039d5dd8ef3d2d5700f4a32928d221836d8.tar.gz
scummvm-rg350-f985a039d5dd8ef3d2d5700f4a32928d221836d8.tar.bz2
scummvm-rg350-f985a039d5dd8ef3d2d5700f4a32928d221836d8.zip
SDL: Ensure the audio sample format is supported
When SDL returns an unsupported audio sample format, ask SDL to do resampling to the one ScummVM expects. This is needed for the PS3 which natively only supports 32 bits floating point as a sample format.
Diffstat (limited to 'backends/mixer/sdl')
-rw-r--r--backends/mixer/sdl/sdl-mixer.cpp55
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) {