ValleyBell / MidiConverters

various tools that convert game data into MIDI files
GNU General Public License v2.0
102 stars 14 forks source link

Soundfont is corrupt (M2MidiDec, Sonic the Fighters) #5

Closed SwitchKaze closed 4 years ago

SwitchKaze commented 4 years ago

Operating System: Windows 10 using the MinGW-w64 toolchain

Input file(s): Sonic the Fighters Model 2 ROM

Expected behavior: I expect the soundfont (out.sf2) generated by M2MidiDec.exe to be a valid soundfont that can be used in *.SF2 compatible programs.

Actual behavior: Various errors pertaining to the soundfont depending on which program is used to open them. For example, the Polyphone soundfont editor states that the file is corrupt and the error originates in the pdta region of the generated soundfont. LMMS, a popular music sequencer, cannot find any patches nor banks in the soundfont file.

Steps to reproduce:

ValleyBell commented 4 years ago

I can confirm that the Polyphone editor is unable to read the SF2 files.

Back when I wrote the converter, I tested the SF2 files against Viena and the BASSMIDI MIDI driver. Both have no problems loading the SF2 files, so I don't know what the problem is. Loading the SF2 file in Viena and saving it also makes it readable in Polyphone, which is weird.

Maybe I stored the chunks in an order that the SF2 loaders don't expect? I really have no idea.

btw, the easiest way to compile the tool is:

gcc Soundfont.c M2MidiDec.c -o M2MidiDec
SwitchKaze commented 4 years ago

Thanks for the info, I'll definitely try that out.

biggestsonicfan commented 4 years ago

For what it's worth, I just extracted both soundfonts and midis last night and used them in Foobar2000 with the Midi component and they worked great.

ValleyBell commented 4 years ago

Okay, so we have some programs that refuse to load the SF2 files and some that load them just fine. So at least I didn't completely screw it up then.

Thanks a lot for checking!

It still leaves the question about what's wrong with them though.

ValleyBell commented 4 years ago

Thanks to insertsurnamehere I recently had a look at the SF2 issue again. And it turns out I missed an important note from the SF2 specification:

In SoundFont 2.0, the order of the sub-chunks within the INFO chunk is arbitrary, but for consistency it is recommended that the sub-chunks be ordered as presented in this document. The order of the all other chunks and sub-chunks is strictly defined and must be maintained as presented in this document.

All chunks in the pdta block have a defined order. I'm outputting them in a different order. Some programs can handle that (Viena, BASSMIDI), others strictly follow the specification and get confused by the incorrect order. (Polyphone)

Loading and resaving the file with Viena resorts the chunks and thus makes the file work in the other tools like Polyphone. I'll try to fix this issue sometime soon.

ValleyBell commented 4 years ago

This should be fixed by 8b66704be05a5bdb55d83c2a8d10028449637b27.

Feel free to reopen the issue if there are still issues with the soundfonts.

possiblyamagicmage commented 2 months ago

It seems the output SF2 still crashes LMMS, but works completely fine with BASSMIDI, Polyphone, and Viena. Resaving with Viena or Polyphone also doesn't fix the issue, strangely enough.

ValleyBell commented 2 months ago

Can you contact the LMMS developers and ask what is wrong with the soundfont or if their SF2 loader is buggy?