From 98e1771a832f0843d1a8be344894c0c77bd5f8fd Mon Sep 17 00:00:00 2001 From: khokh2001 Date: Wed, 29 Oct 2014 01:37:42 +0900 Subject: opl note limitation and octave overflow fixes --- src/i_oplmusic.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c index a1e90506..bb9edcb4 100644 --- a/src/i_oplmusic.c +++ b/src/i_oplmusic.c @@ -734,9 +734,14 @@ static unsigned int FrequencyForVoice(opl_voice_t *voice) // Avoid possible overflow due to base note offset: - if (note > 0x7f) + while (note < 0) { - note = voice->note; + note += 12; + } + + while (note > 95) + { + note -= 12; } freq_index = 64 + 32 * note + voice->channel->bend; @@ -770,14 +775,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. -- cgit v1.2.3 From 0cada1cf6fd7b5cdcf41b5638b35d779b430efb8 Mon Sep 17 00:00:00 2001 From: khokh2001 Date: Wed, 29 Oct 2014 16:52:36 +0900 Subject: Update i_oplmusic.c --- src/i_oplmusic.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c index bb9edcb4..45469dfb 100644 --- a/src/i_oplmusic.c +++ b/src/i_oplmusic.c @@ -715,10 +715,10 @@ static opl_voice_t *ReplaceExistingVoice(opl_channel_data_t *channel) 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; @@ -754,6 +754,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. -- cgit v1.2.3