Question about how Sweep works

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
gravelstudios
Posts: 101
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

Question about how Sweep works

Post by gravelstudios » Tue Mar 30, 2021 5:00 am

In the Wiki's Sweep page (https://wiki.nesdev.com/w/index.php/APU_Sweep) it says this:

For example, if the negate flag is false and the shift amount is zero, the change amount equals the current period, making the target period equal to twice the current period.

This would imply that if the sweep is positive and the shift is zero, then the sweep should cause the pitch to lower one octave each time the divider reaches zero. In Mesen however, if the shift amount is zero, it doesn't sweep at all. I found an old post by Blargg that says:
When the channel's period is less than 8 or the result of the shifter is
greater than $7FF, the channel's DAC receives 0 and the sweep unit doesn't
change the channel's period. Otherwise, if the sweep unit is enabled and the
shift count is greater than 0, when the divider outputs a clock, the channel's
period in the third and fourth registers are updated with the result of the
shifter.
Does setting the sweep shift to 0 result in no sweep?

lidnariq
Posts: 10459
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Question about how Sweep works

Post by lidnariq » Tue Mar 30, 2021 11:35 am

Yes. Visual2A03 node 10509 disables sweep for channel 0 if the lower three bits ("shift count") of $4001 are 0.
Similarly, node 10510 does the same for channel 1 if the same is true for $4005.

User avatar
gravelstudios
Posts: 101
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

Re: Question about how Sweep works

Post by gravelstudios » Tue Mar 30, 2021 12:05 pm

thanks!

lidnariq
Posts: 10459
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Question about how Sweep works

Post by lidnariq » Tue Mar 30, 2021 12:47 pm

The wiki does actually call this out:
If the shift count is zero, the channel's period is never updated, but muting logic still applies.

User avatar
gravelstudios
Posts: 101
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

Re: Question about how Sweep works

Post by gravelstudios » Wed Mar 31, 2021 5:02 am

lidnariq wrote:
Tue Mar 30, 2021 12:47 pm
The wiki does actually call this out:
If the shift count is zero, the channel's period is never updated, but muting logic still applies.
Yes, I saw that, and I initially thought it contradicted the statement made higher up on the page, hence my confusion.

lidnariq
Posts: 10459
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Question about how Sweep works

Post by lidnariq » Wed Mar 31, 2021 11:37 am

Any thoughts on how we could change the article to help?

The only thought that occurs to me is put a banner at the top of the "Muting" section stating that everything in this section only affects the muting behavior and doesn't affect anything else.

User avatar
gravelstudios
Posts: 101
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

Re: Question about how Sweep works

Post by gravelstudios » Wed Mar 31, 2021 2:09 pm

For example, if the negate flag is false and the shift amount is zero, the change amount equals the current period, making the target period equal to twice the current period.
I feel that example is a little confusing, because if it's supposed to be an example of how to use the sweep, it doesn't work. If the shift amount is zero, the period doesn't change, and this quote sort of implies that it should. Does that make sense?

lidnariq
Posts: 10459
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Question about how Sweep works

Post by lidnariq » Wed Mar 31, 2021 2:28 pm

Hm, but that's there to explain why several games never use the lowest octave, and an easy pitfall for developers. Because the target period is still evaluated, even if sweep is disabled (either by SSS=0 or E=0)...

I could call out that, but I worry that that sentence is already too wordy.


I could rephrase the previous sentence from:
"Muting is regardless of the enable flag and regardless of whether the sweep divider is not outputting a clock signal. "
to
"Muting is regardless of whether sweep is enabled [...]"
or more verbosely
"Muting is regardless of whether sweep is disabled (either due to E=0 or SSS=0) [...]"

Pokun
Posts: 1822
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Question about how Sweep works

Post by Pokun » Wed Mar 31, 2021 3:32 pm

That last sentence makes the most sense to me. That's basically what I wrote in my notes about this. I was confused just now that the wiki didn't match my notes, and made the same conclusion as Gravelstudios initially did.

User avatar
Controllerhead
Posts: 241
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

Re: Question about how Sweep works

Post by Controllerhead » Wed Mar 31, 2021 3:38 pm

I fixed / updated Snowbro's SNDTEST to get a handle on the sound registers myself:
viewtopic.php?f=2&t=20609

Image
Image

lidnariq
Posts: 10459
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Question about how Sweep works

Post by lidnariq » Wed Mar 31, 2021 4:42 pm

I've tried to rework that section of the page. Please let me know if it helped or hindered understanding:
nesdevwiki:Show change #18558/APU Sweep

User avatar
gravelstudios
Posts: 101
Joined: Mon Mar 13, 2017 5:21 pm
Contact:

Re: Question about how Sweep works

Post by gravelstudios » Wed Mar 31, 2021 4:55 pm

I think it's clearer now.

Pokun
Posts: 1822
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Question about how Sweep works

Post by Pokun » Thu Apr 01, 2021 9:55 am

I agree, it's very clear now.

Post Reply