schellingb / TinySoundFont

SoundFont2 synthesizer library in a single C/C++ file
MIT License
623 stars 72 forks source link

Stuck instrument with Windows XP onestop.mid #59

Open zennetizen opened 3 years ago

zennetizen commented 3 years ago

When playing onestop.mid from Windows XP a note gets stuck after the first "verse" of the song, and continues through the rest of the song.

I'm trying to figure out what's going on but it's a hard one to debug.

edgarlsitec commented 3 years ago

I was having a similar problem when playing a few midi sample files from Creative SB16 and AWE32 driver. A note always got stuck in the songs styles#2.mid, starman.mid and dance.mid. I managed to find a solution by looking at the last midi commands that were reproduced before the note got stuck. In the example, try to add the following code at TML_PROGRAM_CHANGE case inside the AudioCallback. I hope it helps.

case TML_PROGRAM_CHANGE: 
        tsf_channel_set_presetnumber(g_TinySoundFont, g_MidiMessage->channel, g_MidiMessage->program, (g_MidiMessage->channel == 9));
        tsf_channel_midi_control(g_TinySoundFont, g_MidiMessage->channel, TML_ALL_SOUND_OFF, 0); // this it the fix!!!
        break;

Note: First I used TML_ALL_SOUND_OFF, but TML_ALL_NOTES_OFF appears to sound better at the overture.mid song.