foxygit / doom Log in
commit 98e1771a832f0843d1a8be344894c0c77bd5f8fd
Author:     khokh2001 <alexeytf2@gmail.com>
AuthorDate: Wed Oct 29 01:37:42 2014 +0900
Commit:     khokh2001 <alexeytf2@gmail.com>
CommitDate: Wed Oct 29 01:37:42 2014 +0900

    opl note limitation and octave overflow fixes
---
 src/i_oplmusic.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

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.