aboutsummaryrefslogtreecommitdiff
path: root/backends/mixer
diff options
context:
space:
mode:
Diffstat (limited to 'backends/mixer')
-rw-r--r--backends/mixer/doublebuffersdl/doublebuffersdl-mixer.cpp4
-rw-r--r--backends/mixer/sdl/sdl-mixer.cpp32
-rw-r--r--backends/mixer/sdl/sdl-mixer.h4
-rw-r--r--backends/mixer/sdl13/sdl13-mixer.cpp109
-rw-r--r--backends/mixer/sdl13/sdl13-mixer.h67
-rw-r--r--backends/mixer/symbiansdl/symbiansdl-mixer.cpp6
6 files changed, 209 insertions, 13 deletions
diff --git a/backends/mixer/doublebuffersdl/doublebuffersdl-mixer.cpp b/backends/mixer/doublebuffersdl/doublebuffersdl-mixer.cpp
index 526a01d1bf..3e5b9940e0 100644
--- a/backends/mixer/doublebuffersdl/doublebuffersdl-mixer.cpp
+++ b/backends/mixer/doublebuffersdl/doublebuffersdl-mixer.cpp
@@ -28,7 +28,7 @@ DoubleBufferSDLMixerManager::DoubleBufferSDLMixerManager()
:
_soundMutex(0), _soundCond(0), _soundThread(0),
_soundThreadIsRunning(false), _soundThreadShouldQuit(false) {
-
+
}
DoubleBufferSDLMixerManager::~DoubleBufferSDLMixerManager() {
@@ -45,7 +45,7 @@ void DoubleBufferSDLMixerManager::startAudio() {
// Create two sound buffers
_activeSoundBuf = 0;
- uint bufSize = _obtainedRate.samples * 4;
+ uint bufSize = _obtained.samples * 4;
_soundBufSize = bufSize;
_soundBuffers[0] = (byte *)calloc(1, bufSize);
_soundBuffers[1] = (byte *)calloc(1, bufSize);
diff --git a/backends/mixer/sdl/sdl-mixer.cpp b/backends/mixer/sdl/sdl-mixer.cpp
index 16e7f22db5..001309a777 100644
--- a/backends/mixer/sdl/sdl-mixer.cpp
+++ b/backends/mixer/sdl/sdl-mixer.cpp
@@ -61,18 +61,38 @@ void SdlMixerManager::init() {
// Get the desired audio specs
SDL_AudioSpec desired = getAudioSpec(SAMPLES_PER_SEC);
+ // Needed as SDL_OpenAudio as of SDL-1.2.14 mutates fields in
+ // "desired" if used directly.
+ SDL_AudioSpec fmt = desired;
+
// Start SDL audio with the desired specs
- if (SDL_OpenAudio(&desired, &_obtainedRate) != 0) {
+ if (SDL_OpenAudio(&fmt, &_obtained) != 0) {
warning("Could not open audio device: %s", SDL_GetError());
_mixer = new Audio::MixerImpl(g_system, desired.freq);
- assert(_mixer);
+ assert(_mixer);
_mixer->setReady(false);
} else {
- debug(1, "Output sample rate: %d Hz", _obtainedRate.freq);
+ 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);
+
+ 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);
+
+ if (_obtained.format != desired.format)
+ warning("SDL mixer sound format: %d differs from desired: %d", _obtained.format, desired.format);
+
+#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");
+#endif
- _mixer = new Audio::MixerImpl(g_system, _obtainedRate.freq);
- assert(_mixer);
+ _mixer = new Audio::MixerImpl(g_system, _obtained.freq);
+ assert(_mixer);
_mixer->setReady(true);
startAudio();
@@ -133,7 +153,7 @@ void SdlMixerManager::suspendAudio() {
int SdlMixerManager::resumeAudio() {
if (!_audioSuspended)
return -2;
- if (SDL_OpenAudio(&_obtainedRate, NULL) < 0){
+ if (SDL_OpenAudio(&_obtained, NULL) < 0){
return -1;
}
SDL_PauseAudio(0);
diff --git a/backends/mixer/sdl/sdl-mixer.h b/backends/mixer/sdl/sdl-mixer.h
index 5590c90ab3..6fee26bd1f 100644
--- a/backends/mixer/sdl/sdl-mixer.h
+++ b/backends/mixer/sdl/sdl-mixer.h
@@ -67,13 +67,13 @@ protected:
* The obtained audio specification after opening the
* audio system.
*/
- SDL_AudioSpec _obtainedRate;
+ SDL_AudioSpec _obtained;
/** State of the audio system */
bool _audioSuspended;
/**
- * Returns the desired audio specification
+ * Returns the desired audio specification
*/
virtual SDL_AudioSpec getAudioSpec(uint32 rate);
diff --git a/backends/mixer/sdl13/sdl13-mixer.cpp b/backends/mixer/sdl13/sdl13-mixer.cpp
new file mode 100644
index 0000000000..84777c8bab
--- /dev/null
+++ b/backends/mixer/sdl13/sdl13-mixer.cpp
@@ -0,0 +1,109 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/scummsys.h"
+
+#if defined(SDL_BACKEND)
+
+#include "backends/mixer/sdl13/sdl13-mixer.h"
+#include "common/debug.h"
+#include "common/system.h"
+#include "common/config-manager.h"
+#include "common/textconsole.h"
+
+#ifdef GP2X
+#define SAMPLES_PER_SEC 11025
+#else
+#define SAMPLES_PER_SEC 22050
+#endif
+//#define SAMPLES_PER_SEC 44100
+
+Sdl13MixerManager::Sdl13MixerManager()
+ :
+ SdlMixerManager(),
+ _device(0) {
+
+}
+
+Sdl13MixerManager::~Sdl13MixerManager() {
+ _mixer->setReady(false);
+
+ SDL_CloseAudioDevice(_device);
+
+ delete _mixer;
+}
+
+void Sdl13MixerManager::init() {
+ // Start SDL Audio subsystem
+ if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) {
+ error("Could not initialize SDL: %s", SDL_GetError());
+ }
+
+ // Get the desired audio specs
+ SDL_AudioSpec desired = getAudioSpec(SAMPLES_PER_SEC);
+
+ // Start SDL audio with the desired specs
+ _device = SDL_OpenAudioDevice(NULL, 0, &desired, &_obtained,
+ SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
+
+ if (_device <= 0) {
+ warning("Could not open audio device: %s", SDL_GetError());
+
+ _mixer = new Audio::MixerImpl(g_system, desired.freq);
+ assert(_mixer);
+ _mixer->setReady(false);
+ } else {
+ debug(1, "Output sample rate: %d Hz", _obtained.freq);
+
+ _mixer = new Audio::MixerImpl(g_system, _obtained.freq);
+ assert(_mixer);
+ _mixer->setReady(true);
+
+ startAudio();
+ }
+}
+
+void Sdl13MixerManager::startAudio() {
+ // Start the sound system
+ SDL_PauseAudioDevice(_device, 0);
+}
+
+void Sdl13MixerManager::suspendAudio() {
+ SDL_CloseAudioDevice(_device);
+ _audioSuspended = true;
+}
+
+int Sdl13MixerManager::resumeAudio() {
+ if (!_audioSuspended)
+ return -2;
+
+ _device = SDL_OpenAudioDevice(NULL, 0, &_obtained, NULL, 0);
+ if (_device <= 0) {
+ return -1;
+ }
+
+ SDL_PauseAudioDevice(_device, 0);
+ _audioSuspended = false;
+ return 0;
+}
+
+#endif
diff --git a/backends/mixer/sdl13/sdl13-mixer.h b/backends/mixer/sdl13/sdl13-mixer.h
new file mode 100644
index 0000000000..9e07ea8673
--- /dev/null
+++ b/backends/mixer/sdl13/sdl13-mixer.h
@@ -0,0 +1,67 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BACKENDS_MIXER_SDL13_H
+#define BACKENDS_MIXER_SDL13_H
+
+#include "backends/mixer/sdl/sdl-mixer.h"
+
+/**
+ * SDL mixer manager. It wraps the actual implementation
+ * of the Audio:Mixer used by the engine, and setups
+ * the SDL audio subsystem and the callback for the
+ * audio mixer implementation.
+ */
+class Sdl13MixerManager : public SdlMixerManager {
+public:
+ Sdl13MixerManager();
+ virtual ~Sdl13MixerManager();
+
+ /**
+ * Initialize and setups the mixer
+ */
+ virtual void init();
+
+ /**
+ * Pauses the audio system
+ */
+ virtual void suspendAudio();
+
+ /**
+ * Resumes the audio system
+ */
+ virtual int resumeAudio();
+
+protected:
+
+ /**
+ * The opened SDL audio device
+ */
+ SDL_AudioDeviceID _device;
+
+ /**
+ * Starts SDL audio
+ */
+ virtual void startAudio();
+};
+
+#endif
diff --git a/backends/mixer/symbiansdl/symbiansdl-mixer.cpp b/backends/mixer/symbiansdl/symbiansdl-mixer.cpp
index b2462a1cdf..c911a99b61 100644
--- a/backends/mixer/symbiansdl/symbiansdl-mixer.cpp
+++ b/backends/mixer/symbiansdl/symbiansdl-mixer.cpp
@@ -43,8 +43,8 @@ SymbianSdlMixerManager::~SymbianSdlMixerManager() {
void SymbianSdlMixerManager::startAudio() {
// Need to create mixbuffer for stereo mix to downmix
- if (_obtainedRate.channels != 2) {
- _stereoMixBuffer = new byte [_obtainedRate.size * 2]; // * 2 for stereo values
+ if (_obtained.channels != 2) {
+ _stereoMixBuffer = new byte [_obtained.size * 2]; // * 2 for stereo values
}
SdlMixerManager::startAudio();
@@ -54,7 +54,7 @@ void SymbianSdlMixerManager::callbackHandler(byte *samples, int len) {
assert(_mixer);
#if defined (S60) && !defined(S60V3)
// If not stereo then we need to downmix
- if (_obtainedRate.channels != 2) {
+ if (_obtained.channels != 2) {
_mixer->mixCallback(_stereoMixBuffer, len * 2);
int16 *bitmixDst = (int16 *)samples;