$4011 writes and DPCM together

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
$4011 writes and DPCM together
by on (#170613)
Hey, I have this little question, I would like to add a little extra punch to my percussion but since I'm already using the DMC for raster effects, the only thing I can think of is setting the level via $4011 and since I'm always playing 0 bits with the DMC, it would make a pop sound and then recover the level to 0. But wiki says that if the DMC is active and happens to change the level in the same cycle as you are trying to write to it, the level "doesn't change properly". But what does this mean? Does the $4011 not take effect at all, or is the DMC change ignored? (which would be fine in my case) Moreover, is there any way to fix this, other than doing my $4011 write in NMI, during which I always disable the DMC until the sprite 0 clear? This would delay the pop by about one frame and that's not what I really want.
Re: $4011 writes and DPCM together
by on (#170615)
blargg's apu_ref.txt is unambiguous:
Quote:
Writing to the DAC register ($4011) while a sample is playing sometimes has no
effect, probably because the DMC's output unit is clocking the counter at the
same moment as the write.

If you want to ensure that the write takes effect, probably you can enforce it by doing the write two times (since DMC channel updates are always at least ~50 CPU cycles apart, if the update happens to take over the first write, it should never take over the second one).
Re: $4011 writes and DPCM together
by on (#170925)
Also note that setting the sample value to an extreme makes DMC clip against the edges, so it won't sound very good. You need to set the sample value back to the middle to make DMC clip less.
Re: $4011 writes and DPCM together
by on (#170939)
Example song: One without DMC pops, and the other one with them. Bassline in DMC channel, percussion in Noise channel.
Re: $4011 writes and DPCM together
by on (#170941)
@dwedit : My understanding is that what you are telling has nothing to do with what he's doing. He's using DMC as a timer for raster effect, not to play any sound. He'd want to use $4011 just for popping sound, like Rad Racer II and Final Fantasy III, and that simultaneously. za909 correct me if I'm wrong.
Re: $4011 writes and DPCM together
by on (#170985)
Yes, that's exactly what I want to do. It's not as harsh though because the DMC gets the level back to zero a lot more smoothly and not another $4011 write. I could even do this and have some control over the APU2 volume by selecting to play either $00 bytes all the time or $FF and writing $3F to $4011 would always work regardless of the sample being played.