hex007 / freej2me

A free J2ME emulator with libretro, awt and sdl2 frontends.
Other
501 stars 78 forks source link

PlatformPlayer: Add support for custom MIDI soundfonts #193

Open AShiningRay opened 1 year ago

AShiningRay commented 1 year ago

Given this is a bit of an experiment, i don't expect it to be merged, but there's no harm in trying since it would be a nice feature to have.

While it has already been closed, this PR would technically close #74... Had some fun with it this weekend and the prospect of having FreeJ2ME be able to effectively "remaster" midi tracks or simulate some phones like the Nokia Series 30 was very interesting.

Turns out it is possible to alter the soundfont used by a JVM's midi synth, and not only is it easy, but it can also be isolated from system drivers, which means users can just put a .sf2 file on the specified folder, enable the option on libretro or AWT menus, and run with it without having to deal with MIDI shenanigans on linux or windows.

Personal testing showed that while you can load pretty much any soundfont in there, the RAM and processing requirements will vary a lot depending on the used soundfont. On one hand you can make MIDI samples sound like they're coming from a Yamaha Tyros 4 if you really want to, but be ready to use 10+ gigs of RAM just to load some games, but on the other you can use small soundfonts and FreeJ2ME will actually get lighter and some games (Asphalt 4) will load slightly faster.

As an example, running Block Breaker 2 Deluxe with TyrolandGS.sf2 (a soundfont that simulates the Tyros 4 + Roland JV-1010) gets me the following usage stats upon reaching the menu: FreeJ2ME_TyrolandGS_RAM

vadosnaprimer commented 1 year ago

Woohoo finally the thing I tried to bring up here https://github.com/hex007/freej2me/issues/83#issuecomment-831384735 Dunno if my patch was used as a reference but I see our code mostly matches. The part I couldn't get over was setting up the infrastructure to make this properly optional.

Here's the soundfont that sounds the most like my Nokia X2-00 https://musical-artifacts.com/artifacts/828 I wonder if it makes sense to ship FJ2M with it, enabled by default? After all j2me loader is also not relying on system soundfont.

And yeah from my previous testing, audio sounds weird without fps limitation (so maybe it should also become default?)

Thanks and congrats :)

AShiningRay commented 1 year ago

Woohoo finally the thing I tried to bring up here #83 (comment) Dunno if my patch was used as a reference but I see our code mostly matches. The part I couldn't get over was setting up the infrastructure to make this properly optional.

Here's the soundfont that sounds the most like my Nokia X2-00 https://musical-artifacts.com/artifacts/828 I wonder if it makes sense to ship FJ2M with it, enabled by default? After all j2me loader is also not relying on system soundfont.

And yeah from my previous testing, audio sounds weird without fps limitation (so maybe it should also become default?)

Thanks and congrats :)

Huh, now that i looked at it, they're pretty similar, but i guess that's because there's only really one way to handle custom soundfonts on MidiSystem and PlatformPlayer's midiPlayer is the only place where it would make sense to add the code into... at least intuitively. Making it a toggle-able config on both standalone and libretro was the bulk of the work, although i'm coming to understand FreeJ2ME as a whole a bit more because of it.

Shipping custom soundfonts by default doesn't seem like a good idea to me (mainly thinking about licensing issues, even though quite a few general sf2 are CC 3.0 Unported), the default soundfont already works so there's no reason to ship anything else with FreeJ2ME as that would add unnecessary complexity and size to it.

As for audio playback being wonky, limiting fps doesn't really help matters over here and only mitigates some of it, which means we have another issue sitting around elsewhere... no idea what it could be though, and FreeJ2ME's audio subsystem is far from perfect for now with almost all audio playback repeating two times for some unknown reason.