aboutsummaryrefslogtreecommitdiff
path: root/backends/mixer/sdl/sdl-mixer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backends/mixer/sdl/sdl-mixer.cpp')
-rw-r--r--backends/mixer/sdl/sdl-mixer.cpp59
1 files changed, 38 insertions, 21 deletions
diff --git a/backends/mixer/sdl/sdl-mixer.cpp b/backends/mixer/sdl/sdl-mixer.cpp
index dc0c853808..0ca3231892 100644
--- a/backends/mixer/sdl/sdl-mixer.cpp
+++ b/backends/mixer/sdl/sdl-mixer.cpp
@@ -30,8 +30,10 @@
#include "common/config-manager.h"
#include "common/textconsole.h"
-#ifdef GP2X
+#if defined(GP2X)
#define SAMPLES_PER_SEC 11025
+#elif defined(PLAYSTATION3)
+#define SAMPLES_PER_SEC 48000
#else
#define SAMPLES_PER_SEC 44100
#endif
@@ -78,34 +80,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) {