Midi music is delayed on title screen - preload to fix it
I've tested on windows with fluidlite. When a game has a midi title music, the title appears and the music is delayed for some time. Presumably due to delays in loading the midi libraries.
This effect is pretty jarring. If your title is not midi, than the first midi you play later will cause this lag.
We have plenty of time on engine startup to load this stuff while loading the game data. Therefore I suggest something like the following:
- [ ] On game startup, scan the Music directory. If any midi file is found, preload the system midi library. - Maybe this can be easily faked by playing some midi at 0 volume?
- [ ] If title screen uses midi audio, and midi system is taking too long to load, delay fading into the title screen until midi library is fully loaded.
The midi library is loaded on the main thread. It could be the missing "skip initial silence".
As a side note, the upcoming FluidSynth 2.2.0 is getting soundfont loading parallelization that should relieve this issue. There is also a dynamic sample loading flag to load the required samples on demand (and saves some memory on large soundfonts), disabled by default.
Since the native midi branch landed, this could have been mitigated (midi silence skipping), needs recheck.
Partially related so I'm adding it here, but exiting a game with a midi on the title screen and then reopening it from the game browser may have different results (lack of some instruments, incorrect volume of some instruments, lack of music...). This is not major since it will not continue past the title screen and that just putting the window of the game in the background and reopening it will work as a fix for a player. (Opening the settings menu on the title screen in said condition can also cause the issue to happen).