Add a suggestion on looping seamless music#266
Conversation
MP3 can introduce a gap in looping music when looped. Ogg is preferable.
|
In my experience Ogg also introduces a gap when looping it using libGDX Currently, afaik, the only working solution to avoid this issue is to use gdx-miniaudio (https://github.com/rednblackgames/gdx-miniaudio). If we add a recommendation in the wiki regarding this issue, I think gdx-miniaudio should be mentioned. EDIT: I see it's already recommended here https://libgdx.com/wiki/audio/audio |
Frosty-J
left a comment
There was a problem hiding this comment.
I've been wanting to update those music and sound effects pages but scope creep got the better of me.
My advice would be to not use MP3 unless your music came in that format and you don't wish to re-encode. It has full compatibility across libGDX platforms (iOS was the problem child), and that's all. Ogg doesn't have the gap issue in the codec itself (mileage will vary by platform, e.g. Music on Android will still add a really big gap) and is higher fidelity for the same bitrate, plus the desktop module is slower than it really should be at decoding and seeking MP3. Most importantly of all, the Vorbis logo looks so cool and is Creative Commons.
Having a paragraph about gapless looping isn't unreasonable, given it's such a common requirement in video games. gdx-miniaudio is third-party, but in all honesty libGDX's own audio handling is just a thin wrapper designed around the lowest common denominator (Android, maybe even the very first version of it) and thus isn't the best. TuningFork could also be worth considering for desktop-only games.
My prior experience was desktop (LWJGL) looped fine with Ogg. I think using MediaPlayer#setNextMediaPlayer on Android worked (wouldn't be surprised if results vary by device, though) but I didn't propose making libGDX use that as then either every Music instance would use two MediaPlayers (adding some degree of runtime weight) or a gapless looping overload would have to be added (messy, especially if only applicable to one platform).
For web games, you can exclude your music from the preload filter and do not use AssetManager, then Music just streams from the server. This allows you to loop the music before encoding the file, to be an hour long or however much you think is longer than the user will hear during gameplay, without increasing load times. Upload size isn't too bad if using (HE-)AAC or Opus (the former supports iOS < 18.4), and the largish audio only has to be uploaded once if only uploading build deltas (e.g. itch.io butler). A stupid hack for sure, when I believe this could be fixed at the WebAudio level (and also fixing games causing playback controls to appear in notification area), but hey, it works (unless internet connection is lost).
| float position = music.getPosition(); // returns the playback position in seconds | ||
| ``` | ||
|
|
||
| Music that should loop seamlessly may work better in the Ogg format due to the limitations of MP3 (see 'Why cant MP3 files be seamlessly spliced together?' at [LAME Technical FAQ](https://lame.sourceforge.io/tech-FAQ.txt)). |
There was a problem hiding this comment.
Clearly I will get carried away again. I approve of this addition, as it's better than having nothing at all!
I don't object recommending Ogg for Desktop and GWT to fix the gap, just needs to be specified it only applies to those backends. iOS doesn't support Ogg and on Android, as you acknowledge there's still a large gap. For Android and iOS I'd add a recommendation to use gdx-miniaudio so that the recommendation covers all libGDX backends. |
|
Thanks both for your feedback. Though I'd draft a new paragraph here rather than make multiple commits to the PR, so it's at the end of this comment. Some notes on the feedback:
Anyway, here is the rewritten paragraph on seamless music: If you have music that needs to loop seamlessly be aware that whilst the MP3 format is compatible across all platforms it has technical limitations preventing fully seamless play (see 'Why cant MP3 files be seamlessly spliced together?' at LAME Technical FAQ). The approach to solving this will vary depending on the platforms you need to target:
|
|
Looks good to me! Considering it's several paragraphs and goes quite deep I would add it as a minor subsection with it own title (using markdown |
I learnt this today in the discord - MP3 can introduce a gap in looping music when looped, Ogg format can solve the problem. Thought this was useful in the wiki.