It is currently Tue Oct 24, 2017 4:39 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Wed Feb 10, 2016 9:50 pm 
Offline
User avatar

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
 Profile  
 
PostPosted: Wed Feb 10, 2016 11:37 pm 
Offline
User avatar

Joined: Sun Mar 19, 2006 3:06 am
Posts: 583
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
 Profile  
 
PostPosted: Thu Feb 11, 2016 6:53 pm 
Offline
User avatar

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
 Profile  
 
PostPosted: Thu Feb 11, 2016 11:26 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
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
 Profile  
 
PostPosted: Fri Feb 12, 2016 10:34 pm 
Offline
User avatar

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
 Profile  
 
PostPosted: Sat Feb 13, 2016 6:55 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19122
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
 Profile  
 
PostPosted: Sat Feb 13, 2016 6:59 pm 
Offline
User avatar

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
 Profile  
 
PostPosted: Sat Feb 13, 2016 8:34 pm 
Offline
User avatar

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



Neither does Java =P


Top
 Profile  
 
PostPosted: Sat Feb 13, 2016 11:08 pm 
Offline
User avatar

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
 Profile  
 
PostPosted: Sat Feb 13, 2016 11:14 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google [Bot] and 7 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group