The registers
The S-DSP has 128 registers, one byte each, at $10100 in the file: the low nibble of the address says which register, and the high nibble which voice, for the eight voices. The SPC700 reaches them through DSPADDR and DSPDATA ($F2 and $F3). The chip makes one stereo pair of 16-bit samples every 32 processor clocks (32,000 Hz) by mixing the eight voices.
Voice registers
Voice v has registers at $v0 to $v9 and $vF,
for example $30 to $39 for voice 3.
| Register | Name | Use |
|---|---|---|
| $v0, $v1 | VOL(L), VOL(R) | The voice's volume for each side, signed, 127 loudest. A negative value inverts the phase. |
| $v2, $v3 | P(L), P(H) | The pitch, 14 bits: $1000 plays the sample at its own rate (32,000 samples a second), $2000 an octave up. |
| $v4 | SRCN | The sample number: an entry of the sample directory. |
| $v5, $v6 | ADSR(1), ADSR(2) | The envelope when bit 7 of ADSR(1) is set. |
| $v7 | GAIN | The envelope when ADSR is off. |
| $v8 | ENVX | Read only: the top 7 bits of the voice's envelope. |
| $v9 | OUTX | Read only: the top 8 bits of the voice's output. |
| $vF | FIR coefficient v | The echo filter's coefficient for tap v; see echo. |
Global registers
| Register | Name | Use |
|---|---|---|
| $0C, $1C | MVOL(L), MVOL(R) | Master volume, signed. |
| $2C, $3C | EVOL(L), EVOL(R) | Echo volume, signed. |
| $4C | KON | Key on: a bit for each voice that starts a sample. |
| $5C | KOFF | Key off: a bit for each voice that enters its release. |
| $6C | FLG | Bit 7: soft reset (all voices off and silent). Bit 6: mute the output. Bit 5: stop the echo writing to RAM. Bits 0 to 4: the noise rate. |
| $7C | ENDX | A bit for each voice whose sample has reached an end block. |
| $0D | EFB | Echo feedback, signed. |
| $2D | PMON | Pitch modulation: a bit for each voice (1 to 7) whose pitch is changed by the output of the voice before it. |
| $3D | NON | Noise: a bit for each voice that plays noise in place of its sample. |
| $4D | EON | Echo: a bit for each voice that feeds the echo. |
| $5D | DIR | The page of RAM that holds the sample directory. |
| $6D | ESA | The page of RAM where the echo buffer starts. |
| $7D | EDL | The echo delay, 0 to 15: the buffer is 2,048 bytes for each step (16 ms), and 4 bytes for 0. |
Samples: BRR and the directory
The sample directory is at page DIR of RAM and has four bytes for each sample number: the address where the sample starts and the address it loops to, both little-endian. A sample is a run of 9-byte blocks of 16 samples each. The first byte of a block has the range (shift) in the top four bits, a filter number (0 to 3) in bits 2 and 3, a loop flag in bit 1 and an end flag in bit 0. The 8 bytes after it have two 4-bit signed values each. The filter predicts from the two samples before it, so each block builds on the last. At an end block the voice stops, or, with the loop flag as well, jumps to the loop address.
The DSP reads four decoded samples around the position and mixes them with a Gaussian interpolation, then applies the envelope and the volumes.
Envelopes
With bit 7 of ADSR(1) set, the envelope has four stages. The attack rises from 0 to the top at a rate of 2 × A + 1, A being bits 0 to 3 of ADSR(1). The decay falls to the sustain level at a rate of 2 × D + 16, D being bits 4 to 6. The sustain level is (S + 1) / 8 of the top, S being bits 5 to 7 of ADSR(2), and the sustain falls from there at the rate in bits 0 to 4 of ADSR(2), until a key off, after which the voice releases quickly. With bit 7 clear, GAIN is used: a value under $80 sets the level directly, and otherwise bits 5 and 6 pick a linear decrease, an exponential decrease, a linear increase or a bent increase, with the rate in bits 0 to 4. Each rate number is a period in samples from a table: rate 1 steps once every 2,048 samples, rate 31 every sample, and rate 0 never.
Echo
The voices chosen in EON are added into an echo buffer in RAM that starts at page ESA and is EDL × 2,048 bytes long. Each pair of samples read from it passes through an eight-tap FIR filter with the coefficients in the registers $0F, $1F … $7F, and goes to the output at volume EVOL and back into the buffer with the feedback EFB. The echo keeps writing into RAM unless bit 5 of FLG is set, which is why a song makes sure the buffer is clear of its program.
After the registers
The 64 bytes after the registers (offset $10180) are unused. The 64 bytes after them are RAM, under the boot ROM.
In the explorer
The 128 registers are eight voice nodes of 16 registers each, with the names above, and the global registers in between. The DSP tab shows each voice's volume, pitch (as the sample rate in hertz) and sample (with the address it starts at), the envelope worked out in words and the flags that apply to the voice, then the global registers. The sound is produced by running the song, not by reading the registers. It uses a DSP that has been compared with the C code of snes_spc on real files and on random register settings, sample for sample.
Sources
- SPC file format v0.30: the place of the registers in the file.
- Game_Music_Emu,
Spc_Dsp.cppandSpc_Dsp.h: the register map, BRR decoding, the Gaussian table, the envelopes and their period table, noise, pitch modulation and the echo.