From 3b1a60c3b23fa509cb2a9d3f2f85eb4d9997724b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 28 Jun 2008 15:13:54 +0000 Subject: Removed obsolete ::clearSoundCallback() code svn-id: r32826 --- backends/platform/gp2x/gp2x.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'backends/platform/gp2x/gp2x.cpp') diff --git a/backends/platform/gp2x/gp2x.cpp b/backends/platform/gp2x/gp2x.cpp index 2d2b4b8078..8735ea757e 100644 --- a/backends/platform/gp2x/gp2x.cpp +++ b/backends/platform/gp2x/gp2x.cpp @@ -478,10 +478,6 @@ bool OSystem_GP2X::setSoundCallback(SoundProc proc, void *param) { return true; } -void OSystem_GP2X::clearSoundCallback() { - SDL_CloseAudio(); -} - int OSystem_GP2X::getOutputSampleRate() const { return _samplesPerSec; } -- cgit v1.2.3 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.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'backends/platform/gp2x/gp2x.cpp') 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; -- cgit v1.2.3 From 86706eb7d7c4a208925beebe5da59c02b8a6f34d Mon Sep 17 00:00:00 2001 From: John Willis Date: Sun, 29 Jun 2008 10:16:20 +0000 Subject: Small GP2X tidy (mostly svn:executable on scripts) and fixes needed to reflect "Patch ##1956946 (Audio::Mixer internal API revision)" svn-id: r32835 --- backends/platform/gp2x/gp2x.cpp | 54 +++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'backends/platform/gp2x/gp2x.cpp') diff --git a/backends/platform/gp2x/gp2x.cpp b/backends/platform/gp2x/gp2x.cpp index 1f330cf2d4..c138f6c54d 100644 --- a/backends/platform/gp2x/gp2x.cpp +++ b/backends/platform/gp2x/gp2x.cpp @@ -444,41 +444,69 @@ void OSystem_GP2X::deleteMutex(MutexRef mutex) { #pragma mark --- Audio --- #pragma mark - +void OSystem_GP2X::mixCallback(void *sys, byte *samples, int len) { + OSystem_GP2X *this_ = (OSystem_GP2X *)sys; + assert(this_); + + if (this_->_mixer) + this_->_mixer->mixCallback(samples, len); +} + void OSystem_GP2X::setupMixer() { SDL_AudioSpec desired; SDL_AudioSpec obtained; - memset(&desired, 0, sizeof(desired)); + //memset(&desired, 0, sizeof(desired)); + // Determine the desired output sampling frequency. _samplesPerSec = 0; - if (ConfMan.hasKey("output_rate")) _samplesPerSec = ConfMan.getInt("output_rate"); - if (_samplesPerSec <= 0) _samplesPerSec = SAMPLES_PER_SEC; + //Quick EVIL Hack - DJWillis _samplesPerSec = 11025; + // Determine the sample buffer size. We want it to store enough data for + // about 1/16th of a second. Note that it must be a power of two. + // So e.g. at 22050 Hz, we request a sample buffer size of 2048. + int samples = 8192; + while (16 * samples >= _samplesPerSec) { + samples >>= 1; + } + + memset(&desired, 0, sizeof(desired)); desired.freq = _samplesPerSec; desired.format = AUDIO_S16SYS; desired.channels = 2; //desired.samples = (uint16)samples; desired.samples = 128; // Samples hack - 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); } - _samplesPerSec = obtained.freq; - SDL_PauseAudio(0); - return true; -} - -int OSystem_GP2X::getOutputSampleRate() const { - return _samplesPerSec; } Audio::Mixer *OSystem_GP2X::getMixer() { -- cgit v1.2.3