diff options
author | Walter van Niftrik | 2017-02-20 23:11:38 +0100 |
---|---|---|
committer | Walter van Niftrik | 2017-02-21 11:35:31 +0100 |
commit | 9865ee16f7f5301503cc63e644f009e70465c3b1 (patch) | |
tree | b3914cd4cfc8765fcabb5c27c165324336c98b2d /engines/adl | |
parent | 534157f8e0b4b249423a673d610f800f2adcdf20 (diff) | |
download | scummvm-rg350-9865ee16f7f5301503cc63e644f009e70465c3b1.tar.gz scummvm-rg350-9865ee16f7f5301503cc63e644f009e70465c3b1.tar.bz2 scummvm-rg350-9865ee16f7f5301503cc63e644f009e70465c3b1.zip |
ADL: Use 0-sample for speaker silence
This reduces popping noises
Diffstat (limited to 'engines/adl')
-rw-r--r-- | engines/adl/sound.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/engines/adl/sound.cpp b/engines/adl/sound.cpp index 63eea45953..3d46ea0409 100644 --- a/engines/adl/sound.cpp +++ b/engines/adl/sound.cpp @@ -47,10 +47,9 @@ private: Speaker::Speaker(int sampleRate) : _rate(sampleRate), - _curSample(32767) { - - stopTone(); -} + _halfWaveLen(0), + _halfWaveRem(0), + _curSample(32767) { } void Speaker::startTone(double freq) { _halfWaveLen = _halfWaveRem = doubleToFrac(_rate / freq / 2); @@ -63,10 +62,15 @@ void Speaker::startTone(double freq) { void Speaker::stopTone() { _halfWaveLen = 0; - _halfWaveRem = intToFrac(32767); } void Speaker::generateSamples(int16 *buffer, int numSamples) { + if (_halfWaveLen == 0) { + // Silence + memset(buffer, 0, numSamples * sizeof(int16)); + return; + } + int offset = 0; while (offset < numSamples) { @@ -79,15 +83,14 @@ void Speaker::generateSamples(int16 *buffer, int numSamples) { // Compute next transition point _halfWaveRem += _halfWaveLen - FRAC_ONE; } else { - // Low/high level (incl. silence) + // Low/high level // Generate as many samples as we can const int samples = MIN(numSamples - offset, (int)fracToInt(_halfWaveRem)); Common::fill(buffer + offset, buffer + offset + samples, _curSample); offset += samples; - // Count down to level transition point, unless we're playing silence - if (_halfWaveLen > 0) - _halfWaveRem -= intToFrac(samples); + // Count down to level transition point + _halfWaveRem -= intToFrac(samples); } } } |