The Sound Registers

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
electro
Posts: 132
Joined: Tue Jan 29, 2008 11:12 am
Location: New York

The Sound Registers

Post by electro »

I am experimenting with the noise channel and writing to it's registers.

So we have:

Code: Select all

$400C 

$400E 

$400F
I noticed that if bit #5 is set in register $400C you can get a looping effect. I am now trying to figure out of to adjust the loop time, speed it up, slow it down.

I think this loop timing is controlled via bits in registers $400E and $400F?

Thanks,
T
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

helps to have an APU doc ;P

http://www.slack.net/~ant/nes-emu/apu_ref.txt


The looping you're referring to is the decay unit which controls the output volume. What's happening is the decay unit decreases the volume by steps of 1 at regular intervals. Enabling decay looping (which is what you do when you set $400C.5 and clear $400C.4) causes the volume to wrap from 0->F

So normal decay you have:

F, E, D, C, B, A, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0 ....

whereas with looping decay you have

F, E, D, C, B, A, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, F, E, D, C, B, A, 9 ....


The speed at which the decay unit clocks is controlled by the low 4 bits of $400C (not $400E or $400F like you guessed). The higher the value, the slower the decay.

So...

Code: Select all

LDA #%00100000  ; decay loop, decay enabled, period=0 (fast)
STA $400C  ; decay unit will decay quickly and loop
-----
LDA #%00101111  ; decay loop, decay enabled, period=F (slow)
STA $400C
Note that when decay is enabled, the decay unit controls the output volume. The low 4 bits of $400C double as the fixed output volume if decay is disabled -- which allows you to directly control the output volume. You disable the decay unit by setting bit 4:

Code: Select all

LDA #%00110000  ; decay disabled, volume=0 (silent)
STA $400C
-----------
LDA #%00111111 ; decay disabled, volume=F (loud)
STA $400C
The decay units and volume setup on the square channels operate the exact same way, only you use regs $4000 and $4004 instead (and the high bits of those regs set the duty cycle)


$400E controls the period (aka the frequency, tone, or pitch -- whatever term floats your boat). You only have 16 pre-set frequencies to choose from on the noise channel. The low 4 bits select the pitch (higher values = lower tone... beware of the highest tones 0 and 1 -- they can be somewhat ear-piercing if you play them too loud)

Additionally, the high bit of $400E selects the mode. Clearing it gives you the normal "shhhh" noise, whereas setting it gives you a more of a "bzzzz" noise (the rhythmic buzzing in Quickman's level music in Megaman 2 uses the buzz mode -- listen to that song again to see what I mean)

$400F does nothing but handle the length counter and start up the channel once the length counter expires. I don't feel like going into detail on what the length counter does right now... so blah =P

EDIT -- whoopsie... actually, $400F also resets the decay unit back to $F ^^. Forgot about that. What that means is that when the decay unit has decayed the volume all the way to 0 (or even before then), writing any value to $400F will snap it back to $F. But if decay is disabled, then this is relatively unimportant.

Anyway yeah.. playing around is good. Getting a hands-on feel for how it all works helps a lot. But don't be afraid to use the docs as a guide ;D
User avatar
electro
Posts: 132
Joined: Tue Jan 29, 2008 11:12 am
Location: New York

Post by electro »

Thanks very much. Will study your reply some more and re-post.

I was (am) having trouble fully understanding the docs, I did try to use them before posting.

Your explanation cleared it all up for me, at least concerning the noise channel and it's volume decay loop. (I should have posted 2 days ago!)

Will be posting a million more questions about the sound channels... sigh

Thanks again for the help there.

T
User avatar
electro
Posts: 132
Joined: Tue Jan 29, 2008 11:12 am
Location: New York

Post by electro »

I am reading the doc and from what I can gather square wave 1 (& 2) have this same volume decay loop at the same bit positions?

Square 1 Channel

$4000.5 ;set bit 5 to enable volume decay looping

disable at $4000.4 ; set bit 4 to disable volume decay looping

Thanks,
T
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

Yes. Decay/Volume is exactly the same for the squares. Bit positions and everything.
Post Reply