It is currently Tue Jul 17, 2018 3:04 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 10 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: What am I doing wrong with my sweeps?Posted: Wed Feb 10, 2016 9:50 pm

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
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:

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

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?

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Wed Feb 10, 2016 11:37 pm

Joined: Sun Mar 19, 2006 3:06 am
Posts: 584
Location: Gothenburg/Sweden
Check out the psuedocode by Disch, it's helped me alot. Found in this thread:
viewtopic.php?f=3&t=13767

_________________
http://nes.goondocks.se/

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Thu Feb 11, 2016 6:53 pm

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
I've been comparing, but I'm still having no luck. I've got to be missing something.

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Thu Feb 11, 2016 11:26 pm

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1849
VB is barf and I have a hard time reading it.... so I might be misreading some of this... but from what I can see:

1)
Code:
If (square(chan).sweep > 0) Then square(chan).sweep = square(chan).sweep - 1
If ((square(chan).sweepenable <> 0) And (square(chan).sweep > 0)) Then

That 2nd line looks like it is happening always. It should have an 'else' because you should only do it if the sweep counter was zero at the time of the clock.

2) 'sweepresult' probably should not be a separate variable. The sweep unit directly modifies 'period'

3) You might want to consider a separate approach to indicate whether or not the sweep unit is forcing silence on the channel. Your current approach will only silence the channel if sweep is enabled -- but it should be silencing it even when disabled. See my pseudocode in the thread oRBIT2002 linked for a recommended way to handle this.

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Fri Feb 12, 2016 10:34 pm

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
Disch wrote:
VB is barf and I have a hard time reading it.... so I might be misreading some of this... but from what I can see:

1)
Code:
If (square(chan).sweep > 0) Then square(chan).sweep = square(chan).sweep - 1
If ((square(chan).sweepenable <> 0) And (square(chan).sweep > 0)) Then

That 2nd line looks like it is happening always. It should have an 'else' because you should only do it if the sweep counter was zero at the time of the clock.

2) 'sweepresult' probably should not be a separate variable. The sweep unit directly modifies 'period'

3) You might want to consider a separate approach to indicate whether or not the sweep unit is forcing silence on the channel. Your current approach will only silence the channel if sweep is enabled -- but it should be silencing it even when disabled. See my pseudocode in the thread oRBIT2002 linked for a recommended way to handle this.

Agreed VB is terrible, especially for emulators. That's why I'm doing it. I wrote a NES emulator and a PC emulator in C a few years ago, but have a soft spot for VB since I learned how to code using that and QB... just wanted to see how good of an emu I could make with it.

I'm going to try your suggestions and see what I come up with, thanks!

BTW, if you think NES in VB6 is a waste of time... check this out: http://www.vbforums.com/showthread.php? ... C-emulator!

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Sat Feb 13, 2016 6:55 pm

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20255
Location: NE Indiana, USA (NTSC)
miker00lz wrote:
Agreed VB is terrible, especially for emulators.

VB6 I'm inclined to agree. But what makes VB.NET particularly more "terrible" than C#? I thought the "Visual Fred" camp said VB.NET was C# semantics with different syntax.

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Sat Feb 13, 2016 6:59 pm

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
tepples wrote:
miker00lz wrote:
Agreed VB is terrible, especially for emulators.

VB6 I'm inclined to agree. But what makes VB.NET particularly more "terrible" than C#? I thought the "Visual Fred" camp said VB.NET was C# semantics with different syntax.

Nothing makes it worse than C#, you're right. When I say VB I only refer to VB6.

VB6 is a great language for rapid development of business apps and small utilities, but that's about it. Emulators? Fuhgeddaboutit... doesn't even have unsigned integers!!

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Sat Feb 13, 2016 8:34 pm

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1849
miker00lz wrote:
Fuhgeddaboutit... doesn't even have unsigned integers!!

Neither does Java =P

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Sat Feb 13, 2016 11:08 pm

Joined: Thu Sep 23, 2010 7:28 pm
Posts: 232
I'm not particularly fond of Java either, lol. Took a few classes for it in college. It's good for easy cross-platform compatibility.

Anyway, I got the sweeps more or less working. Still some bugs, but I'll work them out. Thanks Disch!

Here is an mp3 of me playing through the SMB world 1-1: http://proliant.rubbermallet.org/vbnes-smb.mp3

Pipes sound pretty good, everything else is still off.

And just for fun, here is vbNES playing a cool chiptune by zanzan: http://proliant.rubbermallet.org/vbnes- ... _over.flac

Top

 Post subject: Re: What am I doing wrong with my sweeps?Posted: Sat Feb 13, 2016 11:14 pm

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1849
Sounds like you are letting your linear counter wrap from 0->Load instead of stopping it at zero.

It also sounds like you are clocking all subunits way to fast -- which suggests your Frame Counter is being clocked too fast.

Let's see some tracelogs! Tracelogs tracelogs tracelogs. Make some logs that show when \$4017 is being written to, Frame Counter clocks, and what the Linear counter is doing on each of its clocks.

These problems are so easy to solve with tracelogs!

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 10 posts ]

 All times are UTC - 7 hours

Who is online

Users browsing this forum: No registered users and 8 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki