aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/gp2x/gp2x.cpp
diff options
context:
space:
mode:
authorJohn Willis2008-06-29 10:16:20 +0000
committerJohn Willis2008-06-29 10:16:20 +0000
commit86706eb7d7c4a208925beebe5da59c02b8a6f34d (patch)
tree4836238d7a11c7a047089798694d675a490dfa30 /backends/platform/gp2x/gp2x.cpp
parent206485ffc676c64134774b9873cd8d333deddfee (diff)
downloadscummvm-rg350-86706eb7d7c4a208925beebe5da59c02b8a6f34d.tar.gz
scummvm-rg350-86706eb7d7c4a208925beebe5da59c02b8a6f34d.tar.bz2
scummvm-rg350-86706eb7d7c4a208925beebe5da59c02b8a6f34d.zip
Small GP2X tidy (mostly svn:executable on scripts) and fixes needed to reflect "Patch ##1956946 (Audio::Mixer internal API revision)"
svn-id: r32835
Diffstat (limited to 'backends/platform/gp2x/gp2x.cpp')
-rw-r--r--backends/platform/gp2x/gp2x.cpp54
1 files changed, 41 insertions, 13 deletions
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() {