SPC-700 Noise Algorithm?

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Post Reply
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

SPC-700 Noise Algorithm?

Post by blargg »

Has the SPC-700 noise algorithm been determined exactly? A while back I examined it and found it used a similar algorithm as the NES 2A03 sound chip, with some modifications to give it a multi-bit output. I never found an exact algorithm, only something fairly close. Anomie's DSP draft covers the feedback part but not the extra mapping to the final amplitude. Here is what I use in my SPC DSP emulator:

Code: Select all

int feedback = (internal << 13) ^ (internal << 14);
internal = (feedback & 0x4000) | (internal >> 1);

if ( !(internal & 0x4000) )
    noise >>= 1;
else if ( internal & 1 )
	noise += internal;
else
	noise -= internal;
anomie
Lurker
Posts: 151
Joined: Tue Dec 07, 2004 1:40 am

Re: SPC-700 Noise Algorithm?

Post by anomie »

Well, as the DSP doc states, initial value is 0x4000, and on each iteration 'internal' is updated as your code does.

The actual noise sample is exactly this internal, though. The noise sample replaces the BRR decoded sample, before volume adjustments or the 15-to-16 bit conversion. All this was determined by running a noise channel into the echo buffer and examining the output.
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

Ouch, it really is that simple :). I must have messed up the sign-extension when I was trying endless tricky variations of the algorithm I posted. Now Chrono Trigger - Beach sounds exactly the same as on a SNES. Thanks!
Post Reply