APU Step Timing

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
tehcloud
Posts: 22
Joined: Tue Apr 23, 2013 5:25 pm

APU Step Timing

Post by tehcloud »

I finished writing an APU last weekend, and during that process I discovered what appears, at least from my perception, to be a discrepancy on the wiki.

https://wiki.nesdev.com/w/index.php/APU shows this (which originally comes from apu_ref.txt):

Code: Select all

mode 0:    mode 1:       function
---------  -----------  -----------------------------
 - - - f    - - - - -    IRQ (if bit 6 is clear)
 - l - l    l - l - -    Length counter and sweep
 e e e e    e e e e -    Envelope and linear counter
Which is different from this concerning 5-step mode: https://wiki.nesdev.com/w/index.php/APU_Frame_Counter

When implemented in code, I discovered that I had my 5-step mode wrong, resulting in warped and cut off sounds in 5-step mode in my emulator. So, I changed it to be something more like this, which matches up with the APU Frame Counter wiki page:

Code: Select all

mode 0:    mode 1:       function
---------  -----------  -----------------------------
 - - - f    - - - - -    IRQ (if bit 6 is clear)
 - l - l    - l - - l    Length counter and sweep
 e e e e    e e e - e    Envelope and linear counter
Am I just misinterpreting this? The way I have things implemented now, everything sounds perfect.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: APU Step Timing

Post by Dwedit »

Are you doing the immediate clocking?
Writing 0x80 should clock the sweep and envelopes immediately, streemerz relies on this.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
tehcloud
Posts: 22
Joined: Tue Apr 23, 2013 5:25 pm

Re: APU Step Timing

Post by tehcloud »

By immediate clocking, do you mean on 4017 writes? If so, yes.

If you look closely you'll see I just shifted the position of the first column from the original example. I'm counting down CPU cycles to determine when to clock sweep/length/envelope, which seems to be the way things are described on https://wiki.nesdev.com/w/index.php/APU_Frame_Counter
Post Reply