NES APU Pulse-Channel structure

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
NES APU Pulse-Channel structure
by on (#62199)
Hello everyone. I was wondering if anyone could tell me some specifics on how the NES APU Square-wave/Pulse channel works, I've read the documentation on it but I can't figure out some bits.

The Envelope generator creates a signal of either constant volume or with a linear decreasing slope. This bit gets clocked at the 240/192Hz signal from the Frame Sequencer, correct?

This signal then gets multiplied by an enable/silence signal from the Length Counter, clocked by the Frame Sequencer at 120/96Hz, correct?

Now comes the part I find a bit hard to understand. The channel itself also contains an 8-step sequencer, what does it do? what does it multiply the signal with? Is it responsible for the duty cycle?

The sweep unit is the biggest mystery to me. I have absolutely *NO* idea what this thing does, can someone elaborate?
Thanks in advance.

PS. If anyone's wondering, I'm doing a project similar (more exactly like) jwdonal, except I can't guarantee I'll ever catch up to him :wink:

by on (#62201)
As the Wiki page says, the envelope volume is gated by the sequencer, sweep, and length counter. The DAC receives 0 if any of those three want it to.

Is there anything in particular about the sweep page that doesn't make sense?

by on (#62202)
Sort of, it just does a bad job at explaining exactly what it does.

Now, I've come up with an idea as to how it functions, could you tell me if it's correct?

The timer generates a certain wavelength of 8 clocks, determined by the timer register, the 8-step sequencer then uses this to apply a duty cycle to the Envelope signal. The sweep unit adjusts the timer registers to new values as to change the wavelength. Is that how it's done?

EDIT: My bad, channel's raw period does not get changed. Somewhat starting to understand how it works now, but more help would be great :roll:

by on (#62205)
Divide and conquer Focus on a square wave at full volume. There the timer clocks the sequencer. Each clock, the sequencer goes to the next step out of 8. Thus, the frequency of the wave is 1/8 the rate from the timer. At each step the sequencer continually outputs a 0 or 1, based on the currently selected duty. For a square wave, it's 4 steps of each. Then that 0 or 1 output either allows the full volume value ($F) to go to the DAC, or forces 0 to the DAC.

So yeah, like you said. Throw in the sweep, which does two basic things: adjust the timer period periodically, and continuously do a calculation based on the period and silence the channel (force the DAC to 0) if the result meets certain conditions.

by on (#62206)
Care to add something like that to the wiki as a broad overview of the pulse channels?
More sound channel questions
by on (#73202)
I am very new to the APU but have so far been able to reproduce a square wave on an XMega 128. I would like to go further but I feel I am missing something about the sound channels. Right now the Square Wave channels.
I am working with the Volume / envelope decay unit. I understand that if the decay unit is disabled, the volume is determined by bits 0-3. I think I also understand that bits 0-3 control the length of the decay envelope when enabled (240 / (bits 0-3)). I am missing what sets the volume for the channel in this case. What value does the volume start with.

My guess is that, you set bits 0-3 for your length and every time that reaches 0, your volume gets decreased by 1, starting from 15. If loop is enabled, when your volume reaches 0, it's restarted at 15. If loop is disabled, the channel just remains silent.

Can anyone give me any insight to this. I have read both the following docs and the wiki.
http://nesdev.com/NESSOUND.txt
http://nesdev.com/apu_ref.txt