APU Noise
The NES APU noise channel generates pseudo-random 1-bit noise at 16 different frequencies.
Timer --> Shift Register Length Counter
| |
v v
Envelope -------> Gate ----------> Gate ---> (to mixer)
7 bit 0
---- ----
..LC VVVV
|| ||||
|| ++++- When C is set: channel volume value
|| When C is clear: envelope divider reload value
|+------ Constant volume flag (override envelope with V)
+------- Length counter halt flag and envelope loop flag
7 bit 0
---- ----
M... PPPP
| ||||
| ++++- Noise period
+--------- Periodic noise mode
The timer period is set to entry P of the following:
Period (P) | NTSC | PAL |
|---|---|---|
| $0 | 4 | 4 |
| $1 | 8 | 8 |
| $2 | 16 | 14 |
| $3 | 32 | 30 |
| $4 | 64 | 60 |
| $5 | 96 | 88 |
| $6 | 128 | 118 |
| $7 | 160 | 148 |
| $8 | 202 | 188 |
| $9 | 254 | 236 |
| $A | 380 | 354 |
| $B | 508 | 472 |
| $C | 762 | 708 |
| $D | 1016 | 944 |
| $E | 2034 | 1890 |
| $F | 4068 (2046 in early RP2A03 revisions) | 3778 |
The period determines how many CPU cycles happen between shift register clocks. These periods are all even numbers because there are 2 CPU cycles in an APU cycle.
7 bit 0
---- ----
LLLL L...
|||| |
++++-+---- Length counter load value
Writing to this register also restarts envelope.
The shift register is 15 bits wide LFSR.
When the timer clocks the shift register, the following actions occur in order:
- Feedback is calculated as the exclusive-OR of bit 0 and one other bit: bit 6 if periodic noise mode (
Mbit) is set, otherwise bit 1. - The shift register is shifted right by one bit.
- Bit 14, the leftmost bit, is set to the feedback calculated earlier.
This results in a pseudo-random bit sequence, 32767 steps long when Mode flag is clear, and randomly 93 or 31 steps long otherwise. (The particular 31- or 93-step sequence depends on where in the 32767-step sequence the shift register was when Mode flag was set).
The mixer receives the current envelope volume except when
- bit 0 of the shift register is set, or
- the length counter is zero
Within the mixer, the DMC level has a noticeable effect on the noise’s audio level.
On power-up, the shift register is loaded with the value 1.
In the earliest revisions of the 2A03 CPU, the periodic noise flag (M bit) was nonexistent: the shift register always used bits 0 and 1 for feedback, and the lowest period (rate $F) lasts 2046 M2 cycles instead of 4068. These CPUs were used in the first batch of Famicom consoles (which were recalled), in Vs. System boards, and in the arcade games that used the 2A03 as a sound coprocessor. [1], [2]
The 93-step sequence is about a quarter tone (50 cents) sharp relative to A440 tuning. The approximate frequencies and pitches (in LilyPond’s variant of Helmholtz notation) are as follows:
| NTSC | PAL | |||||||
|---|---|---|---|---|---|---|---|---|
| Register value | Sample rate | Repeat rate | MIDI note | Pitch | Sample rate | Repeat rate | MIDI note | Pitch |
| $80 | 447443.2 Hz | 4811.2 Hz | 110.41 | d''''' + 41¢ | 415651.8 Hz | 4469.4 Hz | 109.13 | c#''''' + 13¢ |
| $81 | 223721.6 Hz | 2405.6 Hz | 98.41 | d'''' + 41¢ | 207825.9 Hz | 2234.7 Hz | 97.13 | c#'''' + 13¢ |
| $82 | 111860.8 Hz | 1202.8 Hz | 86.41 | d''' + 41¢ | 118757.6 Hz | 1277.0 Hz | 87.45 | d#''' + 45¢ |
| $83 | 55930.4 Hz | 601.4 Hz | 74.41 | d'' + 41¢ | 55420.2 Hz | 595.9 Hz | 74.25 | d'' + 25¢ |
| $84 | 27965.2 Hz | 300.7 Hz | 62.41 | d' + 41¢ | 27710.1 Hz | 298.0 Hz | 62.25 | d' + 25¢ |
| $85 | 18643.5 Hz | 200.5 Hz | 55.39 | g + 39¢ | 18893.3 Hz | 203.2 Hz | 55.62 | g + 62¢ |
| $86 | 13982.6 Hz | 150.4 Hz | 50.41 | d + 41¢ | 14089.9 Hz | 151.5 Hz | 50.54 | d + 54¢ |
| $87 | 11186.1 Hz | 120.3 Hz | 46.55 | a#, + 55¢ | 11233.8 Hz | 120.8 Hz | 46.62 | a#, + 62¢ |
| $88 | 8860.3 Hz | 95.3 Hz | 42.51 | f#, + 51¢ | 8843.7 Hz | 95.1 Hz | 42.48 | f#, + 48¢ |
| $89 | 7046.3 Hz | 75.8 Hz | 38.55 | d, + 55¢ | 7044.9 Hz | 75.8 Hz | 38.54 | d, + 54¢ |
| $8A | 4709.9 Hz | 50.6 Hz | 31.57 | g,, + 57¢ | 4696.6 Hz | 50.5 Hz | 31.52 | g,, + 52¢ |
| $8B | 3523.2 Hz | 37.9 Hz | 26.55 | d,, + 55¢ | 3522.5 Hz | 37.9 Hz | 26.54 | d,, + 54¢ |
| $8C | 2348.8 Hz | 25.3 Hz | 19.53 | g,,, + 53¢ | 2348.3 Hz | 25.3 Hz | 19.52 | g,,, + 52¢ |
| $8D | 1761.6 Hz | 18.9 Hz | 14.55 | d,,, + 55¢ | 1761.2 Hz | 18.9 Hz | 14.54 | d,,, + 54¢ |
| $8E | 879.9 Hz | 9.5 Hz | 2.53 | d,,,, + 53¢ | 879.7 Hz | 9.5 Hz | 2.52 | d,,,, + 52¢ |
| $8F | 440.0 Hz | 4.7 Hz | -9.47 | d,,,,, + 53¢ | 440.1 Hz | 4.7 Hz | -9.47 | d,,,,, + 53¢ |
| V | | |
|---|---|
| Concepts | Registers | Basics | Period table |
| Channels | Pulse 1 and Pulse 2 | Triangle | Noise | DMC |
| Components | Envelope | Sweep | Frame Counter | Length Counter | DMA | Mixer |
| Expansion audio | 2C33 (Disk System) | MMC5 | VRC6 | VRC7 | Namco 163 | Sunsoft 5B | µPD7756 |