I gave up on sweeps a few years ago, and now I'm trying to finally resolve the problems I have always had with them. Either they sweep way too fast, the pitch is way too low, or other similar glitchy behavior occurs. This is what happens every time I clock the sweep unit:
In another part of the APU code, when generating the current sample to be output, if the sweep unit is enabled and .sweepresult calculated in the above code is greater than zero I use that value as the effective period. If sweep is enabled and .sweepresult is zero, the channel is silenced. Does anybody see at a glance what it is that I'm doing wrong?
Code:
Private Sub sweepclock()
Dim s As Long, wl As Long, chan As Long
If allowsweeps = 0 Then Exit Sub
For chan = 0 To 1
If (square(chan).sweep > 0) Then square(chan).sweep = square(chan).sweep - 1
If ((square(chan).sweepenable <> 0) And (square(chan).sweep > 0)) Then
wl = square(chan).period
s = wl \ (2 ^ square(chan).sweep)
If square(chan).negate Then s = (Not s) + (chan Xor 1)
wl = square(chan).period + s
If ((wl < &H800&) And (wl > 7)) Then square(chan).sweepresult = wl Else square(chan).sweepresult = 0
Else
square(chan).sweepresult = 0
End If
Next chan
End Sub
Dim s As Long, wl As Long, chan As Long
If allowsweeps = 0 Then Exit Sub
For chan = 0 To 1
If (square(chan).sweep > 0) Then square(chan).sweep = square(chan).sweep - 1
If ((square(chan).sweepenable <> 0) And (square(chan).sweep > 0)) Then
wl = square(chan).period
s = wl \ (2 ^ square(chan).sweep)
If square(chan).negate Then s = (Not s) + (chan Xor 1)
wl = square(chan).period + s
If ((wl < &H800&) And (wl > 7)) Then square(chan).sweepresult = wl Else square(chan).sweepresult = 0
Else
square(chan).sweepresult = 0
End If
Next chan
End Sub
In another part of the APU code, when generating the current sample to be output, if the sweep unit is enabled and .sweepresult calculated in the above code is greater than zero I use that value as the effective period. If sweep is enabled and .sweepresult is zero, the channel is silenced. Does anybody see at a glance what it is that I'm doing wrong?