The four channels
A tune’s PLAY routine writes to registers $FF10 to $FF3F. The sound
chip has two pulse channels (square waves with a duty cycle, channel 1 also with a frequency
sweep), a wave channel that plays 32 four-bit samples from wave RAM, and a noise channel built
on a shift register. Each of 1 to 4 has a length counter; 1, 2 and 4 have a volume envelope.
The registers below are described fully in Pan Docs (Audio Registers).
Registers
| Address | Name | Bits |
|---|---|---|
$FF10 | NR10, sweep (channel 1) | 6-4 sweep period; 3 direction (1 down); 2-0 shift. |
$FF11 | NR11, length and duty | 7-6 duty (12.5%, 25%, 50%, 75%); 5-0 initial length timer (written). |
$FF12 | NR12, envelope | 7-4 initial volume; 3 direction (1 up); 2-0 pace (0 = no envelope). Zero in bits 7-3 turns the channel’s DAC off. |
$FF13 | NR13, period low | Low 8 bits of the 11-bit period (write only). |
$FF14 | NR14, period high and control | 7 trigger; 6 length enable; 2-0 period bits 10-8. |
$FF16 to $FF19 | NR21 to NR24 (channel 2) | As NR11 to NR14 (no sweep register). |
$FF1A | NR30, DAC | 7 DAC on. |
$FF1B | NR31, length | Initial length timer, 8 bits. |
$FF1C | NR32, output level | 6-5: 0 mute, 1 full (100%), 2 half (50%), 3 quarter (25%). |
$FF1D, $FF1E | NR33, NR34 | Period low; high 3 bits with trigger (7) and length enable (6). |
$FF20 | NR41, length | 5-0 initial length timer. |
$FF21 | NR42, envelope | As NR12. |
$FF22 | NR43, noise | 7-4 clock shift; 3 width (1: 7-bit LFSR); 2-0 divider code. |
$FF23 | NR44, control | 7 trigger; 6 length enable. |
$FF24 | NR50, master volume | 6-4 left volume; 2-0 right volume (the VIN bits 7 and 3 are unused). |
$FF25 | NR51, panning | Bits 7-4 channels 4 to 1 to the left; bits 3-0 channels 4 to 1 to the right. |
$FF26 | NR52, power | 7 sound on; 3-0 channel 4 to 1 is playing (read only). |
$FF30 to $FF3F | Wave RAM | 16 bytes, 32 four-bit samples, high nibble first. |
Pitch
With the period x from the 11-bit field (0 to 2047):
- pulse channels: 131072 / (2048 − x) Hz;
- wave channel: 65536 / (2048 − x) Hz for the whole 32-sample wave (each sample lasts 2 × (2048 − x) clocks at 2 MHz);
- noise: 262144 / (r × 2s) Hz as the clock of the shift register, where s is the clock shift, and r the divider (0.5 for code 0, else the code).
The explorer’s test with its built tune checks the four pitches against these formulas.
Level
The explorer’s sound chip is libvgm’s port of SameBoy’s, and its output level is libvgm’s: each
channel step is CH_STEP = MAX_CH_AMP / 15 / 8 (integer divisions), with
MAX_CH_AMP = 0x1E00 in libvgm
(emu/cores/sameboy_apu_private.h, “same volume as MAME core”) against
0x0FF0 in SameBoy (Core/apu.h). That makes 64 against 34 per step, so
the explorer is 64 / 34 = 1.88 times as loud as SameBoy on every channel. The VGM, HES and NSF
viewers take their chip levels from the same libvgm code, so the GBS viewer keeps it.
Against Game_Music_Emu, whose scale is Blargg’s, the explorer is about 1.32 times as loud on a whole tune (1.32 and 1.30 on the two songs of the banked sample). Measured by channel on a tune that uses all four, the ratio varies because the two programs mix the channels differently: 1.83 for square 1, 1.53 for square 2, 1.45 for the wave channel and 1.93 for noise, 1.67 for the whole tune. The shapes and the pitches are those of SameBoy’s chip: the comparison with SameBoy running the same tune as a Game Boy ROM gives a correlation of 0.995 to 0.999 on the tone channels, and the level after dividing by 64 / 34 is within 2 % on each channel.
In the explorer
The sound chip is the Game Boy core of the VGM viewer (a port of libvgm’s SameBoy sound code). The Playback tab shows the stereo output, and the options bar can silence each channel.