"no throttle" fixes/cleanups

`throttle == 0` is supposed to emulate at full speed and drop audio
data, this is different from `throttle == 100` which is emulation
throttled at normal speed, the default setting.

Fix the recently rewritten SoundSDL sound driver to make `throttle == 0`
work, and make some minor changes to clean up the relevant code in the
XAudio2 sound driver.
This commit is contained in:
Rafael Kitover 2017-08-27 07:21:27 -07:00
parent 9bca4f7292
commit 1a8f2f9886
2 changed files with 12 additions and 9 deletions

View File

@ -30,12 +30,12 @@ const double SoundSDL::buftime = 0.300;
SoundSDL::SoundSDL():
samples_buf(0),
sound_device(-1),
current_rate(throttle ? throttle : 100),
current_rate(throttle),
initialized(false)
{}
void SoundSDL::soundCallback(void* data, uint8_t* stream, int len) {
reinterpret_cast<SoundSDL*>(data)->read(reinterpret_cast<uint16_t *>(stream), len);
reinterpret_cast<SoundSDL*>(data)->read(reinterpret_cast<uint16_t*>(stream), len);
}
bool SoundSDL::should_wait() {
@ -99,7 +99,7 @@ void SoundSDL::write(uint16_t * finalWave, int length) {
if (should_wait())
SDL_SemWait(data_read);
else
// Drop the remaining of the audio data
// Drop the remainder of the audio data
return;
SDL_LockMutex(mutex);
@ -116,7 +116,10 @@ bool SoundSDL::init(long sampleRate) {
SDL_AudioSpec audio;
SDL_memset(&audio, 0, sizeof(audio));
audio.freq = sampleRate * (current_rate / 100.0);
// for "no throttle" use regular rate, audio is just dropped
audio.freq = current_rate ? sampleRate * (current_rate / 100.0) : sampleRate;
audio.format = AUDIO_S16SYS;
audio.channels = 2;
audio.samples = 2048;
@ -179,6 +182,6 @@ void SoundSDL::reset() {
}
void SoundSDL::setThrottle(unsigned short throttle_) {
current_rate = throttle_ ? throttle_ : 100;
current_rate = throttle_;
reset();
}

View File

@ -599,15 +599,15 @@ void XAudio2_Output::reset()
playing = true;
}
void XAudio2_Output::setThrottle(unsigned short throttle)
void XAudio2_Output::setThrottle(unsigned short throttle_)
{
if (!initialized || failed)
return;
if (throttle == 0)
throttle = 100;
if (throttle_ == 0)
throttle_ = 100;
HRESULT hr = sVoice->SetFrequencyRatio((float)throttle / 100.0f);
HRESULT hr = sVoice->SetFrequencyRatio((float)throttle_ / 100.0f);
assert(hr == S_OK);
}