DMC Question

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
DMC Question
by on (#36502)
Hello again everyone,
i was just wondering how it possible to get positive and negative alternations on a DMC channel (ie. sawtooth and triangles) im trying to really understand how the DMC channel but its a bit overwhelming. am i adjusting the frequency or the volume control.

p.s what file format does the DMC player read. ive tried .raw. bin. asm .nsf with no luck. how exacly do you use it.

thanks again,
el

by on (#36508)
Um. First off, do you understand PCM and Delta Modultation? Wikipedia gives a fairly good explanation. If so, have you already seen nesdev wiki's information about the DMC and blargg's implementation that I think you're talking about ?

If that doesn't explain things, where do you start getting confused?

by on (#36517)
Well, I started a thread a while ago when I didn't understand the channel at all:

http://nesdev.com/bbs/viewtopi ... 06&start=0

Hope this helps somewhat.

by on (#36678)
i read it an was still kinda confusing mean there is no ''eureka''' yet. looking a dmc detailed dmc operation article by blarrag it seem to be more PCM. i was just confused on some topics .

is there a correlation b/w the values stored in the DMC length $4013. (ie. #$00 is supposed to mean fetch 1 sample at time. does #$01 mean fetch 2 samples and so forth?

how dmc addresses work i have no idea. store #$FF to $4012 and it tells the DMC that your at register FFC0 is beyond me?

i made a little chart to see if i was actully understanding well. change if you need to or add what you can. cause i will no be able to understand with out pics.

thanks again you guys for the replies.


Image

by on (#36679)
nineTENdo wrote:
how dmc addresses work i have no idea. store #$FF to $4012 and it tells the DMC that your at register FFC0 is beyond me?


Check out the wiki on that:

http://nesdevwiki.org/index.php/APU_DMC

There is a %11 tagged on to the beginning of the value you give the register, and %000000 tagged at the end. So to figure out what the address will be, plug your number in between those:

%11 $ff %000000

$ff == %11111111

So:

%1111111111000000 (the bold is where your $ff is plugged in)

Which equals:

$ffc0 : )

Which, I never thought of it before, but now that I think of it, this is why I've read/heard that samples have to be in $c000 or above since that is the lowest it can go (plugging $00 in there).
Re: DMC Question
by on (#36688)
nineTENdo wrote:
Hello again everyone,
p.s what file format does the DMC player read. ive tried .raw. bin. asm .nsf with no luck. how exacly do you use it.


If you're talking about the DMC player I wrote... it takes .dmc files which are just a straight dump of the sample in the exact same format the NES requires (1 delta bit per sample).


The DMC plays back "samples" from CPU memory. You can think of these samples as low quality wave files if that helps illustrate the idea (although they're in a different format from wave files). To play these samples, you need to provide the DMC with the following information:

1) speed at which to play back ($4010). Faster speeds will be higher pitch and shorter, while lower speeds will be lower pitch and longer. Think of a cassette tape playing in slow motion vs highspeed. As it speeds up, the pitch raises, and as it slows the pitch drops. The same concept applies here.

2) the address at which the sample data can be found ($4012). For the DMC to fetch bytes from ROM, 'decode' them, and play them back, it needs to know where to start looking for them. So you set the address of the start of the sample here.

3) how big/long the sample data is ($4013). More sample data = longer sample (just like a longer wave file is bigger). A 1-byte DMC sample is only a quick blip, whereas a $FF1 byte sample is pretty lenghty.


Once you set all that information, you just tell the DMC to start playing by flipping on the DMC bit (bit 4) in $4015. The DMC will begin fetching bytes and playing them back automatically, and will shut itself off once it plays the entire sample (unless you set it to loop, in which case it will keep looping until you shut it off).


I don't really know if this clears anything up for you =x.

by on (#36689)
nineTENdo wrote:
is there a correlation b/w the values stored in the DMC length $4013. (ie. #$00 is supposed to mean fetch 1 sample at time. does #$01 mean fetch 2 samples and so forth?


It's 16*n+1 bytes, or 128*n+8 samples, before it one of 1)Stops 2)Interrupts your current code asking what to do 3)Repeats

Quote:
i made a little chart to see if i was actully understanding well. change if you need to or add what you can. cause i will not be able to understand with out pics.


I don't have a place to store an image, so hopefully this will help.

So, say you initialize the DMC like follows-
[$4010] = #$0F (no interrupts, no loops, play once at highest rate)
[$4011] = #64 (initialize DAC at the 50% point)
[$4012] = #0 (load samples starting at $C000)
[$4013] = #1 (play 17 bytes of delta-encoded data)

Further, say that the memory at C000 is
00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00 FF 00

What happens is:
the DMC fetches the byte at $C000 (00)
the DMC looks at the lsb (0)
the DMC decrements the value of the DAC by 2 (minimum 0 or 1)
the DMC waits 54(NTSC) or 50(PAL) instruction cycles
the DMC looks at the 2nd lsb (also 0)
(repeat as necessary for all 8 bits)
Then the DMC fetches the byte at $C001 (FF)
it looks at the lsb (1)
the DMC then increments the value of the DAC by 2 (maximum 126 or 127)
and repeat, until we've fetched all 17 bytes.

Caveat: I don't know whether the delay is before or after the increment/decrement, but i suspect it doesn't matter in practice.

So, what's wrong with your picture is-
1- in 8 DMC cycles, you'll only be able to change the value of the DAC by 8*2=16.
2- Full scale is not FF but 7F
3- Different pitches do not consist of different numbers of the same wave but different horizontal stretching of the same wave.

by on (#38276)
hello again everyone,
ive been looking at the DMC frequency control register chart and was wondering. does the DMC only play from octave C5 to C8? how does the CPU clock in relation to msec. for example c5 is 523.25Hz. using the formula 1/T (period) = f (frequency). Would D60 clock (0 in register $4010) be 1.9**msec?


thanks
el

by on (#38304)
The NES only has 16 output rates for the delta channel, but those do not have to correspond to specific pitches -- just specific relative pitches.

NTSC NES runs at 1.789772 MHz, so the fastest divisor -- 54 cycles -- corresponds to a new sample at 33143Hz. a PAL NES should run a little slower so that the divisor of 50 corresponds to the same output rate, but I don't have the number on hand.

The slowest NTSC divisor is 428, which would correspond to 4181 Hz, or ~239us per sample.

by on (#38309)
Both the NTSC and PAL period lookup tables are set up such that if you have a power of 2 samples per period of the waveform, such as 64 samples per period, the pitches will line up very close to these notes:
C, D, E, F, G, A, B, C, D, F, G, A, C, E, G, C

For example: If you have 64 samples per period, rate 12 (the third C above) will be a middle C. With 32 samples per period, rate 7 (second C) is middle C.

(I think that's also why MOD and XM have 8363 Hz = middle C, because it's very close to the true value of 8372 Hz = middle C that you get with 32 samples per period.)

by on (#38314)
tepples wrote:
Both the NTSC and PAL period lookup tables are set up such that if you have a power of 2 samples per period of the waveform, such as 64 samples per period, the pitches will line up very close to these notes:
C, D, E, F, G, A, B, C, D, F, G, A, C, E, G, C

For example: If you have 64 samples per period, rate 12 (the third C above) will be a middle C. With 32 samples per period, rate 7 (second C) is middle C.

(I think that's also why MOD and XM have 8363 Hz = middle C, because it's very close to the true value of 8372 Hz = middle C that you get with 32 samples per period.)


here a table that shows accurately the DMC notes: http://2a03.org/forum/viewtopic.php?id=924 . Hope that helps ;)