Users browsing this thread: 1 Guest(s)
Adding a New BRR Sample

#1
Posts: 3,969
Threads: 279
Thanks Received: 236
Thanks Given: 57
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
Adding a new BRR Sample

This tutorial is also hosted on the FF6 wiki.

In this tutorial we'll be using FF3us to add a new BRR sample that can be used in songs. You do not need extended musical knowledge to complete this tutorial. One thing that will help is being familiar with the hexadecimal system, the concept of offset, the difference between an absolute and HiROM offset and hex editors.

1. Getting the file and tool

We'll be using the FF5 bass drum sample from our BRR Sample Database. The only thing that you will need is a hex editor. There are many you can choose from, but I'd suggest one that has copy selection, paste-write, and paste-insert functionalities. One good all-purpose hex editor is HxD, and this is what has been used to take the screenshots below. Finally make sure you have a 1.0 or 1.1 FF3us ROM that is expanded either to 28Mbit or 32Mbit.

2. File we will be importing

Select the second download on the FF5 page, the one labeled "BRR Samples with first two bytes as sample length. Pitch, loop and ADSR data are in a text file.". Extract the archive and you are done for now.

3. Changing the Code

Since each sample has data attached to it, we need to move this data first to make some room for the new sample data. What need to be moved is loop start positions, pitch  multipliers and ADSR data. The pointers to the BRR data do not need to be relocated, for the simple reason that we will free the space right after them, thus leaving room to add more.

[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:1.png]

We will put the loop starting positions at $F20000, the pitch mutipliers at $F20200 and finally the ADSR data at $F20400. This leave enough room for the maximum of 256 samples.

There are 3 ASM instruction to modify, more precisely the offset that these instruction carry. Below is the original and modified code. Open HxD and press Ctrl+G, that will open a window. Type 05041C and press "Ok". You are not at $C5041C. You need to enter 0000F2 ($F20000 inverted). We do not touch the 1st byte of the instruction, only bytes 2,3,4. Repeat a similar process for $C5049C and $C504DE.

Original code
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:2.png]

Modified code
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:3.png]

4. Moving the Data

Let's move first the loop starting positions. Select the data from $C53D1C to $C53D99 as shown on the left below and press Ctrl+C. Press Ctrl+G and enter 320000 ($F20000 in HiROM offset).  Right click and press "paste write". The result should be like the right screenshot:

[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:5.png] [Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:8.png]

Redo this process for the pitch multipliers at $C53D9A and the ADSR data at $C53E18:

Pitch multipliers
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:6.png] [Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:9.png]

ADSR data
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:7.png] [Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:10.png]

5. Adding the new sample data

Now we will add the data for the new sample. For more info on these 3 sample data, refer to the last 3 sections of this tutorial. Open the FF5.txt file in the sample archive and look at the 1st line. You'll see the three values that we need to add. Simply append 8C0A to the loop starting positions, append C000 to the pitch multipliers and append FFE0 to the ADSR data. The 3 following screenshots show this:

Loop starting position
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:12.png]

Pitch multiplier
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:13.png]

ADSR data
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:14.png]

6. Importing the Sample

We need after this to import the actual sample. Open 01_bass_drum.brr with HxD, select all (Ctrl+A), copy (Ctrl+C) then "paste write" at $F20600. The two screenshots below show the beginning and the end of the sample:

Beginning
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:15.png]

End
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:16.png]

Finally we will add our new BRR pointer. Go at $C53D1C and add 00 06 F2 ($F20600 inverted). Note that in the screenshot below I replaced all the (now) useless sample data with FF. You can now use your new sample ($40) in the instrument data of a song (32 bytes each starting at $C53F95).

[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:17.png]

This cover the mechanical part of the import. Further down will be detailed how to change ADSR data, loop starting positions and pitch multipliers. Not all samples in the [link|BRR Database] are "plug and play" like the FF5 samples. Some require data modifications.

A. Loop Starting Position

Those two bytes are a looping position. As an example, for a sample of size $0900, he could have a loop position of $0850, meaning once the read reach $0850, $0850 to $08FF will loop. That loop position would be written 5008 in the ROM. A loop position is obviously always smaller than the sample length. The loop starting positions of the samples in the BRR Sample Database are in the most case good.

B. ADSR Data

The ASDR Data is a two bytes value that apply an Attack Rate, Decay Rate, Sustain Level and Sustain Rate envelope to the sample. The format is the following, high bit of 1st byte tells if ADSR is enabled, otherwise Gain is used. Attack is on 4 bits, Decay on 3 while the 2nd byte has Sustain (3 bits) and Release (5 bits). The ADSR data of the samples in the BRR Sample Database are in the most case good. As an example and ADSR value of FFE0 is Attack Rate of 15, Decay Rate of 7, Sustain Level of 7 and Sustain Rate of 0.

[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:adsr.png]

Note that the ADSR settings on SNES are a bit different than the usual ADSR. A quick overview:

 Legend Name Values  Description  Maximum
A  Attack Rate   0 to 15   higher is shorter   maximum 4100ms (at 0)
D  Decay Rate   0 to 7   higher is shorter   maximum 1200ms (at 0)
S  Sustain Level   0 to 7   higher is louder   0% to 100% of initial sound
R  Sustain Rate   0 to 31   higher is shorter   maximum 38,000ms (at 1); 0 is infinite

C. Pitch Mutiplier

The pitch multiplier is a two bytes value that is added to the note multiplier of a note to result in the pitch of the played note (VxPITCH). The game use the following table and formulas to get the correct pitch of a note:

Note modifiers
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:18.png]

Formulas
[Image: fetch.php?media=ff3:ff3us:tutorial:music:brr:19.png]

Note that the pitch multipliers in the BRR Sample Database are good for all the Squaresoft games except FF4, Romacing Saga 1, Seiken Densetsu 3, Super Mario RPG, Bahamut Lagoon and Treasure of the Rudras. Those game will need modifications to their pitch values.
  Find
Quote  
[-] The following 3 users say Thank You to madsiur for this post:
  • emberling (10-20-2018), Gi Nattak (10-20-2018), Lightning (10-21-2018)

#2
Posts: 311
Threads: 20
Thanks Received: 0
Thanks Given: 0
Joined: Dec 2017
Reputation: 2
Status
None
Good job on this! I was just looking for the tutorial on how to import samples a few days ago, and it said "this topic no longer exists", so this is perfect. I might mess with this later on to see if just a few samples works or not on my Everdrive.
  Find
Quote  

#3
Posts: 311
Threads: 20
Thanks Received: 0
Thanks Given: 0
Joined: Dec 2017
Reputation: 2
Status
None
Hey Madsiur, just thought I would let you know that I ran through your tutorial and successfully imported some FF5 samples! Not only that, it works on my Everdrive, which is great news. I think the problem I ran in to before on my Everdrive was due to save corruption. Every single time I update anything big on my mod, I now rename the mod file and save file, otherwise some data seems to carry over. I haven't encountered any issues since doing this.

By the way, the only bug I noticed in your tutorial was this:
Code:
You can now use your new sample ($30) in the instrument data of a song (32 bytes each starting at $C53F95).

The $30 should actually be $40. $30 is the "Wood Block" sample from the original game. Wink
  Find
Quote  

#4
Posts: 3,969
Threads: 279
Thanks Received: 236
Thanks Given: 57
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
(10-22-2018, 06:44 PM)Lightning Wrote: The $30 should actually be $40.  $30 is the "Wood Block" sample from the original game.

I'm glad the tutorial was helpful! And good news for the Everdrive! I'll correct that mistake soon.
  Find
Quote  



Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite