diff options
author | Torbjörn Andersson | 2012-11-17 11:53:54 +0100 |
---|---|---|
committer | Torbjörn Andersson | 2012-11-17 11:53:54 +0100 |
commit | ee65532a5e3af0a92384d6d777110b6e602cf1c3 (patch) | |
tree | db94721bb50a9261f542f5ab2917ff4396aa38b1 | |
parent | 4626e211496aad5ffe27bea3121483faa98770d7 (diff) | |
download | scummvm-rg350-ee65532a5e3af0a92384d6d777110b6e602cf1c3.tar.gz scummvm-rg350-ee65532a5e3af0a92384d6d777110b6e602cf1c3.tar.bz2 scummvm-rg350-ee65532a5e3af0a92384d6d777110b6e602cf1c3.zip |
SCUMM: Avoid "pops" at the end of the note in Mac MI1/Loom music
At least on my computer, when the note ended abruptly there would
be an annoying "pop" at the end. This was particularly noticeable
at the end of the distaff notes in Loom. To get around this, fade
out the last 100 samples. There's nothing magical about 100 in
particular, but it's a nice even number and it should be short
enough that it's never a noticeable part of the note, even at low
sample rates.
-rw-r--r-- | engines/scumm/player_mac.cpp | 20 | ||||
-rw-r--r-- | engines/scumm/player_mac.h | 2 |
2 files changed, 18 insertions, 4 deletions
diff --git a/engines/scumm/player_mac.cpp b/engines/scumm/player_mac.cpp index ac4615c606..7c3e2c22b0 100644 --- a/engines/scumm/player_mac.cpp +++ b/engines/scumm/player_mac.cpp @@ -335,7 +335,7 @@ int Player_Mac::readBuffer(int16 *data, const int numSamples) { } generated = MIN(_channel[i]._remaining, samplesLeft); if (_channel[i]._velocity != 0) { - _channel[i]._instrument.generateSamples(ptr, _channel[i]._pitchModifier, _channel[i]._velocity, generated); + _channel[i]._instrument.generateSamples(ptr, _channel[i]._pitchModifier, _channel[i]._velocity, generated, _channel[i]._remaining); } ptr += generated; samplesLeft -= generated; @@ -354,7 +354,7 @@ int Player_Mac::readBuffer(int16 *data, const int numSamples) { return numSamples; } -void Player_Mac::Instrument::generateSamples(int16 *data, int pitchModifier, int volume, int numSamples) { +void Player_Mac::Instrument::generateSamples(int16 *data, int pitchModifier, int volume, int numSamples, int remainingSamplesOnNote) { int samplesLeft = numSamples; while (samplesLeft) { _subPos += pitchModifier; @@ -366,7 +366,21 @@ void Player_Mac::Instrument::generateSamples(int16 *data, int pitchModifier, int } } - int sample = *data + ((_data[_pos] - 129) * 128 * volume) / 255; + int newSample = ((_data[_pos] - 129) * 128 * volume) / 255; + + // Fade out the last 100 samples on each note. Even at low + // output sample rates this is just a fraction of a second, + // but it gets rid of distracting "pops" at the end when the + // sample would otherwise go abruptly from something to + // nothing. This was particularly noticeable on the distaff + // notes in Loom. + + remainingSamplesOnNote--; + if (remainingSamplesOnNote < 100) { + newSample = (newSample * remainingSamplesOnNote) / 100; + } + + int sample = *data + newSample; if (sample > 32767) { sample = 32767; } else if (sample < -32768) { diff --git a/engines/scumm/player_mac.h b/engines/scumm/player_mac.h index 0585eb16b0..3f5184d2d8 100644 --- a/engines/scumm/player_mac.h +++ b/engines/scumm/player_mac.h @@ -90,7 +90,7 @@ private: _subPos = 0; } - void generateSamples(int16 *data, int pitchModifier, int volume, int numSamples); + void generateSamples(int16 *data, int pitchModifier, int volume, int numSamples, int remainingSamplesOnNote); }; int _pitchTable[128]; |