diff options
author | Max Horn | 2008-06-28 15:28:29 +0000 |
---|---|---|
committer | Max Horn | 2008-06-28 15:28:29 +0000 |
commit | c45d632f3b8c2d8c8aa46b05db758898de863e97 (patch) | |
tree | 7b8fee1589eb6a733aea389b305752ee7d63562b /backends/platform/sdl | |
parent | e68efca5a19fd738a78a61ea21efd19280521f31 (diff) | |
download | scummvm-rg350-c45d632f3b8c2d8c8aa46b05db758898de863e97.tar.gz scummvm-rg350-c45d632f3b8c2d8c8aa46b05db758898de863e97.tar.bz2 scummvm-rg350-c45d632f3b8c2d8c8aa46b05db758898de863e97.zip |
Patch ##1956946 (Audio::Mixer internal API revision) with some tweaks
svn-id: r32828
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 51 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 10 |
2 files changed, 37 insertions, 24 deletions
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 60f8d3c95c..290fe63663 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -30,7 +30,7 @@ #include "backends/saves/default/default-saves.h" #include "backends/timer/default/default-timer.h" -#include "sound/mixer.h" +#include "sound/mixer_intern.h" #include "icons/scummvm.xpm" @@ -131,9 +131,7 @@ void OSystem_SDL::initBackend() { // Create and hook up the mixer, if none exists yet (we check for this to // allow subclasses to provide their own). if (_mixer == 0) { - _mixer = new Audio::Mixer(); - bool result = setSoundCallback(Audio::Mixer::mixCallback, _mixer); - _mixer->setReady(result); + setupMixer(); } // Create and hook up the timer manager, if none exists yet (we check for @@ -391,7 +389,15 @@ void OSystem_SDL::deleteMutex(MutexRef mutex) { #pragma mark --- Audio --- #pragma mark - -bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) { +void OSystem_SDL::mixCallback(void *sys, byte *samples, int len) { + OSystem_SDL *this_ = (OSystem_SDL *)sys; + assert(this_); + + if (this_->_mixer) + this_->_mixer->mixCallback(samples, len); +} + +void OSystem_SDL::setupMixer() { SDL_AudioSpec desired; SDL_AudioSpec obtained; @@ -415,23 +421,30 @@ bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) { desired.format = AUDIO_S16SYS; desired.channels = 2; desired.samples = (uint16)samples; - desired.callback = proc; - desired.userdata = param; + desired.callback = mixCallback; + desired.userdata = this; + + // Create the mixer instance + assert(!_mixer); + _mixer = new Audio::MixerImpl(this); + assert(_mixer); + if (SDL_OpenAudio(&desired, &obtained) != 0) { warning("Could not open audio device: %s", SDL_GetError()); - return false; + _samplesPerSec = 0; + _mixer->setReady(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 = obtained.freq; + debug(1, "Output sample rate: %d Hz", _samplesPerSec); + + // Tell the mixer that we are ready and start the sound processing + _mixer->setOutputRate(_samplesPerSec); + _mixer->setReady(true); + SDL_PauseAudio(0); } - // 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 = obtained.freq; - debug(1, "Output sample rate: %d Hz", _samplesPerSec); - SDL_PauseAudio(0); - return true; -} - -int OSystem_SDL::getOutputSampleRate() const { - return _samplesPerSec; } Audio::Mixer *OSystem_SDL::getMixer() { diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 2cbadae2f4..8a94a17b00 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -38,7 +38,7 @@ namespace Audio { - class Mixer; + class MixerImpl; } namespace Common { @@ -134,8 +134,9 @@ public: virtual bool pollEvent(Common::Event &event); // overloaded by CE backend // Set function that generates samples - typedef void (*SoundProc)(void *param, byte *buf, int len); - virtual bool setSoundCallback(SoundProc proc, void *param); // overloaded by CE backend + virtual void setupMixer(); + static void mixCallback(void *s, byte *samples, int len); + virtual Audio::Mixer *getMixer(); // Poll CD status @@ -186,7 +187,6 @@ public: virtual void setWindowCaption(const char *caption); virtual bool openCD(int drive); - virtual int getOutputSampleRate() const; virtual bool hasFeature(Feature f); virtual void setFeatureState(Feature f, bool enable); @@ -371,7 +371,7 @@ protected: Common::SaveFileManager *_savefile; - Audio::Mixer *_mixer; + Audio::MixerImpl *_mixer; SDL_TimerID _timerID; Common::TimerManager *_timer; |