foxygit / doom Log in
commit ab14960e3a24208709270fb11476f0bbb629b145
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Aug 30 23:04:54 2009 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Aug 30 23:04:54 2009 +0000

    Make I_OPL_StopSong work.

    Subversion-branch: /branches/opl-branch
    Subversion-revision: 1647
---
 src/i_oplmusic.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c
index db7e0ffc..eff3f942 100644
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -598,6 +598,11 @@ static opl_voice_t *FindVoiceForNote(opl_channel_data_t *channel, int note)
     return NULL;
 }

+static void VoiceNoteOff(opl_voice_t *voice)
+{
+    WriteRegister(OPL_REGS_FREQ_2 + voice->index, voice->freq >> 8);
+}
+
 static void NoteOffEvent(opl_track_data_t *track, midi_event_t *event)
 {
     opl_voice_t *voice;
@@ -619,9 +624,7 @@ static void NoteOffEvent(opl_track_data_t *track, midi_event_t *event)
         return;
     }

-    // Note off.
-
-    WriteRegister(OPL_REGS_FREQ_2 + voice->index, voice->freq >> 8);
+    VoiceNoteOff(voice);

     // Finished with this voice now.

@@ -913,10 +916,27 @@ static void I_OPL_ResumeSong(void)

 static void I_OPL_StopSong(void)
 {
+    unsigned int i;
+
     if (!music_initialised)
     {
         return;
     }
+
+    // Stop all playback.
+
+    OPL_ClearCallbacks();
+
+    // Free all voices.
+
+    for (i=0; i<OPL_NUM_VOICES; ++i)
+    {
+        if (voices[i].channel != NULL)
+        {
+            VoiceNoteOff(&voices[i]);
+            ReleaseVoice(&voices[i]);
+        }
+    }
 }

 static void I_OPL_UnRegisterSong(void *handle)