From ab14960e3a24208709270fb11476f0bbb629b145 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 30 Aug 2009 23:04:54 +0000 Subject: 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