$4011 writes and DPCM together

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Post Reply
User avatar
za909
Posts: 249
Joined: Fri Jan 24, 2014 9:05 am
Location: Mijn hart woont al in Nederland

$4011 writes and DPCM together

Post by za909 »

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.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: $4011 writes and DPCM together

Post by thefox »

blargg's apu_ref.txt is unambiguous:
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).
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: $4011 writes and DPCM together

Post by Dwedit »

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.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: $4011 writes and DPCM together

Post by Dwedit »

Example song: One without DMC pops, and the other one with them. Bassline in DMC channel, percussion in Noise channel.
Attachments
test_pops.ogg
(67.47 KiB) Downloaded 225 times
test_nopops.ogg
(65.6 KiB) Downloaded 226 times
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: $4011 writes and DPCM together

Post by Bregalad »

@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.
User avatar
za909
Posts: 249
Joined: Fri Jan 24, 2014 9:05 am
Location: Mijn hart woont al in Nederland

Re: $4011 writes and DPCM together

Post by za909 »

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.
Post Reply