Language…
13 users online:  Anorakun, ElKokis, FantasticFox, Maw, Metal-Yoshi94, Nowieso, PuffleDreemurr, Pyro_L, Saela, Stivi, Toasty, Udjat, Zavok - Guests: 113 - Bots: 134
Users: 67,591 (2,011 active)
Latest user: Pyro_L

An In-depth Look of Vanilla Percussion (@21 - @29) on Addmusic

AdvancedCustom Music

Yes, this tutorial is specified for vanilla percussions in Addmusic, since I see there are lots people don’t really understand about how that confusing stuff works.

So, what @21 - @29 does?

When porters talking about percussion notes feature from other sound engine (eg. Square Soft and Hudson Soft’s one), N-SPC does have the same feature, including SMW’s. It’s pretty limited, since a percussion note in N-SPC is only tied with corresponding instrument. And for whatever reasons, the original Java Addmusic’s author decided to handle the percussion in a really confusing way. For backward compatibility, all Addmusics have to do that in the same confusing way.

The reason that @2X instruments stand out from other vanilla instruments is because how Addmusic handle it. @10, @12, etc. will not be covered here, since they are just standard instruments technologically.

Pitch

Code
@21 o4 c4 c4 c4 c4

So you would assume you will get percussion @21 played 4 times correctly, right? Well, it actually sounds like this: only the first note played in correct pitch, and the rest 3 don’t.

This fragment actually be compiled to this:

Code
$30 $7F $D0 $A4 $A4 $A4
---+--- -+- -----+-----
   |     |       |
   +-----+-------+---------> This means setting note length to $30 ticks (Quarter note) and
         |       |           `q7f` respectively.
         |       |
         +-------+---------> Our percussion note `@21`. The `@21` - `@29` thing is actually 
                 |           handled by Addmusic at compiling stage, which just replacing
                 |           the *first* note after `@2X` into corresponding percussion note.
                 |           
                 +---------> Since the rest notes is not being processed specially, they will
                             play `o4 c` as is under percussion instrument @21. Since the $D0
                             plays `o4 e` (`$A8`), these 3 will sounds detuned.

So, how to make all of them sounds in the correct pitch? Well, there are 2 ways to overcome that:

Redefine @2X every time

You can actually redefine @2X every time before each note. eg:

Code
@21 c4 @21 c4 @21 c4 @21 c4

As you can see, it sounds correctly now as you would expect. And let us look the compiled binary code:

Code
$30 $7F $D0 $D0 $D0 $D0
        -------+-------
               |
               +-----------> Yeah, all of them are converted to percussion note `$D0` correctly

A common misunderstanding is redefining @2X every time will increase the insert size of a song, but it’s not. As we mentioned above, @2X is handled by Addmusic and only replace corresponding normal note ($80 - $C5) to percussion note ($D0 - $D9). Thus, you can redefine @2X thing without worrying about that.

Some people may think redefining @2X would make the MML looks messy, so alternatively you can make other notes plays at correct pitch manually:

Code
o4 h4 @21 c4 c4 c4 c4

It will also sounds correctly, and the compiled binary code loks like this:

Code
$30 $7F $D0 $A8 $A8 $A8
        -+- -----+-----
         |       |
         +-------+---------> Our percussion note `@21`
                 |           
                 +---------> Though the rest notes is not being processed specially, they will
                             all sounds in correct pitch, since we tuned that manually.

I made a tuning table for your convenience:

ID N-SPC Notation Tuning (o4c)
@21$0F $0F $6A $7F $03 $00h4
@22$06 $0E $6A $40 $07 $00h0
@23$06 $8C $E0 $70 $07 $00h-3
@24$0E $FE $6A $B8 $07 $00h0
@25$0E $FE $6A $B8 $08 $00h0
@26$0B $FE $6A $B8 $02 $00h-8
@27$0B $7E $6A $7F $08 $00h2
@28$0B $7E $6A $30 $08 $00h2
@29$0E $0E $6A $7F $03 $00h-3

ADSR/GAIN

So you would think you can redefine ADSR/GAIN of a percussion note, right? Well, let’s look this example:

Code
#amk 2
#samples
{
    ; Sample ID padding
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    "EMPTY.brr"
    ; We make @21 sounds as square wave for demo purpose
    "sb_sw50.brr"
}

#0
@21 $ED $76 $E0 h4 o4 c4 c4 c4 c4

You may think all 4 notes would play with ADSR $76 $E0, but it’s not. All notes still play the original GAIN $7F of @21.

So, what’s going wrong? Well, let us summarize what happened in the binary code:

Code
$ED $76 $E0 $30 $7F $D0 $A8 $A8 $A8
-----+----- ---+--- -+-
     |         |     |
     +---------+-----+-----------------> We set the ADSR of channel 0 to $76 $E0
               |     |
               +-----+-----------------> length = $30, q7f
                     |
                     +-----------------> Percussion note $D0. The percusson note call will *reset*
                                         the current tuning and ADSR/GAIN with the $D0 one, so the
                                         $ED command above is not effective at all.

So, if you want to use custom ADSR/GAIN for a percussion instrument, the best way is defining your own custom instruments:

Code
#instruments
{
	@21	$F6 $E0 $B8 $03 $00    ; we define our custom ADSR here
}

#0
@30
h4    ; Remember set correct tuning!
o4 c4 c4 c4 c4

Now, it sounds corrently.


Oct 4, 2023 update: If you want to customize each vanilla percussion's ADSR/GAIN, you can use this base instrument set; all of them are tuned for o4c and does not need special cares above:

Code
#instruments
{
    @21 $0F $6A $7F $03 $C9
    @22	$0E $6A $40 $07 $00
    @23	$8C $E0 $70 $05 $E3
    @24	$FE $6A $B8 $07 $00
    @25	$FE $6A $B8 $08 $00
    @26	$FE $6A $B8 $01 $43
    @27	$7E $6A $7F $08 $FD
    @28	$7E $6A $30 $08 $FD
    @29	$0E $6A $7F $02 $86
}

Conclusion

If you ever tried to create SMW music, you can see there are a lot of design flaws in Addmusic MML, including percussion “instruments”. It’s quite confusing, but I think if you understand that, you can overcome these disadvantages easily, though I really hope you don’t abusing these design flaws, which would make your MML hard to read and understand.

If you have any questions or suggestions (including writing and grammar), feel free to reply, and I will see what I can do for that!

I like how informative this post is! This is coming from someone who could never figure out the reason why AddMusicK would sometimes mess up the pitches of the @21 - @29 instruments. I really like how in-depth you went with it too with the code boxes, and I've felt I've learned something new from this.

Persoanlly, I do find it easier to use #instruments for @21 - @29 since it cancels out the strange pitch effects that AMK can cause, plus you're more free with giving it the preferred ADSR/GAIN and tuning values.

Originally posted by tcdw
Some people may think redefining @2X would make the MML looks messy, so alternatively you can make other notes plays at correct pitch manually:

Recently, I've been do this too for the default @21 - @29 instruments, but I don't use h. Instead I just go with the correct note that it plays (for @21's case, it's o4e). Either way of doing it works fine though.
Twitter

AdvancedCustom Music