Why does BSNES have a 32040.5 Hz sampling rate?

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
psycopathicteen
Posts: 2923
Joined: Wed May 19, 2010 6:12 pm

Why does BSNES have a 32040.5 Hz sampling rate?

Post by psycopathicteen » Wed Aug 08, 2018 8:43 am

It's half of a prime number. Is this number chosen so that it only syncs up with the master cycle every 22 seconds, as a way to estimate the randomness of the real chip?
Last edited by psycopathicteen on Wed Aug 08, 2018 9:00 am, edited 1 time in total.

tepples
Posts: 21936
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by tepples » Wed Aug 08, 2018 8:53 am

The APU runs at "roughly" 3.07 MHz, with 64 S-DSP cycles and 32 S-SMP cycles per sample. The 32040.5 Hz sample rate implies a 3075888 Hz overall APU rate. I don't see where the 22 enters into anything.

If I were designing a "performance" profile, I'd produce one APU cycle for every 7 master clock cycles. That'd give 945/44*1000000/7/96 = 31960.22 Hz.

psycopathicteen
Posts: 2923
Joined: Wed May 19, 2010 6:12 pm

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by psycopathicteen » Wed Aug 08, 2018 9:10 am

It takes 22 seconds for both the master clock and the sampling rate to hit a whole number at the same time.

lidnariq
Posts: 9284
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by lidnariq » Wed Aug 08, 2018 9:26 am

psycopathicteen wrote:as a way to estimate the randomness of the real chip?
I believe this is correct.

The S-APU uses a ceramic resonator, which are a comparatively low-precision clock source (≈0.1% to 0.5% error). For whatever reason, the one in the SNES seems to tend fast.

And using a large prime number makes it harder for people to make timed code that will fail on actual hardware when the clock rates don't match, without needing to dynamically change the clock rate every time the emulation starts.

psycopathicteen
Posts: 2923
Joined: Wed May 19, 2010 6:12 pm

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by psycopathicteen » Wed Aug 08, 2018 10:51 am

If you're going to make an HDMA streaming code work on every SNES (except for broken ones) you probably want it to tolerate any rate between 64.5 cycles per scanline to 65.5 cycles per scanline. I think having 9 lines of data plus 2 scanlines for timing would be a good idea, because 9 lines would be enough for 4 BRR blocks, and 11*20 = 220 which is close to 224 lines.

creaothceann
Posts: 220
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by creaothceann » Wed Aug 08, 2018 11:37 am

My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10

psycopathicteen
Posts: 2923
Joined: Wed May 19, 2010 6:12 pm

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by psycopathicteen » Wed Aug 08, 2018 12:30 pm

"d4s' Breath of Fire II HDMA audio streamer due to a race condition"

Wait, so this is to get it to work on somebody's ROM hack? You'd think Byuu could've got d4s to fix his ROM hack instead?

creaothceann
Posts: 220
Joined: Mon Jan 23, 2006 7:47 am
Location: Germany
Contact:

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by creaothceann » Wed Aug 08, 2018 1:12 pm

Note that this was "in an older release of bsnes", so there's a possibility that the timing was slightly off.

Anyway, if the ROM hack works on a real SNES, it's better to change the emulator.
My current setup:
Super Famicom ("2/1/3" SNS-CPU-GPM-02) → SCART → OSSC → StarTech USB3HDCAP → AmaRecTV 3.10

93143
Posts: 1133
Joined: Fri Jul 04, 2014 9:31 pm

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by 93143 » Wed Aug 08, 2018 2:38 pm

creaothceann wrote:if the ROM hack works on every real SNES, it's better to change the emulator.
FTFY

It seems to me that if it doesn't work with exactly 32040 Hz, odds are it will fail sooner or later on somebody's console.

I imagine the BoFII streaming code is similar to the N-Warp Daisakusen method, which if I recall correctly uses a constant 66-cycle pickup loop. This is a bit long even for PAL, but it works okay if you keep the data bursts short.* For NTSC it's a full cycle too long and will quickly get out of sync. In any case, if 32040.5 works but 32040 doesn't, it suggests that he was pushing the timing a little hard, and I wouldn't trust it on a real SNES.

But I haven't actually examined the issue, so take the above with a grain of salt. For all I know there could have been a bug in bsnes...


* It helps that he just dumps the data to the stack and relocates it later, rather than writing it directly to the desired location like my proposed method, because the stack method is faster and leaves more room for timing slop. This is why I need a hot-swappable sub-cycle delay block and he doesn't.

psycopathicteen
Posts: 2923
Joined: Wed May 19, 2010 6:12 pm

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by psycopathicteen » Wed Aug 08, 2018 6:55 pm

It must be off by less than a cycle. I'm not sure if it's the NTSC or PAL version that didn't work at 32040 though.

byuu
Posts: 1545
Joined: Mon Mar 27, 2006 5:23 pm
Contact:

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by byuu » Sat Aug 11, 2018 7:04 pm

It's 32040hz now, and has been for a long time. If you choose to use a 7-year old release, it's on you.

Regardless, it really doesn't matter what value is chosen, so long as it's within the accepted tolerance of the ceramic capacitor.

I would bet large sums of money d4s' streamer will break on some real hardware units, but certainly not most ... he's really thorough about testing his stuff.

93143
Posts: 1133
Joined: Fri Jul 04, 2014 9:31 pm

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by 93143 » Sat Aug 11, 2018 8:57 pm

byuu wrote:It's 32040hz now, and has been for a long time.
What actually was the issue? Was the hack fixed, or was there a bug in bsnes causing the problem, or does the hack no longer work?

psycopathicteen
Posts: 2923
Joined: Wed May 19, 2010 6:12 pm

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by psycopathicteen » Sun Aug 12, 2018 9:52 am

If you choose to use a 7-year old release, it's on you.
I got the information from 7-year old forum threads.

Edit:
Wait, that forum thread said 2016? I'm confused.

byuu
Posts: 1545
Joined: Mon Mar 27, 2006 5:23 pm
Contact:

Re: Why does BSNES have a 32040.5 Hz sampling rate?

Post by byuu » Mon Aug 13, 2018 9:19 am

93143 wrote:What actually was the issue? Was the hack fixed, or was there a bug in bsnes causing the problem, or does the hack no longer work?
I stopped caring. No idea if it works or not, sorry ^^;

Post Reply