aboutsummaryrefslogtreecommitdiff
path: root/backends/sdl
diff options
context:
space:
mode:
authorTorbjörn Andersson2005-06-07 14:43:12 +0000
committerTorbjörn Andersson2005-06-07 14:43:12 +0000
commit4b5ff5ba1f8db6dfad5e27e4c0ef7115ce29d3fb (patch)
tree408f7a809804d11e9203dbd8966f3143d8b674cd /backends/sdl
parent54df4a6e5b42f786e0bc40faae98165d51a5c42f (diff)
downloadscummvm-rg350-4b5ff5ba1f8db6dfad5e27e4c0ef7115ce29d3fb.tar.gz
scummvm-rg350-4b5ff5ba1f8db6dfad5e27e4c0ef7115ce29d3fb.tar.bz2
scummvm-rg350-4b5ff5ba1f8db6dfad5e27e4c0ef7115ce29d3fb.zip
Be less prone to crash on really, really stupid output sample rates.
Added warning message if SDL_OpenAudio() fails. Might help diagnosing bug reports like #1206314. svn-id: r18361
Diffstat (limited to 'backends/sdl')
-rw-r--r--backends/sdl/sdl.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/backends/sdl/sdl.cpp b/backends/sdl/sdl.cpp
index 69b767dd0d..117736d0ad 100644
--- a/backends/sdl/sdl.cpp
+++ b/backends/sdl/sdl.cpp
@@ -278,19 +278,22 @@ bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) {
memset(&desired, 0, sizeof(desired));
+ _samplesPerSec = 0;
+
if (ConfMan.hasKey("output_rate"))
_samplesPerSec = ConfMan.getInt("output_rate");
- else
+
+ if (_samplesPerSec <= 0)
_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;
+ uint32 samples = 0x8000;
for (;;) {
- if (samples / (_samplesPerSec / 1000) < 100)
+ if ((1000 * samples) / _samplesPerSec < 100)
break;
samples >>= 1;
}
@@ -298,10 +301,11 @@ bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) {
desired.freq = _samplesPerSec;
desired.format = AUDIO_S16SYS;
desired.channels = 2;
- desired.samples = samples;
+ desired.samples = (uint16)samples;
desired.callback = proc;
desired.userdata = param;
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