Fix factor-of-2-off MIDI velocity parsing (#290)

Velocity in the MIDI format goes from 1...127, so scale the volume of
the note generator by /128 instead of /256.   Increases volume of all
notes by 2x linearly (3dB).

Found by Marc Madaule
This commit is contained in:
Earle F. Philhower, III authored and GitHub committed 2020-08-09 19:01:16 -07:00
1 parent 87742f502c
commit 0d1d849f91
1 file changed
+2 -2
+2 -2
View File
@@ -359,7 +359,7 @@ void AudioGeneratorMIDI::PrepareMIDI(AudioFileSource *src)
earliest_time = 0;
}
// Parses the note on/offs ujntil we are ready to render some more samples. Then return the
// Parses the note on/offs until we are ready to render some more samples. Then return the
// total number of samples to render before we need to be called again
int AudioGeneratorMIDI::PlayMIDI()
{
@@ -472,7 +472,7 @@ int AudioGeneratorMIDI::PlayMIDI()
if (tg->instrument != midi_chan_instrument[trk->chan]) { /* new instrument for this generator */
tg->instrument = midi_chan_instrument[trk->chan];
}
tsf_note_on (g_tsf, tg->instrument, tg->note, trk->velocity / 256.0);
tsf_note_on (g_tsf, tg->instrument, tg->note, trk->velocity / 127.0); // velocity = 0...127
} else {
++notes_skipped;
}