Sweep (?) Bug in APU

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Sweep (?) Bug in APU
by on (#242922)
Hi guys,

I have to bother you one more time, since I always get perfect and immediate help from you.
So, I'm about to finish my APU, or so I thought.

I was playing SMB, and the first level seemed to be great audio-wise. But after Mario automatically enters the pipe to the second level, things started to become off. It sounded like the sweep is applying even though it shouldn't (maybe I'm wrong, this is just what I'm assuming).
I tried several times, always with the same outcome.

I recorded a video of it, so you can see for yourselves:
https://www.youtube.com/watch?v=L7buybdlzMU

Edit: Clarification, the 'real' problems occur in Level 2, about 1min in (or so). (You can still hear some grumbling when entering the pipe in the coin room in Lvl 1 as well though)

If anyone can give me a hint, what I'm probably not doing correctly (disabling the sweep at some point or something), I would greatly appreciate it.

Thanks a lot!
Re: Sweep (?) Bug in APU
by on (#242923)
When the frequency gets too high, the channel is automatically silenced.
It also sounds like the length counter/volume envelope isn't quite right yet.

Also that is the European version of SMB1 for some reason.
Re: Sweep (?) Bug in APU
by on (#242924)
I do check for timer values below 8 and above 0x7ff.
Length counter isn't used in SMB, as far as I can tell (Mesen has all length counters unchecked at all times, and it appears to be never called in my code).

What's wrong with the envelope? Like, where do you hear something wrong?
Yes, because I'm European, it's the european version ;-)
Re: Sweep (?) Bug in APU
by on (#242925)
Sounds like it's running the PAL version with NTSC emulation, though. Better run the NTSC version to eliminate potential problems with that. I doubt this is what's happening here (just purely a guess as an example), but I can imagine a PAL program getting the sweep stuck like that on NTSC, because the longer PAL frames would give it enough time to hit the max frequency and silence itself. But on NTSC maybe the same program would disable the sweep manually (if they chose to) before that happens.

The crackling at the end of level 1 makes it seem like something else though (edit: I mean after the pipe sound)
Re: Sweep (?) Bug in APU
by on (#242926)
Okay, I just tried the NTSC version, still have the same problems.

Also, when I completely comment out the Sweep, the ongoing sounds still persist! Without the weird sweeping of course, but a constant sound, that does not stop.

Edit: Even more information. This only happens, in subworld levels / rooms. Where there is no music on SC1 (and the length counter is continuously on zero).

Maybe with these new information you are able to narrow it down more?
Re: Sweep (?) Bug in APU
by on (#242947)
This isn't a bug with the sweep, it sounds actually like the way SMB silences sound effects isn't properly handled by your sound core. I'm guessing it's going to either be an issue with $4015 writes, or an issue with the volume envelopes with $4000/$4004 writes (I don't recall how SMB silences sound effects at the moment).

The hint that's tipping me off is the way the flagpole sounds at the end; the sound effect is supposed to mute once the flag reaches the bottom of the pole.
Re: Sweep (?) Bug in APU
by on (#242952)
That was it!

I wasn't setting the length counters to zero, on 0x4015 writes. Now it works like a charme.
Thank you so much! :-)
Re: Sweep (?) Bug in APU
by on (#242957)
I'm sure many people who have implemented an APU have heard all those crazy weird sounds too.
Re: Sweep (?) Bug in APU
by on (#242958)
Most likely! Though, it must feel awesome when all of those iconic sound effects actually sound right for the first time. :D
Re: Sweep (?) Bug in APU
by on (#242959)
It does, let me tell you! :D