A Guide to Looping Music

Share guides you have written for SMBX, and related tools here.
Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9834
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

A Guide to Looping Music

Postby Emral » Thu Jul 11, 2024 5:15 am

Various flavours of SMBX, including SMBX2 and TheXTech, support the SDL Mixer X library which lets you use a lot of different file formats, beyond just MP3. These come with perks and features that you might be interested in!
In this guide I'll go over some of the more common ones and how they relate to one feature in particular: Seamless looping, something that mp3s cannot do (back in the day we used to pack 15 minute extended mixes into our level packs. You needed 20MB to download any level!)

Peak Convenience: Old-timey game formats (spc, nsf, gbs, vgm and so forth)
These formats come with 2 super cool perks: tiny filesize, and automatic looping. If you're looking to use tracks from a SNES game, Sega Genesis game or other such old-timey device, you instantly get both of these perks without having to do anything special. You can simply use the files as you would mp3s. Some formats, such as nsf, are so compact they contain all the games sounds at once! If you click "download original music files" on this page, you'll get a zip that has just one file in it. Wild! How do you select which track to play? The editor has a menu that helps you with that:
Spoiler: show
Image
The "Previous" and "Next" buttons control which track in a collection of tracks to play back. You can listen to it with Play music. I like to increase the gain if the track is quiet in-game, but be careful of clipping at higher gains!
Even if your music is more modern, occasionally you can find some talented people porting tracks from old games to a tracker format or game format via a site like SMWCentral's music section. I've been digging into Kevin and Masterlink's impeccable ports of Superstar Saga music lately. If you're using ports like this, make sure to credit the porter as well as the original artist(s).

So that's awesome! All you'd ever want! Unless...

The All-Rounder: OGG/OPUS
My rule of thumb is "if you can't go for peak convenience, always go ogg/opus". While reality is more nuanced for sure and every format has its niche, you can make hundreds of levels using all kinds of different music before ever running into such an edge case.
Functionally, ogg and opus are both part of the vorbis codec. For the purposes of what we care about, they are interchangable.
Their perks include: Loop point support, but a similar filesize to an MP3 of the same length and quality. (100-1000x the size of a SPC, usually between 600KB and 6MB).
So what you really want here is the loop point support. So how do you do that?
There are multiple ways. I will go over two ways in this guide.

Creating Looping OGG Music manually using Tenacity or older versions of Audacity
VIDEO TUTORIAL
! Newer versions of Audacity (since version 4 or so) may cause the above tutorial to not work anymore. I recommend using Tenacity if you follow this method.
Steps:
1. Obtain an MP3 file of the music you wish to use
2. Download either Tenacity or an older version of Audacity.
3. Open the file with your program (I'll say Tenacity)
4. View the video tutorial above to see how to track down the loop points.
4.5. Once you found the loop point, you can delete everything ~0.5 seconds after the end of the loop. This is not a necessary step, but it can save on file size if this is something you care about.
5. Export as an ogg file. During export, specify the LOOPSTART and LOOPEND tags. This is what SMBX will read to make the music loop.

This method is fine and has served users well for years. However, many find it tedious to find the loop points, especially during more atmospheric tracks.

Creating Looping OGG Music automatically using Pymusiclooper
Pymusiclooper Github

Pymusiclooper is a tool by github user arkrow. It's a terminal program written in python that can find your music loops and export ogg automatically. The setup for this can be very intimidating, because it involves using a terminal and pretending you're a superhacker. But together we can get through this. Ready?
Setup:
1. Install python. I use 3.10.10. Any version above 3.9 should work. If you're unsure which to get, scroll down on this page, locate 3.10.10 and download, then install.
2. Once python is installed, follow the instructions on the Pymusiclooper Github linked above to install pymusiclooper. This boils down to these steps:
a. Open a terminal window
b. Copy-paste this line and hit enter: python -m pip install pipx
c. Once the command completed, repeat for the next one: python -m pipx install pymusiclooper
d. One more time! Wait for it to finish, then this: pipx upgrade pymusiclooper
Now you should have pymusiclooper installed. If you run into any issues during this step, leave a reply and I will do my best to help you.
2. Download this file. It is a script I wrote that makes this tool easier to work with.

Now you should be ready to loop music. Follow the next steps to loop your first piece of music with this method:
1. Obtain a MP3 file you wish to loop.
2. Use Tenacity to export it as an ogg file.
3. DRAG AND DROP THE OGG FILE ONTO THE ogg_looper.bat FILE. It should open a terminal and have a loading bar. After loading completes, it should look like this:
Image
4. From here, test out the different loop points until you find one you like. Type 0p and then enter to test the first one. 1p for the second one. There can also be more.
5. Once you found one you like, simply type the same number but without p, hit enter, and it will export the file into a subfolder titled LooperOutput! Now your file is looped and ready for use!
6. Optional step: Now that you know the loop endpoint in seconds, you can go back into tenacity with the newly exported file and cut away all excess track at the end. If you care about filesize. Re-export and you're set!

If you're someone who struggles a lot with making music loop, I hope you'll be able to benefit from this second approach. I found it just recently, and it has already saved me countless headaches.

EPILOGUE

If you're a developer and interested in improving the quality of life of making music loops with me, there is still some more work that can be done. Using pymusiclooper together with ffmpeg, it may be possible to expand the batch script to take an mp3 file, prompt the user to select their favourite loop point, and then afterwards export into a converted ogg with the stray bits at the end already cut out. This would mean that audacity/tenacity become entirely obsolete for the pymusiclooper approach. Additionally, since the setup is very daunting, it would be helpful to have a script that handles all the installation.
I can't make any promises that I will be the one to write any of these improvements, but if anyone with a vision and hacker fingers wants to give it a shot, the stage is yours. I hope that over time we can get rid of the frustrating aspects of making a level.

mariobrigade2018
Volcano Lotus
Volcano Lotus
Posts: 510
Joined: Wed May 24, 2023 7:00 pm
Flair: Normie in coding who dreams of making a Mario game
Pronouns: he/him

Re: A Guide to Looping Music

Postby mariobrigade2018 » Wed Nov 20, 2024 9:00 am

Emral wrote:
Thu Jul 11, 2024 5:15 am
2. Download this file. It is a script I wrote that makes this tool easier to work with.
Where do I put the file?

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9834
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: A Guide to Looping Music

Postby Emral » Wed Nov 20, 2024 5:31 pm

mariobrigade2018 wrote:
Wed Nov 20, 2024 9:00 am
Emral wrote:
Thu Jul 11, 2024 5:15 am
2. Download this file. It is a script I wrote that makes this tool easier to work with.
Where do I put the file?
Somewhere you can easily remember. If you read a few lines further you see the only thing we do with it is drag other files onto it.

Marioman2007
Lakitu
Lakitu
Posts: 497
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: A Guide to Looping Music

Postby Marioman2007 » Tue Nov 26, 2024 12:04 pm

Thank you so much for the pymusiclooper tool and the bat file!


Return to “Guides”

Who is online

Users browsing this forum: No registered users and 0 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari