Banner
Views: 924,134,972
Time:
18 users online: anonimzwx,  BeeKaay, Blue Leaf, bruninhopz, Bumpty, Daizo Dee Von, Ezel,  FPzero, Francium, Jazzman287, KatMakes, lordkronos100, MMaxwell, Morph Moth, RichardDS90, softandwet, TomNook, YouFailMe - Guests: 74 - Bots: 76 Users: 51,681 (2,050 active)
Latest: Ollati12
Tip: Switch palace switches normally disappear if you replay the level. However, if you insert them as direct Map16 and use the hex edit at $00EEB2 in the ROM map, you can replay the level without a problem.
Not logged in.
[Semi-Tutorial] Fixing The ADSR Bug+Using GAIN in AddMusic 4.05
Forum Index - SMW Hacking - SMW Hacking Help - Tutorials - Old Tutorials - [Semi-Tutorial] Fixing The ADSR Bug+Using GAIN in AddMusic 4.05
Pages: « 1 » Link
Hey guys, I figured it would be a good idea to share this information imamelia taught me (Thanks, man!). This is a method of storing samples (SMW samples, even) into ARAM. Why would you want to do this? Well, it:

- Prevents ADSR from bugging out after an SFX plays.
- Allows the use of GAIN. (Possibly for more accurate ports? I personally haven't found too much use for it, though..)
- Can potentially shrink insert size, because the ADSR is stored for each instrument.

Right, so if you're still interested, let's get started! It would probably be best if I showed an example, and broke it down.

Here is the reference TXT: http://dl.dropbox.com/u/28007574/SPC/TXT/SFX_ARAM_Tut.txt

So we see the AM405 header, which is in every port. Immediately after it, we notice a huge string of hex commands (which would be a really good idea to have immediately after the AM405 header):

Originally posted by TXT
$ED $82 $61 $36 $00 $09
$00 $FF $E0 $00 $06
$00 $00 $00 $FF $06


Now, let's break this thing down. The first chunk of hex we'll pay attention to is "$ED $82 $61 $36 $00". This is the command for loading samples, and the $09 that follows after it is the number of samples that we are loading, multiplied by 05 (Both in hexadecimal), and subtracted by 01 (in hex). My song is using two instruments, so I did:

2 Samples = $02 * $05 - $01
= $0A - $01
= $09

So, to load 2 samples, the last byte in the string should be $09: $ED $82 $61 $36 $00 $09

I realize I wasn't very clear with this step, so I'll provide another example.

Let's say we have 14 samples. 14 is $0E in hex, so:

14 Samples = $0E * $05 - $01
= $46 - $01
= $45


Great, so now that the player knows that we are loading two samples, the next thing we do is define each instrument, so the next thing we focus on is the hex strings that follow after the ARAM command:

Originally posted by TXT
$00 $FF $E0 $00 $06
$00 $00 $00 $FF $06


Now, don't let this fool you, because this is how you should really be seeing these strings:

Originally posted by TXT
Sample 1's Information: $00 $FF $E0 $00 $06
Sample 2's Information: $00 $00 $00 $FF $06


The command for each sample is $YY $DA $SR $GA $ZZ, where:

YY = Sample slot number, which can be viewed with SPC700 Player. (SRC in this screenshot: http://dl.dropbox.com/u/28007574/SPC/source.png)
DA, SR = ADSR bytes ($ED $DA $SR), where $DA is added by $80 (in hex).
GA = Gain bytes, where $AD and $SR must be $00 if you intend on using this. If you are already using ADSR, this is best left at $00.
ZZ = Tuning (Works exactly the same way $E5 and $F3 tune things. Reference values here: http://crispyyoshi.hostei.com/amm/pitchreference.php)

How does the command know when we're finished? Well, that's what the $09 was for! It tells us that there are two samples, and that each sample will reserve $05 bytes of data. So, when we hit our 10th (decimal) byte of information, the command is done.

So, now we have declared our instruments, now we just load them in our song.

Instead of changing the instrument with @ and following with a $ED ADSR command, we load our instrument and ADSR with $DA $XX, where:

XX = Sample # + $12

For example, to load sample 1 we would use "$DA $13". To load sample 2 we would use "$DA $14". I'm pretty sure you can still re-assign the ADSR after loading your instrument, in case you want to use a different ADSR than the one you stored in ARAM. You can check your ADSR/GAIN with SPC700 Player.

Anyways, I think that should be it. If anyone has questions, feel free to reply to this thread!

EDIT: Fixed a few problems. Thanks for pointing out my mistakes, Lui37 and MarioStarLuigi!
That's a really useful trick for music porters, and seems you explained it nicely.
I would like to add some things anyway:
the maximum amount of custom instruments that can be loaded to ARAM at the same time is 19 (if you're not overwriting the default instruments, i.e. using the method explained in this tutorial);
decrasing gain doesn't seem to work in smw, and correct me if I'm wrong, but probabily they implemented only direct gain in the game (dunno about the increasing gain);
not to be nitpicky, but shouldn't ADSR be $DA $SR ?

Lastly, I think it would be nice if you also covered the method to upload SFX instruments to ARAM (if you get what I mean)... the format is a bit different, but imamelia explained it in one of his older post. If I had the time I'd help out more, but that's all I can say for now.
Originally posted by Lui37
but shouldn't ADSR be $DA $SR ?

No, actually. This command reads the ADSR as $AD $SR, but I don't really know why.

Also worth mentioning would be that the Decrease value should always be the second byte (Basicly, 80+), or else it'll glitch.
Does it works with addmusicM? If not, it wouldn't be too useful to me :/

Nice tutorial though, if I ever want to make a port only for addmusic 405 I should give this a try.
Originally posted by Masterlink
Does it works with addmusicM? If not, it wouldn't be too useful to me :/

Nice tutorial though, if I ever want to make a port only for addmusic 405 I should give this a try.

I found some relevant data at ARAM $2046 (the default instrument table), and it seems that you should be OK starting writing your instruments at $20A5 (I'm sure at least 2 instruments should work).
Anyway, with addmusicM you can only write one byte per command, so you'll need to do this for each instrument:

$F7 $YY $20 $A5
$F7 $AD $20 $A6
$F7 $SR $20 $A7
$F7 $GA $20 $A8
$F7 $ZZ $20 $A9

the green bytes are the instruments settings (the bytes that we want to write to our ARAM table). Don't forget to keep increasing the orange bytes for each write, because those are the addresses we're writing to.
Ahem, I don't know how many instruments you can have... if you need more you can overwrite the default ones anyway, just start writing from ARAM $2046 (in that case you'll have to call them using $DA $00 and so on, not $DA $13).

If something isn't clear feel free to ask.

Originally posted by Turbo Man
No, actually. This command reads the ADSR as $AD $SR, but I don't really know why.

Also worth mentioning would be that the Decrease value should always be the second byte (Basicly, 80+), or else it'll glitch.

No, really, the low nibble is the Attack, and the high one is the Decay (except bit 7 is used to determine if GAIN or ADSR is enabled; hence the "add $80 to have ADSR" thingy).
Format is in fact gddd aaaa.
I mean, I used that thing like in almost every port of mine, and I'm 100% sure it works like that.
Originally posted by Lui37
Originally posted by Masterlink
Does it works with addmusicM? If not, it wouldn't be too useful to me :/

Nice tutorial though, if I ever want to make a port only for addmusic 405 I should give this a try.

I found some relevant data at ARAM $2046 (the default instrument table), and it seems that you should be OK starting writing your instruments at $20A5 (I'm sure at least 2 instruments should work).
Anyway, with addmusicM you can only write one byte per command, so you'll need to do this for each instrument:

$F7 $YY $20 $A5
$F7 $AD $20 $A6
$F7 $SR $20 $A7
$F7 $GA $20 $A8
$F7 $ZZ $20 $A9

the green bytes are the instruments settings (the bytes that we want to write to our ARAM table). Don't forget to keep increasing the orange bytes for each write, because those are the addresses we're writing to.
Ahem, I don't know how many instruments you can have... if you need more you can overwrite the default ones anyway, just start writing from ARAM $2046 (in that case you'll have to call them using $DA $00 and so on, not $DA $13).

If something isn't clear feel free to ask.

Originally posted by Turbo Man
No, actually. This command reads the ADSR as $AD $SR, but I don't really know why.

Also worth mentioning would be that the Decrease value should always be the second byte (Basicly, 80+), or else it'll glitch.

No, really, the low nibble is the Attack, and the high one is the Decay (except bit 7 is used to determine if GAIN or ADSR is enabled; hence the "add $80 to have ADSR" thingy).
Format is in fact gddd aaaa.
I mean, I used that thing like in almost every port of mine, and I'm 100% sure it works like that.

..ah! Thanks for the information, I'll edit the post now.
The tuning for @2 should be 03, not 04.

--------------------
soundcloud / bandcamp / twitter / battle of the bits / buy our album
This is very important!
In order to find XX in $ED $82 $61 $36 $00 $XX, you must multiply the number of samples by five and subtract one IN DECIMAL, then convert it to hex. So if you had 10 samples total, instead of doing $10*$5 = $50-$1 = $4f, you'd do 10*5 = 50-1 = 49 = $31.
If you fail to do this properly, BAD THINGS WILL HAPPEN.
Thank you.

--------------------
soundcloud / bandcamp / twitter / battle of the bits / buy our album
Originally posted by MarioStarLuigi
This is very important!
In order to find XX in $ED $82 $61 $36 $00 $XX, you must multiply the number of samples by five and subtract one IN DECIMAL, then convert it to hex. So if you had 10 samples total, instead of doing $10*$5 = $50-$1 = $4f, you'd do 10*5 = 50-1 = 49 = $31.
If you fail to do this properly, BAD THINGS WILL HAPPEN.
Thank you.

Originally posted by CrispyYoshi
Now, let's break this thing down. The first chunk of hex we'll pay attention to is "$ED $82 $61 $36 $00". This is the command for loading samples, and the $09 that follows after it is the number of samples that we are loading, multiplied by $05 (in hex), and subtracted by $01 (in hex). My song is using two instruments, so I did:

2 Samples = $02 * $05 - $01
= $0A - $01
= $09

So, to load 2 samples, the last byte in the string should be $09: $ED $82 $61 $36 $00 $09
ffffffixing

Thanks again!
Actually MSL, 0x05 equals 05 so using 10 samples will simply mean 0x05 * 0x0A - 0x01 which would equal 0x31. And that's the number you would put as the amounts of bytes you're going to use, the converting to decimal part isn't necessary.
Also note that the maximum amount of instruments is 19.
It really depends on which way you find easier. Different people do things differently.

--------------------
soundcloud / bandcamp / twitter / battle of the bits / buy our album
Pages: « 1 » Link
Forum Index - SMW Hacking - SMW Hacking Help - Tutorials - Old Tutorials - [Semi-Tutorial] Fixing The ADSR Bug+Using GAIN in AddMusic 4.05

The purpose of this site is not to distribute copyrighted material, but to honor one of our favourite games.

Copyright © 2005 - 2021 - SMW Central
Legal Information - Privacy Policy - Link To Us


Menu

Follow Us On

  • YouTube
  • Twitch
  • Twitter

Affiliates

  • Super Mario Bros. X Community
  • ROMhacking.net
  • Mario Fan Games Galaxy
  • sm64romhacks