Language…
10 users online: cardboardcell, Dephrilibrium, Firstnamebutt, its_4life,  Kevin, KlonoA13Phill, Maab.kawahara, Murphmario, Philips, Zatara - Guests: 98 - Bots: 147
Users: 67,566 (2,007 active)
Latest user: Baschfire

How to use custom .brr in sfx

Custom MusicSamples

Heyo, I just wanted to share something I toyed with, which lets you use .brr files as sfx in Super Mario World. A special thanks to Torchkas for introducing it to me long ago, and to Vitor, which helped me figure it out.

This is an example, just go in the first room of this castle.
Yes, I could've used 8-bit samples and make a proper SFX, but it's just an example. You can potentially put anything as SFX with this method (see the fireball shoot in Super Wakana Land for example).
Sadly, it's going to be kind of tricky to do: you're, infact, supposed to edit ALL your custom musics in order to let your sfx play correctly. I guarantee it's totally worth the effort, and once you get it, it's going to be extremly fun to edit the original SFX!

What do you need is the following:
- a SMW.smc rom
- addmusick
- your custom .brr
- maybe a tiny bit of porting knowledge


Step 1: insert your sfx's data
In your addmusick folder, go in asm -> InstrumentData.asm. You should see this stuff in the bottom of it:

Code
SFXInstrumentTable:
db $70, $70, $00, $10, $06, $DF, $E0, $B8, $02 
db $70, $70, $00, $10, $00, $FE, $0A, $B8, $03 
db $70, $70, $00, $10, $03, $FE, $11, $B8, $03 
db $70, $70, $00, $10, $04, $FE, $6A, $B8, $03 
db $70, $70, $00, $10, $00, $FE, $11, $B8, $03 
db $70, $70, $00, $10, $08, $FE, $6A, $B8, $03 
db $70, $70, $00, $10, $02, $FE, $6A, $B8, $06 
db $70, $70, $00, $10, $06, $FE, $6A, $B8, $05 
db $70, $70, $00, $10, $00, $CA, $D7, $B8, $03 
db $70, $70, $00, $10, $10, $0E, $6A, $7F, $04 
db $70, $70, $00, $10, $0B, $FE, $6A, $B8, $02 
db $70, $70, $00, $10, $0B, $FF, $E0, $B8, $05 
db $70, $70, $00, $10, $0E, $FE, $00, $7F, $06 
db $70, $70, $00, $10, $00, $B6, $30, $30, $06 
db $70, $70, $00, $10, $12, $0E, $6A, $70, $03 
db $70, $70, $00, $10, $01, $FA, $6A, $70, $03 
db $70, $70, $00, $10, $02, $FE, $16, $70, $03 
db $70, $70, $00, $10, $13, $0E, $16, $7F, $03 
db $70, $70, $00, $10, $02, $FE, $33, $7F, $03


This is where all SMW's original SFX data is. Since we don't want to mess with the original SFX, we need to add new lines for our SFX. So do it like this:

Code
SFXInstrumentTable:
db $70, $70, $00, $10, $06, $DF, $E0, $B8, $02 
db $70, $70, $00, $10, $00, $FE, $0A, $B8, $03 
db $70, $70, $00, $10, $03, $FE, $11, $B8, $03 
db $70, $70, $00, $10, $04, $FE, $6A, $B8, $03 
db $70, $70, $00, $10, $00, $FE, $11, $B8, $03 
db $70, $70, $00, $10, $08, $FE, $6A, $B8, $03 
db $70, $70, $00, $10, $02, $FE, $6A, $B8, $06 
db $70, $70, $00, $10, $06, $FE, $6A, $B8, $05 
db $70, $70, $00, $10, $00, $CA, $D7, $B8, $03 
db $70, $70, $00, $10, $10, $0E, $6A, $7F, $04 
db $70, $70, $00, $10, $0B, $FE, $6A, $B8, $02 
db $70, $70, $00, $10, $0B, $FF, $E0, $B8, $05 
db $70, $70, $00, $10, $0E, $FE, $00, $7F, $06 
db $70, $70, $00, $10, $00, $B6, $30, $30, $06 
db $70, $70, $00, $10, $12, $0E, $6A, $70, $03 
db $70, $70, $00, $10, $01, $FA, $6A, $70, $03 
db $70, $70, $00, $10, $02, $FE, $16, $70, $03 
db $70, $70, $00, $10, $13, $0E, $16, $7F, $03 
db $70, $70, $00, $10, $02, $FE, $33, $7F, $03

db $30, $30, $00, $0A, $14, $FF, $E0, $7F, $01 ;1-UP
db $30, $30, $00, $0A, $15, $FF, $E0, $7F, $01 ;FIREBALL
db $30, $30, $00, $0A, $16, $FF, $E0, $7F, $01 ;JUMP
db $30, $30, $00, $0A, $17, $FF, $E0, $7F, $01 ;POWERUP
db $30, $30, $00, $0A, $18, $FF, $E0, $7F, $01 ;BUMP
db $30, $30, $00, $0A, $19, $FF, $E0, $7F, $01 ;COIN

(don't add commented stuff here btw, I only did it for tutorial purposes)
The added lines are the one in red, each defines a custom .brr. In the example (which is the .ips up there), I inserted 6 SFX.
The criteria of editing each byte there is explained in the .asm file, just scroll up a bit, or look here:

Code
; Format: 9 bytes per sample instrument.
; Byte 0: Left volume
; Byte 1: Right volume
; Byte 2: Starting pitch 1
; Byte 3: Starting pitch 2
; Byte 4: Sample (SRCN) number
; Byte 5: ADSR 1 / GAIN
; Byte 6: ADSR 2
; Byte 7: GAIN
; Byte 8: Tuning


Be cautious, in particular to the byte 4. The first sample you need to insert must be $14, since $13 is the last original SMW's SFX instrument. Also, if you plan to insert more than one, they should follow the order, byte 4 increasing by 1 for each line.

Save and close the .asm file, now your new SFX's data has been inserted! Although, now we need to replace the original SFX, as well as setting up each music.

Step 2: making a list of samples

In order to make things comfy, I highly suggest making your own samples set in "Addmusic_Sample_Groups.txt". Look this example, it should be easy to figure:

Code
#customSFX
{
	"optimized/00 SMW @0.brr"!
	"optimized/01 SMW @1.brr"!
	"optimized/02 SMW @2.brr"!
	"optimized/03 SMW @3.brr"!
	"optimized/04 SMW @4.brr"!
	"optimized/05 SMW @8.brr"!
	"optimized/06 SMW @22.brr"!
	"optimized/07 SMW @5.brr"!
	"optimized/08 SMW @6.brr"!
	"optimized/09 SMW @7.brr"!
	"optimized/0A SMW @9.brr"!
	"optimized/0B SMW @10.brr"!
	"optimized/0C SMW @13.brr"!
	"optimized/0D SMW @14.brr"
	"optimized/0E SMW @29.brr"!
	"optimized/0F SMW @21.brr"
	"optimized/10 SMW @12.brr"!
	"optimized/11 SMW @17.brr"
	"optimized/12 SMW @15.brr"!
	"optimized/13 SMW Thunder.brr"!

	"customSFX/1up.brr"
	"customSFX/fireball.brr"
	"customSFX/jump.brr"
	"customSFX/powerup.brr"
	"customSFX/bump.brr"
	"customSFX/coin.brr"
}


Here, I copypasted the #optimized samples set, then added my samples just after it (look the red lines), then gave it a name, #customSFX. I suggest doing so, since you'll have more room if you use #optimized as base.
Do note that my samples are in a folder called "customSFX" inside the "samples" folder of AMK (note the "customSFX/1up.brr"). I suggest you doing so as well, so that your samples folder won't look too messy.

Let's move ahead! Now that we have our sample set, let's replace the original samples!

Step 3: replacing the original sfx

As you maybe know, SMW has its SFX organized in 2 folders in AMK, "1DF9" and "1DFC". Each folder contains a part of all the SFX played in SMW.
Due to the very simple nature of this method, you just need to replace the mess of $XX values with one note playing. Either replace, or add, but we're going to just replace, since it's simpler.
The important thing to take note of is the order of the samples you stored in the instrumentdata.asm and in your sample set. If you follow my same scheme (used #optimized as base), the 1up will be sample @19, the fireball sample @20, the jump sample @21 and so on, till the coin sample being @24.

So how do we replace? Simple! As I said before, it's just a note playing. Let's do this, take a look on my "05 1-UP.txt", located in the 1DFC folder:

Code
@19 v50 f2 $00


Simple, no? @19, since it's the 1-up.brr, vXX sets the volume (iirc v127 is the highest volume for sfx), >f2 is my note, and $00 is an ending note. This could've been replaced with a rest, like r8.

If your sample is out of tune, either change the note, or the tuning byte in instrumentdata.asm.
If the sample cuts off in-game, increase the lenght of it, smallest being like 64 and the biggest being 1.

The method is the same for all the other samples! For the fireball you need the same line, except put @20 instead of @19 (again, mind the order of your samples in the sample list!), jump is @21... which one is for the coin? Yes, @24!

Since you got it, let's go to (finally) the last step, maybe the most tricky to do, which is adding your SFX in every song you have in your hack.

Step 4: placing samples in your music.txt

If you played the .ips, you noticed it's imamelia's "New Super Mario Bros Wii - Koopa Kid's Castle". If you insert it in your rom as it is now, it will do nothing... actually, your samples won't play at all. In order to fix that, you need to edit the .txt a little bit. Look my example here:

Code
#am4
#samples
{
#customSFX
}
#instruments
{
"customSFX/1up.brr"	$00$00$FF$04$00
"customSFX/fireball.brr"$00$00$FF$04$00
"customSFX/jump.brr"	$00$00$FF$04$00
"customSFX/powerup.brr"	$00$00$FF$04$00
"customSFX/bump.brr"	$00$00$FF$04$00
"customSFX/coin.brr"	$00$00$FF$04$00
}

; **************************************************************
; New Super Mario Bros. Wii - Koopa Kid Castle
; ported by imamelia
[...]


Okay, so what do we see here?

#samples
{
#customSFX
}

First, we set our own sample set (#customSFX) in #samples. Do note that if your music already has a #default, or an #optimized, you're supposed to replace it with yours!

Next:

#instruments
{
"customSFX/1up.brr" $00$00$FF$04$00
"customSFX/fireball.brr"$00$00$FF$04$00
"customSFX/jump.brr" $00$00$FF$04$00
"customSFX/powerup.brr" $00$00$FF$04$00
"customSFX/bump.brr" $00$00$FF$04$00
"customSFX/coin.brr" $00$00$FF$04$00
}

...the instruments (mind the order again!). Do note that these must be on the very top of the #instruments table! If I had something like this:

#instruments
{
"trumpet.brr" $FF$E0$00$05$32
"saxophone.brr" $FF$E0$00$02$72
"piano.brr" $FF$E0$00$0A$92
[...]
}

You need to change it like this:

#instruments
{
"customSFX/1up.brr" $00$00$FF$04$00
"customSFX/fireball.brr"$00$00$FF$04$00
"customSFX/jump.brr" $00$00$FF$04$00
"customSFX/powerup.brr" $00$00$FF$04$00
"customSFX/bump.brr" $00$00$FF$04$00
"customSFX/coin.brr" $00$00$FF$04$00
"trumpet.brr" $FF$E0$00$05$32
"saxophone.brr" $FF$E0$00$02$72
"piano.brr" $FF$E0$00$0A$92
[...]
}

Sadly, this will move all the @XX definitions in your music, so be sure to fix this. If this was my case, I had to replace all the @XX of the .txt with @XX+6, since we moved them by 6 slots because 6 samples.

Save, and finally insert the music in your rom.
Now the new SFX will play in the level your custom music is in! It will glitch in any other music, though, so be sure to apply step 4 to all your custom musics!

Note that you still may need to tune it properly, or resize the lenght of the note it plays. Sadly, the .spcs generated by AMK won't help, so you'll have to test in game and edit each time, until you get the right tuning and the right lenght.




That's it so far! Hope it's understandable for anyone. This should hopefully set the birth to more romhacks with custom SFX as brr files.
Any question (or if I said something wrong there), please, feel free to post!
Awesome tutorial! Thank you so much for putting this together. I've been trying to figure this out but I don't think I would have realized I had to add the samples and instruments to my custom songs on my own.
Someday, I will finish what I sta-
Originally posted by Skewer
Do you have a solution for this particular error? And if so, please include the solution to the tutorial for those who may run into it as well. Thanks!

The issue here is the sample, not the tutorial itself: whoever made the .brr messed up the starting/ending loop point (which should be multiple of 16); he most likely used snesBRR as well, which I don't suggest: I'd use the method with C700 addon instead, which grants 100% functionality (since it takes cares of correct loop points by itself).
For more info, see this chapter of my porting tutorial, and check "ripping samples from external resources".

Edit: post was deleted but basically a sample wasn't inserting because it gave issues about its length.
Just to further clearify for those who had trouble with SFX, basically instead of putting in @19 v50 f2 $00 in your txt folder, you should be inserting this:

Code
$DA $xx
$7F $vv $DD $hh $00 $7F $hh
$7F $vv $EB $00 $7E $hh


Basically, $xx is the replacement for the @19 slot (in hex, so 13). $vv is the volume with the limit of $7F (anything above it will crash). $hh is the pitch of the note itself (keep in mind it should be really high, so like A0-FF). If you want to extend the note, you put in another "$7F $vv $EB $00 $7E $hh" under it. It's recommended to keep all $vv and $hh values the same to make sure it doesn't change pitch (unless that's what you want).

Give credit to worldpeace, since he taught me how the format works.
Want progress on 100 Rooms of Enemies: The Nightmare Edition? Go here to see.

(rip my other userbars momentarily)

I believe you can generate SPCs by putting the following command in a .bat file:
Code
addmusick -dumpsfx


Never tried it before, but it should work.

Edit: Fixed a typo with the batch command.
My Mode 0 guide.

My Discord server. It has a lot of archived ASM stuff, so check that out!

Custom MusicSamples