godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 69 forks source link

Add tracker music support using libopenmpt #10077

Open seacat17 opened 3 days ago

seacat17 commented 3 days ago

Describe the project you are working on

I'm making a 3D platformer that takes place in space where you play as an alien who needs to fight to return back to home.

Describe the problem or limitation you are having in your project

I found some cool tracker music for this project that sounds cool and loops perfectly. But Godot doesn't support tracker music natively and the only add-on for Godot 4 plays it incorrectly.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

You should probably include libopenmpt for native tracker music playback with perfect interpolation and looping.

https://lib.openmpt.org/libopenmpt/

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

If you embed an OGG file into your project, Godot will immediately recognize it and will use proper decoder for AudioStream node. The same thing could happen with MPTM, MOD, XM, S3M and other MOD-based music files. You can make it loop and you can change interpolation method or disable it entirely.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No. The thing is that even though someone managed to make a MOD-player in GDScript as an add-on in AssetLib, you can't make it play every MOD format in existence. You need a library for this.

Is there a reason why this should be core and not an add-on in the asset library?

MOD music is a good way to do perfect looping and reduce the file size of music in your game. It would be really good to be able to just... Import it and see it working.

yankscally commented 3 days ago

This would be really good for things like web exports, when you need music but you want to keep the project size small in space.

MOD formats use a couple of short samples like drum hits and synth notes, and repitches them based on composition data. They end up being roughly 10% of the size of what it would be in .mp3 and tiny compared to WAV.

Being able to convert MOD to raw PCM data is novel with this library.

RedMser commented 2 days ago

This already exist as an extension: https://github.com/Dudejoe870/godot-openmpt

I don't see a strong argument for bringing this into core. It is further maintenance effort that can be circumvented by using the new interactive music player system. It would also increase build size for everyone by ~1 to 2 MB even if the feature is not used.

Calinou commented 1 day ago

Note that Opus could deliver smaller music files without being limited to tracker music too. 64 Kb/s audio is already pretty decent with Opus, assuming the source audio is lossless with good recording quality.

loteque commented 1 day ago

Adding tracker functionality would benefit those of us that like to compose dynamic music for our games by putting music composition tools right in the engine editor. Not only would it be a benefit to developers that already have experience with dynamic music, it would open doors for all the users who are learning and exploring video game development through Godot. I think it would improve Godot in the academic setting as well.

Just thinking about it momentarily, based on my experience writing dynamic music systems in GDScript, I feel that implementing tracker features in Godot would be far more straight forward than implementing something like fmod. fmod has library bindings already anyway as far as I am aware. As far as supporting MOD derived formats I don't know what that would require...

I can understand if this doesn't get prioritized right away, but it seems like a winning feature for a general purpose engine and a standout accessibility feature for one of the best all-purpose editors out there.

GeminiSquishGames commented 1 day ago

I like the idea of it and kinda didn't realize the interactive music thing was coming so soon, in the next version, so I started making noise too. The things I'm realizing are it's not as good of a match with how the AudioStreamPlayer works internally, it's a lot more code to maintain and think about on top of the Godot base Audio Engine, but most importantly are the caveats I'm starting to find when testing with the current plugin here: https://github.com/Dudejoe870/godot-openmpt. I think if there is a chance for this to be added, the first step would be to help test and make suggestions for that existing plugin. I think it makes a fine plugin too and it's very useable for what libopenmpt does, but the more I talk to the community the more I see that the way Godot is written and the needs of the majority of modern game composition, that it is probably better to officially support the Audio Engine classes and keep it all streamlined than add a low level, self-contained composition system that relies on external open source code.

We also have a lot of things to work on to make it appealing to old composers/new tracker users. One probably being compression and getting the above plugin to work with MO3-compressed files. libopenmpt has to include mp3 or ogg libraries like libogg to work and if we expect people to use entire stems as sample synth instruments doesn't really cut it, it needs to have compression for larger samples. And large samples don't really support realtime tempo/pitch changing that you can get with tracker instruments. There isn't really anything that can be done in trackers about that. We can use sample triggering to help time samples but to make that sound good takes dsp algorithms that tax the CPU in real time, detracting overhead from the actual game play. Even the pitch change effect on Godot buses mangles the frequencies and mid/side channels too much to be useful for music stems.

The use case for dynamic music, even modern-sounding music, is really great here. Having sample synth and OPL in the MPTM format would be amazing for neo-retro soundtracks and tiny files, but that probalby isn't the majority of use cases in game music in general these days, as even I have a need to just export my Reson/FL Studio stems directly rather than take the time to make them sound like I want as sampled synths without losing the dynamics and timbre of my more complex sounds like modeled synths. It's harder to make tracker music sound not dated, as much as I hate saying it.

Probably at this point, it's better to support the plugin that exists and use it for ideas to help make better what already exists and what can be incorporated with less fuss and maintenance. I've just started looking at the Godot source and trying my hand at playing with it... even I probably wouldn't want to try and add libopenmpt into it and maintain that relationship, as much as I love using tracker music. But the plugin certainly gets the functionality in and seeing on how people like it other than me, I think we can work together to make it an amazing addon.

Edit: Also maybe relevant but stopped support at Godot 4.1.1 is an FMOD addon: https://github.com/alessandrofama/fmod-for-godot

GeminiSquishGames commented 1 day ago

Note that Opus could deliver smaller music files without being limited to tracker music too. 64 Kb/s audio is already pretty decent with Opus, assuming the source audio is lossless with good recording quality.

I just kinda started working with Opus in FMOD recently. Is Opus something we can have as a sound file in Godot natively now/soon/someday?

Calinou commented 16 hours ago

Is Opus something we can have as a sound file in Godot natively now/soon/someday?

This should be discussed in the proposal I linked, not here.

PS: In the future, please use the Edit button (located behind the icon in the top-right corner of your comments) instead of multi-posting.