summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2014-11-01 21:07:38 -0400
committerSimon Howard2014-11-01 21:07:38 -0400
commit116b698e31c8637248ca1610e2faa717d005b6f2 (patch)
treec4efac41d9307c36d8ebe93c0c9d93c745918832
parentd051bd5d55a998f2ff4f74f718e23c98cbf49b88 (diff)
parent0cada1cf6fd7b5cdcf41b5638b35d779b430efb8 (diff)
downloadchocolate-doom-116b698e31c8637248ca1610e2faa717d005b6f2.tar.gz
chocolate-doom-116b698e31c8637248ca1610e2faa717d005b6f2.tar.bz2
chocolate-doom-116b698e31c8637248ca1610e2faa717d005b6f2.zip
Merge pull request #466 from khokh2001/opl-fix2
opl note limitation and octave overflow fixes Adjust how the OPL MIDI code behaves at extreme MIDI note values (high/low octaves) to better match how the Doom DMX library decides on the OPL register value (thanks Alexey Khokholov / khokh20010.
-rw-r--r--src/i_oplmusic.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c
index 9960d35d..4641912e 100644
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -700,10 +700,10 @@ static void ReplaceExistingVoice()
static unsigned int FrequencyForVoice(opl_voice_t *voice)
{
genmidi_voice_t *gm_voice;
- unsigned int freq_index;
+ signed int freq_index;
unsigned int octave;
unsigned int sub_index;
- unsigned int note;
+ signed int note;
note = voice->note;
@@ -719,9 +719,14 @@ static unsigned int FrequencyForVoice(opl_voice_t *voice)
// Avoid possible overflow due to base note offset:
- if (note > 0x7f)
+ while (note < 0)
+ {
+ note += 12;
+ }
+
+ while (note > 95)
{
- note = voice->note;
+ note -= 12;
}
freq_index = 64 + 32 * note + voice->channel->bend;
@@ -734,6 +739,11 @@ static unsigned int FrequencyForVoice(opl_voice_t *voice)
freq_index += (voice->current_instr->fine_tuning / 2) - 64;
}
+ if (freq_index < 0)
+ {
+ freq_index = 0;
+ }
+
// The first 7 notes use the start of the table, while
// consecutive notes loop around the latter part.
@@ -755,14 +765,7 @@ static unsigned int FrequencyForVoice(opl_voice_t *voice)
if (octave >= 7)
{
- if (sub_index < 5)
- {
- octave = 7;
- }
- else
- {
- octave = 6;
- }
+ octave = 7;
}
// Calculate the resulting register value to use for the frequency.