[X2] Dynamic music using multi-track OGG files

Share guides you have written for SMBX, and related tools here.

Moderator: Userbase Moderators

MrDoubleA
Edward
Edward
Posts: 394
Joined: Mon Aug 20, 2018 7:02 am
Flair: How much munchers?

[X2] Dynamic music using multi-track OGG files

Postby MrDoubleA » Sun Apr 20, 2025 10:34 am

SMBX2 has support for OGG files with multiple tracks and has the ability to individually toggle those tracks.
Here's a video with an example of this:



This guide will describe the process of creating something like this, using this music as an example.
Some minor notes:
  • This will only cover stereo music and not mono audio.
  • This will only cover OGG files, although step 4 can apply to any music format that has multiple tracks (including SPC, MIDI, etc.)
  • Audacity will be assumed to be used. Or, more specifically, Tenacity, but the steps should be the same in both.

1. Setting Up an Audacity Project

You must create an Audacity project where each track of your music is one separate stereo layer, as such:

Image

You should also be sure to save it as a proper Audacity project file, to make it more convenient to change later if necessary.

2. Exporting

By default, Audacity will crush all the tracks into one when exporting as an OGG file. There is a setting to change this, called "advanced mixing options":

Image
Image

When exporting, you'll get the following additional prompt:

Image

In a simple case like this, where one track in Audacity corresponds to one track in the export, it can be left as-is. However, if that is not the case, you will have to manually pair each L/R pair on the left to a pair of channels on the right.

Afterward, it can be exported as normal (including looping).

3. Setting Metadata

If you play it in-game, currently, it will play all the tracks together with no way of controlling them individually. To fix this, you need to add metadata to the music field in-editor.
You may be familiar with adding a "gain" option to an SPC file by adding extra settings after the path. This works similarly.

For my three-track example, I used this:

Code: Select all

Rainy Day.ogg|m1;c2;r3
"m1" enables the multi-track functionality;
"c2" is the number of channels per track (so 2 for stereo audio, 1 for mono);
"r3" is the number of tracks (so 3 in this case).
In practice, you'll probably only want to change r.

OGGs support up to 32 channels, so you can go wild (although maybe keep file size in mind).

4. Making it Dynamic

Now, we can use Lua code to actually make it dynamic. This is done through this pair of functions:

Code: Select all

Audio.MusicInstChannelMute(trackIndex)
Audio.MusicInstChannelUnmute(trackIndex)
trackIndex is a number starting from 0.
In my example, the tracks are 0 (the base layer), 1 (the "working" layer) and 2 (the "treasure" layer).

You can call these from pretty much wherever you want in your Lua code.
By default, all tracks will be unmuted.
To give a useful example, here is code (for a luna.lua file) that mutes track 1 when the level starts, but unmutes it when a certain event is triggered:

Code: Select all

function onStart()
    Audio.MusicInstChannelMute(1)
end

function onEvent(eventName)
    if eventName == "example event" then
        Audio.MusicInstChannelUnmute(1)
    end
end
And after that, you should be good to go!

Marina
Cecil
Cecil
Posts: 2380
Joined: Sun May 25, 2014 7:01 am
Flair: everything's still romantic, right?
Pronouns: she/her/they/them

Re: [X2] Dynamic music using multi-track OGG files

Postby Marina » Sun Apr 20, 2025 10:52 am

WE SHALL HAVE A SPRING WEDDING

FutureNyanCat
Eerie
Eerie
Posts: 765
Joined: Fri Dec 20, 2013 8:39 pm
Flair: Species: Felis robotus
Pronouns: He/Him
Contact:

Re: [X2] Dynamic music using multi-track OGG files

Postby FutureNyanCat » Sun Apr 20, 2025 11:42 am

Thanks for the tutorial, that was pretty easy to get it working! I didn't think multi-track OGG files would be compatible with SMBX2, but here we are now.

PizzaNoob
Bot
Bot
Posts: 53
Joined: Wed May 29, 2024 8:36 pm
Flair: I like to make comics!
Pronouns: he/him

Re: [X2] Dynamic music using multi-track OGG files

Postby PizzaNoob » Sat May 10, 2025 3:06 pm

THis is awesome! However, where can I find video game music with multiple tracks?

Thundaga_T2
Ripper II
Ripper II
Posts: 352
Joined: Wed Jun 11, 2014 6:31 am

Re: [X2] Dynamic music using multi-track OGG files

Postby Thundaga_T2 » Mon May 26, 2025 4:48 pm

How would i do this for adding an underwater track to a level?


Return to “Guides”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari