Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Audio

Note

This page is currently a stub and needs more detail.

Starfrootle has 16 audio channels. Every channel is a mono source with a pan control, and all channels are mixed into a stereo output at 48,000 Hz (800 samples per frame at 60 FPS). Pan the center to get a mono sound, or play a stereo sound on two channels panned hard left and hard right.

The CPU only writes to registers. The console generates the sound itself, and music and sound effects are handled by code in the game.

Where the audio registers live in memory is described in I/O Layout.

Signal Flow

Each channel passes through the following steps, in order:

  1. Source: a generated wave, noise, or a sample.
  2. Filter: a low-pass filter (only if the filter is enabled).
  3. Envelope and volume: the envelope shapes the volume over time (only if the envelope is enabled).
  4. Effect sends: a part of the signal is sent to the global reverb, chorus and delay.
  5. Pan: the signal is placed between the left and right outputs.

The three global effects are mixed with the channels to make the final output, which is then scaled by the master volume.

Channel Entry

A channel entry is exactly 64 bytes. Channel N lives at base + N * 0x40, where base is the start of the audio channel table (see I/O Layout).

All of the multi-byte values in a channel entry are big-endian. Zeroed memory is silent.

Layout

OffsetSizeField
+0x001 byteFlags
+0x011 byteSource
+0x021 byteVariant
+0x031 byteVolume
+0x041 bytePan (signed)
+0x052 bytesPitch
+0x071 byteEnvelope: attack
+0x081 byteEnvelope: decay
+0x091 byteEnvelope: sustain level
+0x0A1 byteEnvelope: release
+0x0B1 byteVibrato: rate
+0x0C1 byteVibrato: depth
+0x0D1 byteVibrato: shape
+0x0E1 byteFilter: cutoff
+0x0F1 byteFilter: peak
+0x101 byteReverb send
+0x111 byteChorus send
+0x121 byteDelay send
+0x131 byteReserved
+0x143 bytesSample start address
+0x173 bytesSample end address
+0x1A3 bytesSample loop start address
+0x1D3 bytesSample loop end address
+0x2032 bytesReserved

Flags

Offset +0x00

BitFlag
0Gate: a note starts when this changes from 0 to 1, and is released when it changes from 1 to 0
1Loop (samples only)
2Envelope enabled
3Filter enabled
4Active (read only): 1 while the channel is making sound. The console sets and clears this bit, and writes to it are ignored.
5 to 7Reserved

When a note starts, the envelope begins its attack from silence, the vibrato starts at the beginning of its cycle, the filter is cleared, and a sample starts playing from its start address.

When a note is released, the envelope starts its release. If the envelope is not enabled, the sound stops immediately. The active bit is cleared once the sound has fully stopped, which includes a sample reaching its end when it isn’t looping. To play a note again after that, write 0 and then 1 to the gate.

Source and Variant

Offsets +0x01 and +0x02

SourceSound
0Pulse
1Triangle
2Saw
3Sine
4Noise
5Sample

Values above 5 are not yet defined.

The variant changes how some sources sound, and is ignored by the others:

SourceVariant
PulseDuty cycle: the fraction of each wave that is high, as the value divided by 256 (0x80 is 50%, 0x40 is 25%)
Noise0 is long noise, 1 is short, more metallic noise. Other values are not yet defined.

Volume and Pan

Offsets +0x03 and +0x04

Volume goes from 0 (silent) to 255 (full volume).

Pan is a signed byte from -128 (fully left) through 0 (center) to 127 (fully right). At the center, both sides play at full volume. Moving away from the center fades the opposite side out linearly.

Pitch

Offsets +0x05 and +0x06

Pitch is a 16-bit value that sets the playback speed as a multiple of the sample’s native speed:

speed = pitch / 0x1000

So 0x1000 plays at normal speed, 0x2000 plays one octave higher, and 0x0800 plays one octave lower. A pitch of 0x0000 is silent. The values are linear in frequency, so going up an octave doubles the value, which is a shift left.

Samples are expected to be tuned to C-5 and have a native rate of 32,000 Hz, so 0x1000 is C-5. Generated waves at 0x1000 also produce C-5 (about 523.25 Hz), and scale linearly from there. Noise advances at the same ratio.

Notes follow equal temperament with A-4 at 440 Hz. This is the table for octave 5, and every other octave is this table shifted left (up) or right (down) once per octave:

NotePitchNotePitch
C-50x1000F#-50x16A1
C#-50x10F4G-50x17F9
D-50x11F6G#-50x1966
D#-50x1307A-50x1AE9
E-50x1429A#-50x1C82
F-50x155CB-50x1E34

The range of notes that fit is C-0 (0x0080) to B-8 (0xF1A2). One step of pitch is about 0.42 cents at C-5, and is coarser for lower notes.

Envelope

Offsets +0x07 to +0x0A

The envelope shapes the volume of a note, and only applies if the envelope flag is set. Without it, a note plays at full volume until it is released.

OffsetFieldMeaning
+0x07AttackFrames to rise from silence to full volume
+0x08DecayFrames to fall from full volume to the sustain level
+0x09Sustain levelThe level held while the gate is 1, from 0 (silent) to 255 (full)
+0x0AReleaseFrames to fall from the current level to silence after the gate is released

A frame is 1/60 of a second, and a time of 0 is instant. All of the changes are linear.

Vibrato

Offsets +0x0B to +0x0D

Vibrato is a low frequency oscillator (LFO) that moves the pitch up and down.

OffsetFieldMeaning
+0x0BRateCycles per second, as the value divided by 16 (0x60 is 6 Hz)
+0x0CDepthThe peak change in pitch in semitones, as the value divided by 16 (0x10 is one semitone up and down). A depth of 0 is no vibrato.
+0x0DShape0 sine, 1 triangle, 2 saw, 3 square. Other values are not yet defined.

The depth is measured in semitones, so vibrato sounds the same in every octave.

Filter

Offsets +0x0E and +0x0F

A two pole low-pass filter that only applies if the filter flag is set.

OffsetFieldMeaning
+0x0ECutoffCutoff frequency, from 20 Hz at 0 rising exponentially to about 20 kHz at 255. The frequency is 20 Hz × 2^(value / 25.5).
+0x0FPeakResonance peak at the cutoff, from 0 (no peak) to 255 (the strongest peak), roughly a Q of 0.7 to 10

Effect Sends

Offsets +0x10 to +0x12

Each send is how much of this channel’s sound goes to the matching global effect, from 0 (none) to 255 (full). The send is taken after the envelope and volume are applied, and before pan.

Samples

Offsets +0x14 to +0x1F

A sample is a run of 8-bit signed mono samples, one byte per sample, with a native rate of 32,000 Hz. Samples are read straight from memory, usually ROM. Playback uses linear interpolation.

OffsetField
+0x14Start address: where playback begins when a note starts
+0x17End address: the address just after the last sample. Playback stops here unless the loop flag is set.
+0x1ALoop start address
+0x1DLoop end address: the address just after the last looped sample

When the loop flag is set, playback jumps back to the loop start whenever it reaches the loop end, and the end address is not used. Samples can have an intro before the loop start.

Global Block

The global block holds settings for the whole mix. It lives right after the channel table (see I/O Layout).

OffsetSizeFieldMeaning
+0x001 byteMaster volume0 (silent) to 255 (full)
+0x011 byteReverb returnHow loud the reverb is in the mix, 0 to 255
+0x021 byteReverb decayHow long the reverb lasts, 0 (shortest) to 255 (longest)
+0x031 byteChorus returnHow loud the chorus is in the mix, 0 to 255
+0x041 byteChorus rateSpeed of the chorus, in the same units as the vibrato rate (value divided by 16, in Hz)
+0x051 byteChorus depthAmount of the chorus, 0 (none) to 255 (most)
+0x061 byteDelay returnHow loud the delay is in the mix, 0 to 255
+0x071 byteDelay timeTime between echoes, in units of 5 milliseconds (up to 1.275 seconds)
+0x081 byteDelay feedbackHow much of each echo is fed back into the delay, as the value divided by 256
+0x097 bytesReserved

Since zeroed memory has a master volume of 0, a game has to set the master volume before it will hear anything.

Warning

The exact algorithms behind the reverb, chorus and delay are purposely left undefined for now. Only their settings are defined here.