How to add custom soundbanks by fznmeatpopsicle - dbc60/Render96Wiki GitHub Wiki
-
Step 1. Convert the sound to
.AIFF
. The sound in question must be single channel. -
Step 2. Create a new folder in sound/samples. Can be named anything. For the sake of the tutorial, let’s call it "custom"
-
Step 3. in sound/sound_banks/ copypaste one of the soundbank
.json
files. Let’s say "00.json". Rename it to be the next bank after the last one by value. The next available bank number is 26, so name it something like "26_custom" -
Step 4. Open up your new json. You’ll have to modify certain blocks:
"date": "1996-02-14", "sample_bank": "sfx_1", "envelopes": { "envelope0": [ [2, 32700], [1, 32700], [32700, 29430], "hang" ] },
Change the "sample_bank" to the name of your custom folder so: "sample_bank": "custom",
You can leave everything else alone.
The following chunks are the main part to modify: "inst0": { "release_rate": 208, "envelope": "envelope0", "sound": "00_twirl" },
You only need to modify the first line and the "sound" part. Starting with 0, change "inst0" to the next sequential number(These are counted in normal decimal numbers, not hex). Then change "00_twirl" into the name of the file you want it to be, minus the file extension. I don’t think having a number at the start of the filename is necessary, but it’s at least useful for organisation, especially if they’re numbered in hex. You can add as many sounds as you need to, just remember to change "inst0" accordingly. You can leave release rate at 208 if your sound doesn’t need any speed adjustments. Finally, remember to add a comma after every sound, but make sure the last one does not have one.
Now add the new instrument to the list below in "instrument_list"
"instrument_list": [ "inst0", "inst1", "inst2", "inst3", "inst4" ] You’ll need one for every sample you created above.
-
Step 5. Now that you’ve created the new bank, you’ll need to add it to the sequences list. In "sound/sequences.json" is a list of all the tracks and what sound banks they use. We need to look at the first one: "00_sound_player": ["00", "01_terrain", "02_water", "03", "04", "05", "06", "07", "08_mario", "09", "0A_mario_peach"],
This is the sound effect track, and which sound banks it used. We’re gonna add our bank to the end of it after "0A_mario_peach". So take the name of your bank, and add it to the end. For the sake of the tutorial it was "26_custom", so you should have: "00_sound_player": ["00", "01_terrain", "02_water", "03", "04", "05", "06", "07", "08_mario", "09", "0A_mario_peach", "26_custom"],
*Note the position of the bank. Starting from 0, it’s the 11th bank in the list, so this makes it bank 11.
-
Step 6. In
/sound/sequences/00_sound_player.s
, let’s define the new sound. Find the channel table of the sounds. they are namedchannelX_table
. Let’s add it to bank 0; that’s "channel0_table". The other channel names are located at the top of the document. I have tried adding to other banks but they all seem to respond differently to new sounds. Channel 5, for instance, straight crashes the game. Scroll down to the bottom of the table, "channel0_table", and add your new sound:
sound_ref .sound_new_sound
Next we’ll actually create the sound. I don’t believe it matters where you define the sound. You can either put it at the very end of the file, or at the end of the table of whatever channel you’ll be adding it to. The new sound will look like this:
chan_setbank 11 chan_setinstr 0 chan_setlayer 0, .layer_new_sound chan_end
In order is: The name of the sound, the bank to play from, which sound in the bank to play, and the layer(how to play it). As noted above, our custom sound bank is bank 11. The first sound in the bank is 0, and the layer is the script that controls the pitch and duration of the sound itself. We’ll make new layer now:
layer_note1 39, 0xc8, 127 layer_end
The name of the layer can be called whatever you want, as long as it starts with ".layer_". Make sure it matches the name you declared in the sound previously. The "layer_note" is the note at which to play the sound. I don’t know what the first value is(maybe the key?), but I’m pretty sure the second one is the actual note. The last value is the volume of the note. 127 is the maximum. The values in the example should play the sound as normal(maybe a couple notes down?). You can add multiple notes, so layer_note2, layer_note3, etc. There is also other effects and stuff you can add, but you’ll need to experiment by looking at other sounds and layers.
Your new sound is now technically ingame, but there is a few more steps to go.
-
Step 7. Next up, open up
/include/audio_defines.h
and find the bottom of bank 0’s defines and add a new member. By default, the last member of bank 0 is:
#define SOUND_ACTION_INTRO_UNK45F SOUND_ARG_LOAD(0, 4, 0x5F, 0x80, 8)
Copypaste that line underneath and rename it to the name of your sound. In our case it will be:
#define SOUND_NEW_SOUND SOUND_ARG_LOAD(0, 4, 0x5F, 0x80, 8)
The first value of "SOUND_ARG_LOAD" is the channel it plays on. It needs to match the bank you’ve created the new sound in, so in our case it’s 0. I don’t know what the second value is, so let’s leave it alone. The third value is the sound ID. This one is very important, but we’ll get to that in a moment. The forth value is the priority of the sound. Sounds with higher values will interrupt and play over sounds with lesser values. I don’t know what the last value is, so let’s also leave it alone.
The third value, or Sound ID, previously 0x5F, represents the position in the sound table it’s drawing from. Take a look at the table in "00_sound_player.s" and find the position of the last applicable sound in the defines. This will help you determine the position, because it most likely won’t just be "0x60". "SOUND_ACTION_INTRO_UNK45F" can be found further up the table, so take that position, and then count down till you hit the bottom. You should be thinking of "0x70", after "sound_action_jump_default".
-
Step 8. The sound in theory is now able to be played, but there’s still a tiny bit more that needs doing before it’s fully ready to use. Firstly, the audio system has a bounding table used for looking up sounds. 0x70 in bank 0 is out of bounds and therefore won’t be played, so the bounds must be expanded.
In "/src/audio/external.c", look for the struct called "sNumSoundsPerBank". These are the bounding values. You can safely change them all to 0xFF, and you don’t realistically have to worry about out of bounds indices ever again.
-
Step 9. Your sound is finally ready for use ingame. Just use any of the sound playing functions, like:
play_sound(SOUND_NEW_SOUND, gDefaultSoundArgs);