23. Using DMC Sounds

I’m going to explain how to use Famitone2 and Famitracker to add DMC sound samples to your game…first let’s review how the DMC channel works…here’s some code…

*((unsigned char*)0x4015) = 0x0f; //turn off DMC

//this controls which channels are on/off, DMC is the 0x10 bit

*((unsigned char*)0x4010) = 0x0f; //set the sample rate, f = highest

ADDRESS = 0xf000; //or whatever is the location of the DMC sample in the ROM

//the DMC samples MUST be located between c000 and ffff in the ROM

*((unsigned char*)0x4012) = (ADDRESS & 0x3fff) >> 6; // 0xf000 => 0xc0

LENGTH = 0x0101; //Actual length of a sample (in hex)

*((unsigned char*)0x4013) = LENGTH >> 4; // 0x0101 => 0x10

*((unsigned char*)0x4015) = 0x1f; //turn back on DMC channel

//any time DMC channel is turned on, it triggers the DMC sample to play

Ok, well, Famitone2 does all this for you, but if you ever wanted to add a DMC sample without Famitone2, this would the sequence of code to make it work. Here’s some more thoughts about DMC usage. Keep the samples very short. I use 0.1-0.5 second samples. You can use more/longer samples with a slower sample rate, but they will all have an annoying buzzing sound in them and poor quality. Also, DMC samples are only about half as loud as the other music channels…so if you want to balance the mix, you should cut the volume of the other channels by half.


Anyway. We are going to use the simple platformer code again, and add a Famitracker song that uses DMC samples for drums. I’m using some royalty free sounds samples that I got on a free CD many years ago. I edited them for length (shorter = better). Then I imported them into Famitracker. (You have to click on instrument #0, and then the DPCM tab).


After importing the files, save them as DMC files. Assign each sample to a Key (on the left) and now you can enter them into the song under the DPCM column. Save the finished song, and export it as a .txt file. Bring that over to Famitone2/tools, and run the text2data program to convert it into a .s and .dmc file. (It’s a command prompt .exe)

text2data DMCmusic.txt -ca65

Now, I had to do a few things to get it to play…I enabled DMC (and SoundFx) for Famitone2 (.define in my reset.s file). And, I defined the start location “FT_DPCM_OFF” to be at $f000. Then, I included the files at the bottom of the reset.s file. I made sure the DMC samples were in the .segment “SAMPLES” which I had to add to the .CFG file (and define it to be at $f000).

At this point, Famitone2 takes care of the rest. I’m just playing the song the same as we did on the “Adding Music” page, and it will trigger the DMC samples for you in the music code of famitone.s.

I also added a non-DMC sound effect by making a Famitracker file and saving as NSF file, and using the famitone2/tools/nsf2data program (see “Adding Sound Effects”), triggered when the character jumps. There, done.



Now, I want to use some DMC sound effects. I decided to use the same song, but I changed the drums to Noise Channel (so it won’t cut in and out when a sound effect is played).

Famitone2 makes you add DMC sound effects into the song. Must be on instrument #0. I exported a .txt from Famitracker, and used text2data again. It created a .s and .dmc file. Basically same as above, exept I didn’t use the DMC sample in the song.


Now, to call the sound effect from the C code, we need to do a fastcall to the famitone2.s label FamiToneSamplePlay but we need to add an underscore, I just added this above it…_DMC_PLAY (and added the line .export _DMC_PLAY). Now, I added a ‘fastcall’ function to the C code…

void __fastcall__ DMC_PLAY(unsigned char effect);

And, we need to give it a 1 byte value, equal to the DMC samples value. Now, I thought that their values would be #1 and #2. When I tried that, I got nothing. So, I looked closely at the DMCmusic2.s file (which defines each sample), and for some reason, it put the samples at #25 and #27. Here, look…


I don’t know why they’re at 25 and 27, but…whatever.

* It was because I chose note C-3 and D-3, which are the 25th and 27th notes on the scale…Shiru starts it at C-1,  I think.

You call them in the C code like this…


I have it set to play sample 1 when you jump, and play sample 2 when you press ‘START’.

Here’s the link…




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s