Page 1 of 7

DMC channel

Posted: Fri Nov 16, 2007 11:41 pm
by Celius
I was wondering whether or not to start this thread, but I decided that I must, because I just have no clue what I'm doing in this field. I've been interested in learning about the DMC channel, but everywhere I look leaves me with one question: "...What?"

I honestly don't know what the documents are talking about. But, I did look around in a few threads on this site that pointed me to a few programs, such as Tepple's program for converting WAV files to DMC files. So I recorded a sound, and turned it into a WAV file, and then converted it to a DMC file.

However, I don't know exactly what to do with this file. I tried to .incbin my file at a specific location; one that was a multiple of $40 + $C000 ($C400 to be exact). I don't know what it is, but I can't get it to play. The file is 7 KB. Is this even a valid file size? Doesn't the length counter only allow for around 4 KB ($FF * $10 + 1 = $FF1 = 4081)? Well, Perhaps someone could point me in the right direction by telling me how I can initiate this file with a small peice of sample code. With that, I could study the documents, and study the code, and possibly get some useful information out of it. If someone could do that for me, I'd be very very happy.

Re: DMC channel

Posted: Sat Nov 17, 2007 9:13 am
by Disch
Celius wrote:The file is 7 KB. Is this even a valid file size? Doesn't the length counter only allow for around 4 KB ($FF * $10 + 1 = $FF1 = 4081)?
You are correct. Your file is too long to play in its entirety. Shorten it by either shortening the wav you're converting, or using a lower frequency/quality setting when converting it.

Playing them is pretty simple:

Code: Select all

LDA #$0F
STA $4010  ; set frequency ($0F is highest quality/pitch.  Experiment with
           ; lower values, but beware that below $0A or so they get pretty slow)

LDA #$3F
STA $4011  ; set output to "center line".  This step can possibly be skipped,
             ; but I'd recommend leaving it in... see notes at bottom)

LDA #$10
STA $4012  ; set address to $C400

LDA #$FF
STA $4013  ; set length to max ($FF1 bytes) -- lower this if you shrink your dmc sample.


LDA #$0F
STA $4015  ; stop DMC if it's currently playing

LDA #$1F
STA $4015  ; and restart it
That's all there is to it. Flipping on bit 4 of $4015 will start your sample. But note that only works if the DMC is not playing (which is why you stop it first by clearing that bit)

As far as the "center line" stuff goes -- if your wave extends too high or too low it will end up getting clipped which will distort the sound. Setting the center line to $3F or $40 keeps it right in the middle so there's the least chance of clipping occuring.


EDIT


I made this a while back so you can preview your DMC sample before dropping it in your program:

http://disch.arc-nova.org/dmcplayer.zip

Posted: Sat Nov 17, 2007 10:28 am
by Celius
Thank you very much Disch, you've pretty much answered my questions. And it turns out that it wasn't playing at first due to a completely unrelated reason. However, all of this information was very helpful. So pretty much anyone who's new to the DMC channel should be pointed to this thread. Does anyone think it would be a good idea to write a small document for those who want to learn about the DMC channel, but can't really understand what the docs are saying?

EDIT: By the way, very nice little program. I'll be using it quite frequently =).

Posted: Sat Nov 17, 2007 12:58 pm
by atari2600a
Curious, has anyone ever tried converting an entire song & slapping it into a ROM?

Posted: Sat Nov 17, 2007 1:11 pm
by tepples
atari2600a wrote:Curious, has anyone ever tried converting an entire song & slapping it into a ROM?
I've done so. But 512 KiB for a <2 minute song is impractical. Better is to do it without DPCM.

Posted: Sat Nov 17, 2007 6:47 pm
by Celius
I'm just wondering how that would be possible, because can't you only stick DMC data in $C000-$FFFF? Is the ROM 1024k? I think I may have heard that before actually...

EDIT: No, actually, I had a different ROM that was 1024k, and it had a DMC file in it, and it was really really nice sound. I remember that it was when I wasn't even into NESdev yet, and I was so blown away by the quality and I didn't know how it was even possible to do such a thing.

Posted: Sat Nov 17, 2007 9:31 pm
by Disch
you can stream raw PCM data to $4011 to produce your own sound wav. A few games do this (Battletoads comes to mind right away).

That is to say... you can output a 44.1 KHz wave (good quality) if you write to $4011 with a new sample 44100 times every second (spaced evenly, of course).

You're still limited to 7-bit mono samples though.

Posted: Sat Nov 17, 2007 9:41 pm
by tepples
Celius wrote:I'm just wondering how that would be possible, because can't you only stick DMC data in $C000-$FFFF?
MMC3 has two switchable banks. In one common configuration, one is placed at $C000-$DFFF and the other at $A000-$BFFF.
EDIT: No, actually, I had a different ROM that was 1024k, and it had a DMC file in it, and it was really really nice sound. I remember that it was when I wasn't even into NESdev yet, and I was so blown away by the quality and I didn't know how it was even possible to do such a thing.
But why would someone waste that much NOR flash on one song? Sure it's possible, just like it's possible to hack a low-quality reproduction of Sonic Adventure music into Sonic the Hedgehog for Sega Genesis. But that doesn't make it desirable.

Posted: Sat Nov 17, 2007 9:44 pm
by tokumaru
Disch wrote:spaced evenly
This would be the hard part, if you are doing anything besides playing the samples. But I guess this would allow for some sort of audio compression, if the decompression engine was simple enough and everything was very well timed.

Posted: Sat Nov 17, 2007 9:48 pm
by tokumaru
tepples wrote:Sure it's possible, just like it's possible to hack a low-quality reproduction of Sonic Adventure music into Sonic the Hedgehog for Sega Genesis. But that doesn't make it desirable.
It does indeed sound like crap.

Posted: Sat Nov 17, 2007 10:01 pm
by tepples
tokumaru wrote:
Disch wrote:spaced evenly
This would be the hard part, if you are doing anything besides playing the samples. But I guess this would allow for some sort of audio compression, if the decompression engine was simple enough and everything was very well timed.
I believe that's called Big Bird's Hide and Speak. I tried tracing through its audio decompression code. It has about eight "flavors" of compressed sample blocks; they take different amounts of time to decode so each byte just JSRs into a big NOP slide to kill time. Eventually, I said screw it, I'm just writing my own ADPCM playback engine.

Posted: Sat Nov 17, 2007 11:00 pm
by Celius
So in other words, you'd have to update it every X scanlines, where X = (However many cycles are in a frame) * 60 / 44100. So you could do something with MMC3's scanline counter. That would be interesting. That seems like it would be really hard without a scanline counter. I have to admit, the DMC address byte is a really stupid concept. It would have caused way less problems if they just made it like $2005/$2006, where you can do two writes to it. It's actually kind of dissapointing to know that there isn't that much flexibility with it.

Posted: Sat Nov 17, 2007 11:11 pm
by tokumaru
Celius wrote:So in other words, you'd have to update it every X scanlines
Scanlines? I don't think any scanline counter will be able to help you there... 44100 is the number of samples in a second... since the NES runs at nearly 60 frames per second, that'd be 735 samples per frame, and that number is quite larger than the number of scanlines. I think you'd have to write a byte every 40 or so CPU cycles.

EDIT: In the formula you presented, X is the number of cycles, not scanlines, and it evaluates to 40 and some fraction of cycle.

Posted: Sat Nov 17, 2007 11:19 pm
by Celius
Oh, yeah, oops. That just wouldn't work if it were scanlines. That would be terribly difficult to do every 40 cycles. Actually updating it could take more than 40 cycles (If you're doing math or something). Doesn't sound so worth it to me.

Posted: Sat Nov 17, 2007 11:31 pm
by tokumaru
Celius wrote:Doesn't sound so worth it to me.
The quality sure is better than DPCM, but not being able to do anything else sure is a pain in the ass.

Well, there must be some good use to it. We're talking about this in the thread that was split from this one.