diff -ur --exclude=CVS ScummVM/backends/sdl/sdl-common.h ScummVM+hack/backends/sdl/sdl-common.h
old
|
new
|
|
133 | 133 | |
134 | 134 | virtual void setWindowCaption(const char *caption); |
135 | 135 | virtual bool openCD(int drive); |
| 136 | virtual void setOutputSampleRate(int rate); |
136 | 137 | virtual int getOutputSampleRate() const; |
137 | 138 | |
138 | 139 | virtual bool hasFeature(Feature f); |
… |
… |
|
169 | 170 | SDL_Surface *_tmpscreen; |
170 | 171 | bool _overlayVisible; |
171 | 172 | |
| 173 | // Audio |
| 174 | int _samplesPerSec; |
| 175 | |
172 | 176 | // CD Audio |
173 | 177 | SDL_CD *_cdrom; |
174 | 178 | int cd_track, cd_num_loops, cd_start_frame, cd_duration; |
diff -ur --exclude=CVS ScummVM/backends/sdl/sdl.cpp ScummVM+hack/backends/sdl/sdl.cpp
old
|
new
|
|
95 | 95 | #endif |
96 | 96 | _hwscreen(0), _screen(0), _screenWidth(0), _screenHeight(0), |
97 | 97 | _tmpscreen(0), _overlayVisible(false), |
| 98 | _samplesPerSec(SAMPLES_PER_SEC), |
98 | 99 | _cdrom(0), _scaler_proc(0), _modeChanged(false), _dirty_checksums(0), |
99 | 100 | _mouseVisible(false), _mouseDrawn(false), _mouseData(0), |
100 | 101 | _mouseHotspotX(0), _mouseHotspotY(0), |
… |
… |
|
289 | 290 | |
290 | 291 | bool OSystem_SDL::setSoundCallback(SoundProc proc, void *param) { |
291 | 292 | SDL_AudioSpec desired; |
| 293 | SDL_AudioSpec obtained; |
292 | 294 | |
293 | 295 | memset(&desired, 0, sizeof(desired)); |
294 | 296 | |
295 | | desired.freq = SAMPLES_PER_SEC; |
| 297 | desired.freq = _samplesPerSec; |
296 | 298 | desired.format = AUDIO_S16SYS; |
297 | 299 | desired.channels = 2; |
298 | 300 | desired.samples = 2048; |
299 | 301 | desired.callback = proc; |
300 | 302 | desired.userdata = param; |
301 | | if (SDL_OpenAudio(&desired, NULL) != 0) { |
| 303 | if (SDL_OpenAudio(&desired, &obtained) != 0) { |
302 | 304 | return false; |
303 | 305 | } |
| 306 | // Note: This should be the obtained output rate, but it seems that at |
| 307 | // least on some platforms SDL will lie and claim it did get the rate |
| 308 | // even if it didn't. Probably only happens for "weird" rates, though. |
| 309 | _samplesPerSec = obtained.freq; |
304 | 310 | SDL_PauseAudio(0); |
305 | 311 | return true; |
306 | 312 | } |
… |
… |
|
309 | 315 | SDL_CloseAudio(); |
310 | 316 | } |
311 | 317 | |
| 318 | void OSystem_SDL::setOutputSampleRate(int rate) { |
| 319 | _samplesPerSec = rate; |
| 320 | } |
| 321 | |
312 | 322 | int OSystem_SDL::getOutputSampleRate() const { |
313 | | return SAMPLES_PER_SEC; |
| 323 | return _samplesPerSec; |
314 | 324 | } |
315 | 325 | |
316 | 326 | #pragma mark - |
diff -ur --exclude=CVS ScummVM/common/system.h ScummVM+hack/common/system.h
old
|
new
|
|
546 | 546 | virtual void clearSoundCallback() = 0; |
547 | 547 | |
548 | 548 | /** |
| 549 | * Set the desired output sample rate. It has to be called before |
| 550 | * setSoundCallback(), and it's not certain that we actually get it. |
| 551 | * Use getOutputSampleRate() to find out. |
| 552 | */ |
| 553 | virtual void setOutputSampleRate(int rate) = 0; |
| 554 | |
| 555 | /** |
549 | 556 | * Determine the output sample rate. Audio data provided by the sound |
550 | 557 | * callback will be played using this rate. |
551 | 558 | * @return the output sample rate |
diff -ur --exclude=CVS ScummVM/sound/mixer.cpp ScummVM+hack/sound/mixer.cpp
old
|
new
|
|
21 | 21 | */ |
22 | 22 | |
23 | 23 | #include "stdafx.h" |
| 24 | #include "common/config-manager.h" |
24 | 25 | #include "common/file.h" |
25 | 26 | #include "common/util.h" |
26 | 27 | |
… |
… |
|
111 | 112 | _premixProc = 0; |
112 | 113 | int i = 0; |
113 | 114 | |
114 | | _outputRate = (uint) _syst->getOutputSampleRate(); |
115 | | |
116 | | if (_outputRate == 0) |
117 | | error("OSystem returned invalid sample rate"); |
| 115 | if (ConfMan.hasKey("output_rate")) |
| 116 | _syst->setOutputSampleRate(ConfMan.getInt("output_rate")); |
118 | 117 | |
119 | 118 | _globalVolume = 0; |
120 | 119 | _musicVolume = 0; |
… |
… |
|
125 | 124 | _channels[i] = 0; |
126 | 125 | |
127 | 126 | _mixerReady = _syst->setSoundCallback(mixCallback, this); |
| 127 | _outputRate = (uint) _syst->getOutputSampleRate(); |
| 128 | |
| 129 | if (_outputRate == 0) |
| 130 | error("OSystem returned invalid sample rate"); |
| 131 | |
| 132 | debug(1, "Output sample rate: %d Hz", _outputRate); |
128 | 133 | } |
129 | 134 | |
130 | 135 | SoundMixer::~SoundMixer() { |