Author Topic: How does the NES Sound processor (2A03) produce the noise waveforms?  (Read 1949 times)

0 Members and 1 Guest are viewing this topic.

Offline ELS122Topic starter

  • Frequent Contributor
  • **
  • Posts: 917
  • Country: 00
the built-in Audio Processing Unit in the 2A03 in the NES has a noise channel, which has 2 modes, one sounds like static and other more metallic and gritty.
but how does it make these waveforms? also how does it make it sound like a specific pitch?
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3368
  • Country: ua
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #1 on: July 01, 2022, 04:15:25 am »
probably the same as it implemented in AY8910/YM2149F PSG chip - random noise generator on linear feedback shift register which output is feed into programable divider to allow select noise frequency. 

I don't know about 2A03, but AY8910/YM2149F also allows to change volume and it includes several predefined envelopes, so the noise can be modulated with AM.
« Last Edit: July 01, 2022, 04:19:19 am by radiolistener »
 
The following users thanked this post: ELS122

Offline ELS122Topic starter

  • Frequent Contributor
  • **
  • Posts: 917
  • Country: 00
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #2 on: July 01, 2022, 04:18:43 am »
* NES VST noise EtoG.mp3 (88.84 kB - downloaded 34 times.)

here's notes E to G using NES VST plugin, set on the "93bit noise" setting, as opposed to "32767bit noise"
 

Offline taste_tester

  • Regular Contributor
  • *
  • Posts: 73
  • Country: us
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #3 on: July 03, 2022, 01:34:19 am »
The noise generator is a linear-feedback shift register in an 8 bit chip, so it's almost certainly using some kind of pseudorandom number or noise generator, which explains why the output seems consistent.
 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7738
  • Country: ca
 

Offline ELS122Topic starter

  • Frequent Contributor
  • **
  • Posts: 917
  • Country: 00
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #5 on: July 03, 2022, 10:53:35 am »
but what do the "93bit noise" reffers to?

I doubt it would be a huge 93bit LFSR, futhermore then the white noise setting would need to be a 32767 bit LFSR which it ofc wont be
« Last Edit: July 03, 2022, 11:52:30 am by ELS122 »
 

Offline ELS122Topic starter

  • Frequent Contributor
  • **
  • Posts: 917
  • Country: 00
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #6 on: July 03, 2022, 02:45:59 pm »
on the NES VST plugin wiki I found this about noise:
Quote
The noise channel in the Nintendo is not noise in the usual sense, where amplitude or frequency would be modulated randomly. Instead, the NES sends a random sequence of bits directly to audio out. This is analagous to a square wave with a continuously-varying random pulse width. The NES produces noise in repeating sequences of 32767 or 93 bits. The pitch or color of the noise is variable at 16 modes. These modes are mapped to MIDI notes in our VST plugin.

The noise sequence produced by code is heavily aliased with a great deal of harmonic content above 22,050 hz. To solve this problem we subdivide time and create 8 unique output samples at every tick. These samples are merged and lowpass filtered to produce an 8x oversampled anti-aliased output.

so is it a LFSR with varying clock and then it being reset after 93 bits played?
but the noise changed slightly every time you play a note, so I dont think the LFSR would be reset. but then idk what the 93 bits means
« Last Edit: July 03, 2022, 03:49:26 pm by ELS122 »
 

Offline ELS122Topic starter

  • Frequent Contributor
  • **
  • Posts: 917
  • Country: 00
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #7 on: July 03, 2022, 11:44:44 pm »
well 93 can be divided into 31, so maybe it's like a 32 bit string of bit values that for some reason has 1 bit subtracted, and since the NES has 4 bit audio that would mean that there's an LFSR the length of 4, and with its configuration it returns to value 0 after 8 cycles? idk if that makes sense.
maybe I'll just try decompiling the NES VST plugin and see how it was done in code
 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7738
  • Country: ca
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #8 on: July 03, 2022, 11:46:16 pm »
93 bits is the width of the LFSR.  Take a look at the SID random noise.  It is only an 8 bit output dac, but they use a 23bit LFSR so that the generated noise will achieve all possible numbers over time.  Read the linked WIKI.  Take a look at their example and follow the logic in your head.  That 16bit example will not achieve the 65536 states they claim if you just run the thing indefinitely.  Unfortunately, they will hit a smaller repetitive loop of numbers well below 65536.  But if you only use the bottom 8 bit out as an 8 bit random number generator, then you will possibly achieve a pattern with 256 steps, but only a few thousand possibilities before it repeats.  This is why the 8bit SID uses 23 bits for it's random number generator as the pattern it generates is large enough to not create an audible repetitive sub-tone.  An 8 bit LFSR just wouldn't be enough.  Even using 8 bits out of a 16bit LFSR might have generated an acoustic sub-tone as that counter would repeat every few k clock cycles, and if your sample playback is 10 or 20 Khz, buried repetitious pattern may generate something you may be able to hear.
 

Offline ELS122Topic starter

  • Frequent Contributor
  • **
  • Posts: 917
  • Country: 00
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #9 on: July 03, 2022, 11:54:45 pm »
93 bits is the width of the LFSR.  Take a look at the SID random noise.  It is only an 8 bit output dac, but they use a 23bit LFSR so that the generated noise will achieve all possible numbers over time.  Read the linked WIKI.  Take a look at their example and follow the logic in your head.  That 16bit example will not achieve the 65536 states they claim if you just run the thing indefinitely.  Unfortunately, they will hit a smaller repetitive loop of numbers well below 65536.  But if you only use the bottom 8 bit out as an 8 bit random number generator, then you will possibly achieve a pattern with 256 steps, but only a few thousand possibilities before it repeats.  This is why the 8bit SID uses 23 bits for it's random number generator as the pattern it generates is large enough to not create an audible repetitive sub-tone.  An 8 bit LFSR just wouldn't be enough.  Even using 8 bits out of a 16bit LFSR might have generated an acoustic sub-tone as that counter would repeat every few k clock cycles, and if your sample playback is 10 or 20 Khz, buried repetitious pattern may generate something you may be able to hear.

so you're saying that the 32767 bit mode would have a 32767 width LFSR? that's insane, even for today.

and I found this on an archived website while researching VST plugins.
Quote
The random wavelength channel prodces waves of lengths in integer multiples
inbetween 1 and 16 of 1-of-16 predefined base wavelengths. This results in
the ability for this channel to be suitable for all kinds of noisey sound
effect simulations. Output frequencys can range anywhere from 29.3 Hz to 447
KHz. It's key feature is it's 15-bit shift register-based random number
generator, which has two operational modes.

so now I know that it's a 15 bit width LFSR.
the 2 operational modes could be 2 tap configurations... maybe I can use the 6502's (iirc) die images to try to figure out which configurations those are, I heard that the 6502 is similar to the 2A03


actually reading the article to the end answered all my questions.

here it is fyi:
Quote
The noise channel has a 1-bit pseudo-random number generator. It's based on
a 15-bit shift register, and an exclusive or gate. The generator can produce
two types of random number sequences: long, and short. The long sequence
generates 32,767-bit long number patterns. The short sequence generates
93-bit long number patterns. The 93-bit mode will generally produce higher
sounding playback frequencys on the channel. Here is the bit that controls
the mode:

$400E bits
----------
7   mode

If mode=0, then 32,767-bit long number sequences will be produced (32K
mode), otherwise 93-bit long number sequences will be produced (93-bit
mode).

The following diagram shows where the XOR taps are taken off the shift
register to produce the 1-bit pseudo-random number sequences for each mode.

mode       <-----
----   EDCBA9876543210
32K   **
93-bit   *     *

The current result of the XOR will be transferred into bit position 0 of the
SR, upon the next shift cycle. The 1-bit random number output is taken from
pin E, is inverted, then is sent to the volume/envelope decay hardware for
the noise channel. The shift register is shifted upon recieving 2 clock
pulses from the programmable timer (the shift frequency will be half that of
the frequency from the programmable timer (one octave lower)).

On 2A03 reset, this shift register is loaded with a value of 1.


RP2A03E quirk
-------------
I have been informed that revisions of the 2A03 before "F" actually lacked
support for the 93-bit looped noise playback mode. While the Famicom's 2A03
went through 4 revisions (E..H), I think that only one was ever used for the
front loading NES: "G". Other differences between 2A03 revisions are
unknown.

and here's a link for it: https://web.archive.org/web/20220331114130/https://www.nesdev.com/2A03%20technical%20reference.txt
« Last Edit: July 03, 2022, 11:59:22 pm by ELS122 »
 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7738
  • Country: ca
Re: How does the NES Sound processor (2A03) produce the noise waveforms?
« Reply #10 on: July 04, 2022, 12:07:05 am »
93 bits is the width of the LFSR.  Take a look at the SID random noise.  It is only an 8 bit output dac, but they use a 23bit LFSR so that the generated noise will achieve all possible numbers over time.  Read the linked WIKI.  Take a look at their example and follow the logic in your head.  That 16bit example will not achieve the 65536 states they claim if you just run the thing indefinitely.  Unfortunately, they will hit a smaller repetitive loop of numbers well below 65536.  But if you only use the bottom 8 bit out as an 8 bit random number generator, then you will possibly achieve a pattern with 256 steps, but only a few thousand possibilities before it repeats.  This is why the 8bit SID uses 23 bits for it's random number generator as the pattern it generates is large enough to not create an audible repetitive sub-tone.  An 8 bit LFSR just wouldn't be enough.  Even using 8 bits out of a 16bit LFSR might have generated an acoustic sub-tone as that counter would repeat every few k clock cycles, and if your sample playback is 10 or 20 Khz, buried repetitious pattern may generate something you may be able to hear.

so you're saying that the 32767 bit mode would have a 32767 width LFSR? that's insane, even for today.

No, I never said that.

I said that a 16 bit LFSR would achieve less than 65536 patterns before it looped.  Something like 10k cycles at it's maximum before a repeat number comes and the cycle restarts.  So, an approximate 24 bit LFSR (utilizing it's bottom 16 bits as your random number) should do an adequate job.  Not a 32767 bit LFSR.  For a 32bit number, I use a 43bit LFSR XORED with a 37 bit CASR random number generator running in parallel, see here:
https://github.com/BrianHGinc/BrianHG-DDR3-Controller/blob/c901baa0c41ae46389940ae729cc772c8d40a8f1/BrianHG_DDR3_GFX_source_v16/BrianHG_draw_test_patterns.sv#L527

That is not a 4 billion bit LFSR to generate a random 32bit number.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf