aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorTorbjörn Andersson2004-07-16 10:24:29 +0000
committerTorbjörn Andersson2004-07-16 10:24:29 +0000
commit70f8f689a152aee9a599c310a09da0a72508af6d (patch)
treeb6151287e1a67cb5eae6efd00333dc0ddf200753 /backends
parent078dc6220f2f2cb829429c1075c9c66bd0f717c3 (diff)
downloadscummvm-rg350-70f8f689a152aee9a599c310a09da0a72508af6d.tar.gz
scummvm-rg350-70f8f689a152aee9a599c310a09da0a72508af6d.tar.bz2
scummvm-rg350-70f8f689a152aee9a599c310a09da0a72508af6d.zip
Applied patch #957544 to make output sample rate configurable at runtime.
svn-id: r14225
Diffstat (limited to 'backends')
-rw-r--r--backends/sdl/sdl-common.h3
-rw-r--r--backends/sdl/sdl.cpp31
2 files changed, 30 insertions, 4 deletions
diff --git a/backends/sdl/sdl-common.h b/backends/sdl/sdl-common.h
index 02a9244046..10f6c8b5e4 100644
--- a/backends/sdl/sdl-common.h
+++ b/backends/sdl/sdl-common.h
@@ -169,6 +169,9 @@ protected:
SDL_Surface *_tmpscreen;
bool _overlayVisible;
+ // Audio
+ int _samplesPerSec;
+
// CD Audio
SDL_CD *_cdrom;
int cd_track, cd_num_loops, cd_start_frame, cd_duration;
diff --git a/backends/sdl/sdl.cpp b/backends/sdl/sdl.cpp
index a15978f791..c7292ad554 100644
--- a/backends/sdl/sdl.cpp
+++ b/backends/sdl/sdl.cpp
@@ -95,6 +95,7 @@ OSystem_SDL::OSystem_SDL()
#endif
_hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0),
_tmpscreen(0), _overlayVisible(false),
+ _samplesPerSec(0),
_cdrom(0), _scaler_proc(0), _modeChanged(false), _dirty_checksums(0),
_mouseVisible(false), _mouseDrawn(false), _mouseData(0),
_mouseHotspotX(0), _mouseHotspotY(0),
@@ -274,18 +275,40 @@ void OSystem_SDL::deleteMutex(MutexRef mutex) {
bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) {
SDL_AudioSpec desired;
+ SDL_AudioSpec obtained;
memset(&desired, 0, sizeof(desired));
- desired.freq = SAMPLES_PER_SEC;
+ if (ConfMan.hasKey("output_rate"))
+ _samplesPerSec = ConfMan.getInt("output_rate");
+ else
+ _samplesPerSec = SAMPLES_PER_SEC;
+
+ // Originally, we always used 2048 samples. This loop will produce the
+ // same result at 22050 Hz, and should hopefully produce something
+ // sensible for other frequencies. Note that it must be a power of two.
+
+ uint16 samples = 0x8000;
+
+ for (;;) {
+ if (samples / (_samplesPerSec / 1000) < 100)
+ break;
+ samples >>= 1;
+ }
+
+ desired.freq = _samplesPerSec;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
- desired.samples = 2048;
+ desired.samples = samples;
desired.callback = proc;
desired.userdata = param;
- if (SDL_OpenAudio(&desired, NULL) != 0) {
+ if (SDL_OpenAudio(&desired, &obtained) != 0) {
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;
SDL_PauseAudio(0);
return true;
}
@@ -295,7 +318,7 @@ void OSystem_SDL::clearSoundCallback() {
}
int OSystem_SDL::getOutputSampleRate() const {
- return SAMPLES_PER_SEC;
+ return _samplesPerSec;
}
#pragma mark -