dwhinham / mt32-pi

🎹🎶 A baremetal kernel that turns your Raspberry Pi 3 or later into a Roland MT-32 emulator and SoundFont synthesizer based on Circle, Munt, and FluidSynth.
https://twitter.com/d0pefish
GNU General Public License v3.0
1.28k stars 81 forks source link

Initmt32emu fails if sf2 file in directory #93

Closed flynnsbit closed 3 years ago

flynnsbit commented 3 years ago

Exodos default install includes an mt32 folder which has both the mt-32 roms as well as a SoundCanvas.sf2 file. If user copies the entire folder over to the mt32-pi sd card for mt32 roms it will cause this issue.

dwhinham commented 3 years ago

Thanks!

I know the cause of this, and it shouldn't occur on Pi 4. It could occur if any kind of large file greater than around 32MB is in the directory.

The MT-32 ROM loader will try to read the entire file into memory, but fail because it won't be able to allocate more than ~32MB. This is because the amount of heap memory remaining for libc malloc()/new is around ~32MB after the custom allocator used by FluidSynth reserves the majority of the Pi's RAM.

Valid MT-32 ROMs can never be more than 1MB in size (the largest ROM is the CM-32L PCM ROM at 1MB), and so an easy fix would be to simply skip files >1MB in the ROM scanner. I'll implement this for the next release.

This issue may come back again if anything else needs to do a large malloc() however - so the true long-term fix is to completely replace the Circle memory allocator with the custom one.