diff options
author | Christopher Page | 2008-07-14 00:10:09 +0000 |
---|---|---|
committer | Christopher Page | 2008-07-14 00:10:09 +0000 |
commit | d2e8d4831e33f9e1c63d53c9dd615a15f67ab995 (patch) | |
tree | 308cc8bb9ab0bc80d006c84b8ff84267355cedcb /backends/platform/gp2x/gp2x.cpp | |
parent | 3ac3e84ecffa967f02eeb497e260a0de08e3d2e7 (diff) | |
parent | ef95c6ff70c1b428ab1d086a9b0b551fc82c8451 (diff) | |
download | scummvm-rg350-d2e8d4831e33f9e1c63d53c9dd615a15f67ab995.tar.gz scummvm-rg350-d2e8d4831e33f9e1c63d53c9dd615a15f67ab995.tar.bz2 scummvm-rg350-d2e8d4831e33f9e1c63d53c9dd615a15f67ab995.zip |
Merged revisions 32744-32745,32747,32750-32759,32762-32764,32769,32777,32783,32785-32786,32789-32791,32798-32799,32801-32807,32809-32812,32816-32817,32819-32821,32823-32830,32832-32836,32838-32844,32846-32850,32852-32854,32858-32859,32865-32868,32873-32874,32879,32883,32895,32899,32902-32904,32910-32912,32923-32924,32930-32931,32938,32940,32948-32949,32951,32960-32964,32966-32970,32972-32974,32976,32978,32983,32986-32990,32992,32994,33002-33004,33006-33007,33009-33010,33014,33017,33021-33023,33030,33033 via svnmerge from
https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/trunk
svn-id: r33051
Diffstat (limited to 'backends/platform/gp2x/gp2x.cpp')
-rw-r--r-- | backends/platform/gp2x/gp2x.cpp | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/backends/platform/gp2x/gp2x.cpp b/backends/platform/gp2x/gp2x.cpp index 2d2b4b8078..c138f6c54d 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 <stdio.h> #include <stdlib.h> @@ -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,45 +444,69 @@ void OSystem_GP2X::deleteMutex(MutexRef mutex) { #pragma mark --- Audio --- #pragma mark - -bool OSystem_GP2X::setSoundCallback(SoundProc proc, void *param) { +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; -} - -void OSystem_GP2X::clearSoundCallback() { - SDL_CloseAudio(); -} - -int OSystem_GP2X::getOutputSampleRate() const { - return _samplesPerSec; } Audio::Mixer *OSystem_GP2X::getMixer() { |