Sweep (?) Bug in APU

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
LilaQ
Posts: 23
Joined: Mon Sep 02, 2019 3:28 pm

Sweep (?) Bug in APU

Post by LilaQ » Tue Oct 01, 2019 5:25 pm

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!
Last edited by LilaQ on Tue Oct 01, 2019 6:01 pm, edited 1 time in total.

User avatar
Dwedit
Posts: 4246
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Sweep (?) Bug in APU

Post by Dwedit » Tue Oct 01, 2019 5:28 pm

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.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

LilaQ
Posts: 23
Joined: Mon Sep 02, 2019 3:28 pm

Re: Sweep (?) Bug in APU

Post by LilaQ » Tue Oct 01, 2019 5:57 pm

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 ;-)

User avatar
Memblers
Site Admin
Posts: 3777
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Sweep (?) Bug in APU

Post by Memblers » Tue Oct 01, 2019 6:23 pm

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)

LilaQ
Posts: 23
Joined: Mon Sep 02, 2019 3:28 pm

Re: Sweep (?) Bug in APU

Post by LilaQ » Tue Oct 01, 2019 6:37 pm

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?

Drag
Posts: 1289
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Re: Sweep (?) Bug in APU

Post by Drag » Wed Oct 02, 2019 7:59 pm

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.

LilaQ
Posts: 23
Joined: Mon Sep 02, 2019 3:28 pm

Re: Sweep (?) Bug in APU

Post by LilaQ » Thu Oct 03, 2019 4:16 am

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! :-)

User avatar
Dwedit
Posts: 4246
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Sweep (?) Bug in APU

Post by Dwedit » Thu Oct 03, 2019 11:45 am

I'm sure many people who have implemented an APU have heard all those crazy weird sounds too.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

Drag
Posts: 1289
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Re: Sweep (?) Bug in APU

Post by Drag » Thu Oct 03, 2019 5:47 pm

Most likely! Though, it must feel awesome when all of those iconic sound effects actually sound right for the first time. :D

LilaQ
Posts: 23
Joined: Mon Sep 02, 2019 3:28 pm

Re: Sweep (?) Bug in APU

Post by LilaQ » Thu Oct 03, 2019 5:52 pm

It does, let me tell you! :D

Post Reply