Interkarma / daggerfall-unity

Open source recreation of Daggerfall in the Unity engine
http://www.dfworkshop.net
MIT License
2.7k stars 327 forks source link

Fix drums in custom soundfonts #2627

Closed Kung-vr closed 2 months ago

Kung-vr commented 5 months ago

Many soundfonts will only provide percussion on patch 0 of bank 128. This fix allows attempting to fall back to the default percussion patch location when a drum patch is unavailable.

See this comment for an example of the common soundfont bank and patch setup for drums: https://github.com/LMMS/lmms/issues/323#issuecomment-40160617

To verify the problem, try loading this OPL3.SF2 soundfont OPL3.zip with the current release version and notice the percussion during 5strong.mid is missing in the startup screen. When this fix is applied the percussion will work.

KABoissonneault commented 5 months ago

Thank you! We're currently on hold while waiting for the v1.1 changes to be done, but I'll have a look after. I suppose the fact that your reference says "channel 10" but your review checks channel 9 is because of 0-indexing vs 1-indexing differences?

Kung-vr commented 5 months ago

Thanks for taking a peek so quickly! I didn't know how active this project is, but a reply within just an hour is amazing 🙏

your reference says "channel 10" but your review checks channel 9 is because of 0-indexing vs 1-indexing differences?

Yep that's correct! Midi channels start from 1, but in code are indexed from 0, so the 9 there represents midi channel 10 which is the standard channel for percussion.

Kung-vr commented 5 months ago

Actually, the drum channel was defined as a constant in MidiHelper.DrumChannel (still 9), so I changed it to use that instead to avoid using magic numbers.