From c45d632f3b8c2d8c8aa46b05db758898de863e97 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 28 Jun 2008 15:28:29 +0000 Subject: Patch ##1956946 (Audio::Mixer internal API revision) with some tweaks svn-id: r32828 --- backends/platform/gp2x/gp2x-common.h | 4 +- backends/platform/gp2x/gp2x.cpp | 7 ++- backends/platform/psp/osys_psp.cpp | 4 +- backends/platform/sdl/sdl.cpp | 51 +++++++++++++-------- backends/platform/sdl/sdl.h | 10 ++--- backends/platform/symbian/src/SymbianOS.cpp | 69 ++++++++++++++++------------- backends/platform/symbian/src/SymbianOS.h | 9 +--- backends/platform/wince/wince-sdl.cpp | 45 ++++++++++++------- backends/platform/wince/wince-sdl.h | 5 +-- 9 files changed, 112 insertions(+), 92 deletions(-) (limited to 'backends/platform') diff --git a/backends/platform/gp2x/gp2x-common.h b/backends/platform/gp2x/gp2x-common.h index 78d1296bc7..7e0ea88e0b 100644 --- a/backends/platform/gp2x/gp2x-common.h +++ b/backends/platform/gp2x/gp2x-common.h @@ -37,7 +37,7 @@ #include namespace Audio { - class Mixer; + class MixerImpl; } namespace Common { @@ -367,7 +367,7 @@ protected: Common::SaveFileManager *_savefile; FilesystemFactory *getFilesystemFactory(); - Audio::Mixer *_mixer; + Audio::MixerImpl *_mixer; SDL_TimerID _timerID; Common::TimerManager *_timer; diff --git a/backends/platform/gp2x/gp2x.cpp b/backends/platform/gp2x/gp2x.cpp index 8735ea757e..1f330cf2d4 100644 --- a/backends/platform/gp2x/gp2x.cpp +++ b/backends/platform/gp2x/gp2x.cpp @@ -40,7 +40,7 @@ #include "backends/timer/default/default-timer.h" #include "backends/plugins/posix/posix-provider.h" #include "backends/fs/posix/posix-fs-factory.h" // for getFilesystemFactory() -#include "sound/mixer.h" +#include "sound/mixer_intern.h" #include #include @@ -225,8 +225,7 @@ void OSystem_GP2X::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(); - setSoundCallback(Audio::Mixer::mixCallback, _mixer); + setupMixer(); } // Create and hook up the timer manager, if none exists yet (we check for @@ -445,7 +444,7 @@ void OSystem_GP2X::deleteMutex(MutexRef mutex) { #pragma mark --- Audio --- #pragma mark - -bool OSystem_GP2X::setSoundCallback(SoundProc proc, void *param) { +void OSystem_GP2X::setupMixer() { SDL_AudioSpec desired; SDL_AudioSpec obtained; diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index aff5373510..2d18b4bfd6 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -34,7 +34,7 @@ #include "backends/timer/default/default-timer.h" #include "graphics/surface.h" #include "graphics/scaler.h" -#include "sound/mixer.h" +#include "sound/mixer_intern.h" #include @@ -99,7 +99,7 @@ OSystem_PSP::~OSystem_PSP() { void OSystem_PSP::initBackend() { _savefile = new DefaultSaveFileManager(); - _mixer = new Audio::Mixer(); + _mixer = new Audio::MixerImpl(this); _timer = new DefaultTimerManager(); setSoundCallback(Audio::Mixer::mixCallback, _mixer); setTimerCallback(&timer_handler, 10); 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; diff --git a/backends/platform/symbian/src/SymbianOS.cpp b/backends/platform/symbian/src/SymbianOS.cpp index d3e92731db..dfeb24d825 100644 --- a/backends/platform/symbian/src/SymbianOS.cpp +++ b/backends/platform/symbian/src/SymbianOS.cpp @@ -173,11 +173,8 @@ void OSystem_SDL_Symbian::quit() { OSystem_SDL::quit(); } -bool OSystem_SDL_Symbian::setSoundCallback(SoundProc proc, void *param) { +void OSystem_SDL_Symbian::setupMixer() { - // First save the proc and param - _sound_proc_param = param; - _sound_proc = proc; SDL_AudioSpec desired; SDL_AudioSpec obtained; @@ -207,48 +204,53 @@ bool OSystem_SDL_Symbian::setSoundCallback(SoundProc proc, void *param) { desired.format = AUDIO_S16SYS; desired.channels = 2; desired.samples = (uint16)samples; -#ifdef S60 desired.callback = symbianMixCallback; desired.userdata = this; -#else - desired.callback = proc; - desired.userdata = param; -#endif + + // 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; - } - // 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; - _channels = obtained.channels; - - // Need to create mixbuffer for stereo mix to downmix - if (_channels != 2) { - _stereo_mix_buffer = new byte [obtained.size*2];//*2 for stereo values + _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; + _channels = obtained.channels; + + // Need to create mixbuffer for stereo mix to downmix + if (_channels != 2) { + _stereo_mix_buffer = new byte [obtained.size*2];//*2 for stereo values + } + + // Tell the mixer that we are ready and start the sound processing + _mixer->setOutputRate(_samplesPerSec); + _mixer->setReady(true); + SDL_PauseAudio(0); } - - SDL_PauseAudio(0); - return true; } /** * The mixer callback function, passed on to OSystem::setSoundCallback(). * This simply calls the mix() method. */ -void OSystem_SDL_Symbian::symbianMixCallback(void *s, byte *samples, int len) { - static_cast (s)->symbianMix(samples,len); -} +void OSystem_SDL_Symbian::symbianMixCallback(void *sys, byte *samples, int len) { + OSystem_SDL_Symbian *this_ = (OSystem_SDL_Symbian *)sys; + assert(this_); + if (!this_->_mixer) + return; -/** - * Actual mixing implementation - */ -void OSystem_SDL_Symbian::symbianMix(byte *samples, int len) { +#ifdef S60 // If not stereo then we need to downmix if (_channels != 2) { - _sound_proc(_sound_proc_param, _stereo_mix_buffer, len * 2); + this_->_mixer->mixCallback(_stereo_mix_buffer, len * 2); + int16 *bitmixDst = (int16 *)samples; int16 *bitmixSrc = (int16 *)_stereo_mix_buffer; @@ -258,9 +260,12 @@ void OSystem_SDL_Symbian::symbianMix(byte *samples, int len) { bitmixSrc += 2; } } else - _sound_proc(_sound_proc_param, samples, len); +#else + this_->_mixer->mixCallback(samples, len); +#endif } + /** * This is an implementation by the remapKey function * @param SDL_Event to remap diff --git a/backends/platform/symbian/src/SymbianOS.h b/backends/platform/symbian/src/SymbianOS.h index 77e42cd476..71d24f6286 100644 --- a/backends/platform/symbian/src/SymbianOS.h +++ b/backends/platform/symbian/src/SymbianOS.h @@ -58,7 +58,7 @@ public: // This function is overridden by the symbian port in order to provide MONO audio // downmix is done by supplying our own audiocallback // - virtual bool setSoundCallback(SoundProc proc, void *param); // overloaded by CE backend + virtual void setupMixer(); // overloaded by CE backend // Overloaded from SDL_Commmon void quit(); @@ -70,11 +70,6 @@ protected: // static void symbianMixCallback(void *s, byte *samples, int len); - // - // Actual mixing implementation - // - void symbianMix(byte *samples, int len); - virtual FilesystemFactory *getFilesystemFactory(); public: // vibration support @@ -121,8 +116,6 @@ protected: // Audio int _channels; - SoundProc _sound_proc; - void *_sound_proc_param; byte *_stereo_mix_buffer; // Used to handle joystick navi zones diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp index 8cf5fac279..470c4ef435 100644 --- a/backends/platform/wince/wince-sdl.cpp +++ b/backends/platform/wince/wince-sdl.cpp @@ -35,7 +35,7 @@ #include "base/main.h" #include "base/plugins.h" -#include "sound/mixer.h" +#include "sound/mixer_intern.h" #include "sound/fmopl.h" #include "backends/timer/default/default-timer.h" @@ -404,7 +404,7 @@ void OSystem_WINCE3::initBackend() // Instantiate our own sound mixer // mixer init is postponed until a game engine is selected. if (_mixer == 0) { - _mixer = new Audio::Mixer(); + _mixer = new Audio::Mixer(this); } // Create the timer. CE SDL does not support multiple timers (SDL_AddTimer). @@ -770,7 +770,7 @@ void OSystem_WINCE3::create_toolbar() { _toolbarHandler.setVisible(false); } -bool OSystem_WINCE3::setSoundCallback(SoundProc proc, void *param) { +void OSystem_WINCE3::setupMixer(SoundProc proc, void *param) { SDL_AudioSpec desired; int thread_priority; @@ -785,12 +785,16 @@ bool OSystem_WINCE3::setSoundCallback(SoundProc proc, void *param) { desired.channels = 2; desired.samples = 128; desired.callback = private_sound_proc; - desired.userdata = param; + desired.userdata = this; + + // Create the mixer instance + assert(!_mixer); + _mixer = new Audio::MixerImpl(this); + assert(_mixer); // Add sound thread priority - if (!ConfMan.hasKey("sound_thread_priority")) { + if (!ConfMan.hasKey("sound_thread_priority")) thread_priority = THREAD_PRIORITY_NORMAL; - } else thread_priority = ConfMan.getInt("sound_thread_priority"); @@ -799,16 +803,24 @@ bool OSystem_WINCE3::setSoundCallback(SoundProc proc, void *param) { SDL_CloseAudio(); if (SDL_OpenAudio(&desired, NULL) != 0) { warning("Could not open audio device: %s", SDL_GetError()); - return false; - } - else + _mixer->setReady(false); + + } else { debug(1, "Sound opened OK, mixing at %d Hz", _sampleRate); - SDL_PauseAudio(0); - return true; + + // Tell the mixer that we are ready and start the sound processing + _mixer->setOutputRate(_sampleRate); + _mixer->setReady(true); + SDL_PauseAudio(0); + } } void OSystem_WINCE3::private_sound_proc(void *param, byte *buf, int len) { - (*_originalSoundProc)(param, buf, len); + OSystem_WINCE3 *this_ = (OSystem_WINCE3 *)param; + assert(this_); + + if (this_->_mixer) + this_->_mixer->mixCallback(buf, len); if (!_soundMaster) memset(buf, 0, len); } @@ -838,7 +850,7 @@ bool OSystem_WINCE3::checkOggHighSampleRate() { } #endif -void OSystem_WINCE3::get_sample_rate() { +void OSystem_WINCE3::compute_sample_rate() { // Force at least medium quality FM synthesis for FOTAQ Common::String gameid(ConfMan.get("gameid")); if (gameid == "queen") { @@ -875,9 +887,8 @@ void OSystem_WINCE3::setWindowCaption(const char *caption) { //update_game_settings(); // finalize mixer init - get_sample_rate(); - bool result = setSoundCallback(Audio::Mixer::mixCallback, _mixer); - _mixer->setReady(result); + compute_sample_rate(); + setupMixer(); // handle the actual event OSystem_SDL::setWindowCaption(caption); @@ -1050,7 +1061,7 @@ void OSystem_WINCE3::update_game_settings() { } } - get_sample_rate(); + compute_sample_rate(); } void OSystem_WINCE3::initSize(uint w, uint h) { diff --git a/backends/platform/wince/wince-sdl.h b/backends/platform/wince/wince-sdl.h index daa7e832f6..8853c156d8 100644 --- a/backends/platform/wince/wince-sdl.h +++ b/backends/platform/wince/wince-sdl.h @@ -82,7 +82,7 @@ public: // Overloaded from SDL_Commmon void quit(); // Overloaded from SDL_Commmon (master volume and sample rate subtleties) - bool setSoundCallback(SoundProc proc, void *param); + void setupMixer(); // Overloaded from OSystem //void engineInit(); void getTimeAndDate(struct tm &t) const; @@ -160,13 +160,12 @@ private: #endif static void private_sound_proc(void *param, byte *buf, int len); - static SoundProc _originalSoundProc; bool update_scalers(); void create_toolbar(); void update_game_settings(); void check_mappings(); - void get_sample_rate(); + void compute_sample_rate(); void retrieve_mouse_location(int &x, int &y); -- cgit v1.2.3