GWAVE Code

A side by side comparison of Eugene Jarvis and Sam Dicker's 6808 assembly code for the Defender sound ROM (Williams, 1980), beside the JavaScript in GWAVE. GWAVE does not emulate the 6808. Each ROM routine is written as a generator that writes the same DAC values at the same CPU cycles.

VSNDRM1.SRC is loaded from GitHub into your browser at startup.

Loading VSNDRM1.SRC from GitHub…

GWAVE source: snapshot of GWAVE @ 20261030 7d41b2b

Clock, time and the DAC

SOUND

The ROM makes sound only by storing bytes at SOUND, the PIA port that drives the DAC. GWAVE keeps that one effect and replaces the CPU with arithmetic: it counts time in 6800 cycles and writes each byte at the cycle the ROM would have.

The 6808's clock is the 3.579545 MHz crystal divided by 4 on the chip: 894,886 cycles a second. CPU_CLOCK is that rate. FRAME_CYCLES is one 60 Hz game frame, used only to space out GWAVE's game-sound sequences.

Sound board

The 6808 runs from a 3.579545 MHz crystal, divided by 4 on the chip.

GWAVE 2248–2249

            

SOUND is port A of the PIA at $0400, wired to the MC1408 DAC. Every STAA SOUND, STAB SOUND and COM SOUND in the ROM is a this.write() in GWAVE. Both are marked red throughout this page.

VSNDRM1.SRC 11

            
GWAVE 2834–2837

            

Each routine is a generator. It yields the number of cycles until its next event and resume() adds them to this.time. The cycle counts were worked out from the source; no instruction is decoded at run time.

Sound board

The 6800 runs instruction after instruction. Between two writes to SOUND, only the number of cycles matters for the sound.

GWAVE 2839–2849

            

byte() and word() keep the 8- and 16-bit wraparound of the registers. timesLooped() and timesLoopedWord() turn a loaded count of 0 into 256 or 65,536 passes.

Sound board

8-bit counters wrap: a DECA/BNE loop that starts at 0 runs 256 times, and a DEX loop from 0 runs 65,536 times.

GWAVE 2251–2260

            

Reset

SETUP · vectors

At power-up the ROM sets up the PIA, seeds the random generator, clears its flags and waits for an interrupt.

SETUP masks interrupts, puts the stack at $7F and programs the PIA: port A (the DAC) as outputs, port B (the command) as inputs, and an interrupt on a rising CB1 edge. The first byte at $F800 is the checksum the diagnostic compares against.

VSNDRM1.SRC 168–181

            
GWAVE

GWAVE has no PIA. Commands reach the board through send().

A still holds $3C from the control-register write, so STAA HI seeds the random generator with $3C. That is why GWAVE starts with random = { high: 0x3c, low: 0 }. The five flags start at zero in the constructor and in reset().

VSNDRM1.SRC 182–189

            
GWAVE 2770–2788, 2824–2832

            

BRA * loops until an interrupt. idle() holds the DAC level and yields 1,024 cycles at a time.

VSNDRM1.SRC 190

            
GWAVE 2868–2871

            

An interrupt abandons whatever the CPU was doing: the IRQ handler resets the stack and never returns. startInterrupt() and nmi() do the same by replacing the running generator.

VSNDRM1.SRC 1155–1162

            
GWAVE 2805–2817

            

Interrupt: reading a command

IRQ · ADDX · JMPTBL

A command from the game raises an interrupt. The handler decodes the 5-bit number and dispatches: 1–13 to GWAVE, 14–28 through a jump table, 29–31 to VARI. When the sound ends it falls through to the background sounds or idles.

19 cycles pass before the command is read: the interrupt entry (12), LDS (3) and LDAA SOUND+2 (4). A command sent in that window only replaces the latch (interruptMask "masked"). During CLI's 2 cycles a new command is held as pending and restarts the handler. The game sends the number inverted and COMA turns it back, so GWAVE's send() takes the plain number and keeps 5 bits.

VSNDRM1.SRC 909–913

            
GWAVE 2790–2798, 2902–2916

            

A set organ flag means the command belongs to an organ sequence. Negative ($FF, set by ORGANT) means the number picks a tune. Positive (set by ORGANN) means it is one of the three numbers that give the oscillator mask and the note.

VSNDRM1.SRC 914–919

            
GWAVE 2917–2926

            

Any command other than 14 resets the spinner step, and any other than 18 clears the bonus flag. Repeating 14 or 18 therefore continues the sound instead of restarting it.

VSNDRM1.SRC 920–926

            
GWAVE 2927–2936

            

The speech check (LDAB TALK, CMPB #$7E) costs 10 cycles and never finds the JMP opcode, because Defender has no speech ROM. Command 0 goes straight to IRQ3.

VSNDRM1.SRC 927–935

            
GWAVE 2937–2938

            

Commands 1–13 load a GWAVE vector and play it. GWAVE adds two options for its own front panel: a loop (the turbine) and a starting frequency offset. A ROM command always starts at offset 0.

VSNDRM1.SRC 936–941

            
GWAVE 2939–2947

            

Commands 14–28 index JMPTBL. The yield is the instruction sum: CMPA and BHI 6, SUBA 2, ASLA 2, LDX 3, BSR 8, ADDX 25 or 31, LDX 0,X 6, JSR 0,X 8. X now holds the routine's own address, kept in this.index.

VSNDRM1.SRC 942–950

            
GWAVE 2948–2952

            

Commands 29–31 load VARI vector 0–2 (SAW, FOSHIT, QUASAR) and play it.

VSNDRM1.SRC 951–953

            
GWAVE 2953–2960

            

After every sound: with a background flag set, clear the bonus flag and restart BG1 or BG2; otherwise BEQ * idles. BG1 runs with whatever X holds, so its length is this.index.

VSNDRM1.SRC 954–962

            
GWAVE 3028–3041

            

ADDX adds A to X through memory. It takes 25 cycles, or 31 when the low byte carries and INC XPLAY runs. indexingCycles() gives that count for a table address and offset.

GWAVE keeps the routine addresses only for a side effect: BG1 and THRUST never load X, so they use their own address as the sample count ($F913 = 63,763 for BG1, $F91C = 63,772 for THRUST).

VSNDRM1.SRC 996–1001

            
GWAVE 2274–2277, 2981–3026

            

GWAVE: loading a sound

GWLD · WVTRAN · TRANS · WVDECA · SVTAB · GWVTAB · GFRTAB

Each GWAVE sound is a 7-byte vector: a waveform, a pattern of periods to play it at, and settings for repeats, echoes, decay and sweep. GWLD copies the waveform into RAM, decays it, and sets up the pattern.

The vectors in command order. decodeGWaveVector() splits the nibbles: echoes and cycles, echo decay and wave number, then pre-decay, sweep step, sweep count, pattern length and pattern offset.

VSNDRM1.SRC 1091–1116

            
GWAVE 2350–2368, 2446–2458

            

GWLD multiplies the vector number by 7, finds the vector with ADDX and unpacks the first two bytes into RAM. GWAVE copies the whole decoded patch into the voice at once, then yields the 72 cycles up to STAA TEMPA plus ADDX.

VSNDRM1.SRC 726–750

            
GWAVE 3054–3066

            

The waveform's address is found by skipping waves one at a time, each length byte plus one. DEC TEMPA is 6 cycles; each skipped wave costs 49 (BMI 4, LDAA 5, INCA 2, JSR 9, ADDX 25, BRA 4).

VSNDRM1.SRC 751–758

            
GWAVE 3067–3074

            

WVTRAN copies the waveform into GWTAB in RAM through TRANS: 43 cycles a byte in the TRANS1 loop, 57 around it. transferWave() copies the samples and returns that count.

The pre-decay is applied once, right after the copy.

The remaining four bytes: sweep step, sweep count, pattern length and pattern offset, which give the pattern's start and end addresses. FOFSET is cleared. GWAVE set these fields at the top of loadGWave() and counts the 128 cycles here.

Each wave byte loses one sixteenth of the original ROM sample per unit of decay. The step comes from the ROM copy, so every decay subtracts the same amount. X ends at the end of the wave, recorded in this.index.

VSNDRM1.SRC 877–905

            
GWAVE 3087–3109

            

Seven waveforms. The first byte of each is its length, which GWAVE takes from samples.length.

VSNDRM1.SRC 1068–1089

            
GWAVE 2281–2315

            

The period patterns, one table with offsets into it. GWAVE keeps the table as bytes and names each pattern with its offset and length. The zeros marked "MATCH THE PROMS" are kept.

VSNDRM1.SRC 1118–1153

            
GWAVE 2317–2348

            

GWAVE: playing

GWAVE · GPLAY · GOUT · GEND

The player steps through the period pattern. For each period it plays the wave in RAM a number of times, waiting the period between samples. Each echo replays the pattern with the wave decayed further.

GECNT counts the echoes. Each echo starts again at the first period, GWFRQ.

VSNDRM1.SRC 785–788

            
GWAVE 3111–3115

            

The next period is the pattern byte plus FOFSET. At FRQEND the echo is over. GCCNT is how many times the wave plays at this period.

VSNDRM1.SRC 789–797

            
GWAVE 3131–3135

            

The inner loop. Wait GPER × 6 cycles (DECA 2, BNE 4), output one wave byte, move to the next. The 13 is LDAA GPER 3, LDAA ,X 5 and STAA SOUND 5; the 12 between samples is INX, CPX and BNE.

VSNDRM1.SRC 798–806

            
GWAVE 3136–3141

            

After a full wave, DECB counts the repeats. Before the next one, INX/DEX pairs and two NOPs add 36 cycles ("SYNC 36"), which with BRA and LDX make the 43-cycle gap.

VSNDRM1.SRC 807–819

            
GWAVE 3142–3146

            

At the end of the pattern the wave is decayed by GECDEC and the pattern plays again until the echoes run out.

VSNDRM1.SRC 820–823

            
GWAVE 3116–3122, 3148–3149

            

A laser-ball bonus stops here after each pass; the next command 18 takes the next sweep step.

VSNDRM1.SRC 824–825

            
GWAVE 3123–3124

            

GWAVE: frequency sweep

GEND50 · GEND60 · GEND61 · GW0–GW3

After the echoes, a sound with a sweep step shifts every period by the step and plays again, for as many steps as GDCNT allows. Periods that would overflow are cut from the pattern.

GDFINC is the step and GDCNT the number of steps. Each step adds GDFINC to FOFSET.

VSNDRM1.SRC 826–831

            
GWAVE 3152–3167

            

GEND61 finds the run of pattern bytes that stay valid after adding FOFSET. Rising: the sum must not carry. Falling (GDFINC negative): the sum must carry and must not be zero. The run becomes the new GWFRQ to FRQEND. If none is valid, the sound ends.

VSNDRM1.SRC 832–855

            
GWAVE 3169–3195

            

With a new range, the wave is copied and pre-decayed again if the echoes decay it, and JMP GWAVE plays the sound again.

VSNDRM1.SRC 856–863

            
GWAVE 3196–3204, 3125

            

Background sounds

BG1 · BG2INC · BG2 · BGEND

Two sounds keep playing after a command finishes: BG1, a quiet filtered noise, and BG2, the turbine, a GWAVE sound that sweeps forever. Commands 15, 16 and 19 switch them.

BG1 sets its flag and runs filtered noise with FMAX 1, no distortion and no decay. X still holds BG1's own address, which becomes the sample count.

VSNDRM1.SRC 336–342

            
GWAVE 2986–2989

            

BG2INC stops BG1 and raises the turbine level BG2FLG from 1 to 29, then back to 1.

VSNDRM1.SRC 664–674

            
GWAVE 3043–3052, 2990–2991

            

BG2 loads the TRBV vector and sets FOFSET to the complement of BG2FLG × 4, so a higher level gives shorter periods and a higher pitch. It enters the sweep code at GEND60, and BG2LP counts GDCNT up so the sweep never runs out.

VSNDRM1.SRC 676–687

            
GWAVE 3036–3039, 3206–3217

            

BGEND clears both flags. The sound playing now ends at the next command, after which the board idles.

VSNDRM1.SRC 657–662

            
GWAVE 2996–3001

            

Laser-ball bonus

BON2

Command 18 plays the BONV sweep one step per command.

The first 18 sets B2FLG and plays BONV. While the flag stays set, each further 18 enters GEND50 to take one more sweep step, which plays once and stops at the B2FLG test.

VSNDRM1.SRC 714–722

            
GWAVE 3219–3234

            

VARI: variable duty-cycle square wave

VARILD · VARI · VVECT

VARI plays a square wave whose low and high halves have separate lengths. Both lengths change step by step, and a 16-bit timer decides how long each step lasts.

Nine-byte vectors: LOPER, HIPER, LODT, HIDT, HIEN, SWPDT (two bytes), LOMOD and VAMP.

VSNDRM1.SRC 1003–1009

            
GWAVE 2370–2376, 2460–2480

            

VARILD multiplies the number by 9 and copies the vector to RAM through TRANS. loadVari() decodes the patch and returns 435 cycles plus ADDX.

VSNDRM1.SRC 192–204

            
GWAVE 3236–3239

            

Output the amplitude VAMP, then load the two half-period counters.

VSNDRM1.SRC 206–213

            
GWAVE 3264–3271

            

Complement SOUND, count LOCNT; complement, count HICNT. X counts SWPDT down through both halves at 14 cycles a count (DEX 4, BEQ 4, DECA 2, BNE 4) and ends the step wherever it reaches zero, even in the middle of a half.

VSNDRM1.SRC 214–227

            
GWAVE 3273–3294

            

VSWEEP leaves the output on the level with bit 7 set: if SOUND is below $80 it is complemented, which costs 2 more cycles.

VSNDRM1.SRC 228–232

            
GWAVE 3295–3298

            

Both half-periods change by LODT and HIDT until HICNT equals HIEN.

VSNDRM1.SRC 233–240

            
GWAVE 3299–3302

            

LOMOD changes LOPER and the whole sweep repeats, until LOPER wraps to 0. With LOMOD 0 the sound ends after one sweep.

VSNDRM1.SRC 241–246

            
GWAVE 3303–3308

            

Spinner

SP1

Command 14 plays the CABSHK VARI sound. Each repeat of the command raises a step that shortens the low half, so the pitch climbs while the game keeps sending 14.

Load CABSHK, VARI vector 3.

VSNDRM1.SRC 689–692

            
GWAVE 3241–3242

            

SP1FLG counts 1 to 31 and wraps. The interrupt handler clears it when any other command arrives.

VSNDRM1.SRC 693–698

            
GWAVE 3243–3248

            

LOPER comes from 32 minus the step: 14 for each count above 20 and 5 for each count from 20 down. spinnerLowPeriod() is the same sum; the yield is the cost of the two loops.

VSNDRM1.SRC 699–710

            
GWAVE 3249–3252, 2482–2488

            

SP1LP plays VARI again and again until the next command.

VSNDRM1.SRC 711–712

            
GWAVE 3256–3262

            

Random bits

HI · LO

The noise routines share a 16-bit shift register in HI and LO. Each routine has its own copy of the shift code; GWAVE has one function.

The new top bit is bit 3 XOR bit 0 of LO. HI and LO shift right together, and the bit that falls out of LO is the random bit (the carry). The function yields before and after the 6-cycle ROR LO, so HI and LO change at their own cycles.

VSNDRM1.SRC 270–277

            
GWAVE 3311–3319

            

FNOISE copies the current output level into B (TAB) and taps its bit 3 instead of LO's. That is the source argument: shiftRandom(cycles, level).

VSNDRM1.SRC 370–377

            
GWAVE 3311, 3379

            

Lightning and appear

LITE · APPEAR · LITEN

Random clicks: each random 1 flips the output, then a delay. After a number of bits the delay changes, which moves the pitch of the crackle.

The two entries only set parameters, which GWAVE stores as patches. LITE: period 1, step +1, 3 bits per period. APPEAR: period $C0, step −2, 16 bits per period.

VSNDRM1.SRC 248–261

            
GWAVE 2624–2630, 2647–2653

            

Store the period, put the output at $FF, set the bit count.

VSNDRM1.SRC 263–268

            
GWAVE 3347–3352

            

For each bit: shift the generator; on a 1, complement SOUND. Then wait LFREQ × 6 cycles.

VSNDRM1.SRC 269–284

            
GWAVE 3353–3362

            

LFREQ moves by DFREQ until it reaches 0. LITE's period grows from 1 to 255, so the crackle falls in pitch.

VSNDRM1.SRC 285–289

            
GWAVE 3363–3366

            

White noise

TURBO · NOISE

Random bits sent straight to the DAC at full or zero level, with an amplitude that decays.

TURBO, the laser: amplitude $FF, decay 1, 32 bits per step, period 1, period growing.

VSNDRM1.SRC 291–299

            
GWAVE 2640–2646

            

Store decay, period, amplitude and bit count.

VSNDRM1.SRC 301–308

            
GWAVE 3321–3325

            

Shift the generator. Output 0 for a 0 bit and NAMP for a 1 bit.

VSNDRM1.SRC 309–320

            
GWAVE 3326–3329

            

Wait NFRQ1 × 8 cycles (DEX 4, BNE 4), then the next bit.

After CYCNT bits the amplitude drops by DECAY; the sound ends when it reaches 0. With NFFLG set the period grows by one each time, so the noise falls in pitch.

VSNDRM1.SRC 326–334

            
GWAVE 3332–3344

            

Filtered noise

THRUST · CANNON · FNOISE

Instead of jumping to each random level, the output slides toward it at a set rate. The slope limits how fast the output can change, which acts as a low-pass filter on the noise.

THRUST: slope 3, no decay, and X (THRUST's own address) as the sample count. CANNON, the explosion: slope $FF, 1,000 samples per stretch, decay and distortion on. BG1 is the same routine with slope 1.

VSNDRM1.SRC 344–358

            
GWAVE 2654–2667, 2609–2615

            

Store the parameters and clear FLO, the fraction of the slope. Each stretch starts from the current output level.

VSNDRM1.SRC 360–369

            
GWAVE 3369–3377

            

The new random LO is the target level. The slope is FMAX, or FMAX AND HI with distortion, which makes the slope random too.

VSNDRM1.SRC 370–382

            
GWAVE 3378–3382

            

Rising: write the level, add the slope (FHI.FLO as a 16-bit step), and stop on overflow or once past the target. X counts the samples of the stretch.

VSNDRM1.SRC 383–394

            
GWAVE 3383–3408

            

Falling: the same with subtraction.

VSNDRM1.SRC 395–402

            
GWAVE 3409–3421

            

Snap to the target level and pick the next one.

VSNDRM1.SRC 403–405

            
GWAVE 3422–3428

            

When the stretch's sample count runs out: with decay on, FMAX.FLO loses one eighth (three shifts, negate, add). The sound ends when FMAX is 0 and FLO is 7; otherwise the next stretch starts.

VSNDRM1.SRC 406–426

            
GWAVE 3429–3442

            

Radio

RADIO · RADSND

A 16-step wavetable read by a phase accumulator whose speed rises each time the phase wraps.

The 16-byte waveform.

VSNDRM1.SRC 1011–1014

            
GWAVE 2378–2380

            

The frequency starts at 100. RADIO never sets the phase itself. GWAVE starts its low byte, B, at $FF (RADIO_PHASE_LOW_AT_ENTRY); the last load into B before RADIO is the interrupt handler's LDAB TALK. The high byte, TEMPA, keeps what the previous sound left, as this.temp.a does.

VSNDRM1.SRC 428–433

            
GWAVE 3447–3451, 2381

            

Add the frequency to the 16-bit phase TEMPA:B. When the phase carries out, the frequency goes up by one; when the frequency wraps to 0 the sound ends. BRA *+2 evens out the two paths.

VSNDRM1.SRC 434–444

            
GWAVE 3452–3466

            

The low 4 bits of TEMPA, the phase's high byte, pick the waveform byte to output.

VSNDRM1.SRC 445–452

            
GWAVE 3467–3470

            

Hyperspace

HYPER

A square wave whose duty cycle steps through 128 phases.

Output 0 and start at phase 0.

VSNDRM1.SRC 454–458

            
GWAVE 3473–3479

            

A time counter runs from 0 to 127 with a delay of 18 counts of DECB/BNE between steps. When it equals the phase, the output flips.

VSNDRM1.SRC 459–467

            
GWAVE 3480–3491

            

At the end of each cycle the output flips again and the phase advances. The sound ends after phase 127.

VSNDRM1.SRC 468–471

            
GWAVE 3492–3498

            

Scream

SCREAM · STABLE

Four echoes, each a frequency and a timer. Each sample adds 128, 64, 32 and 16 for the echoes whose timers are in their upper half. The frequencies fall, and each echo starts the next one partway down.

Clear the table and start the first echo at frequency $40. ECHOS is 4 in the ROM; GWAVE lets its front panel choose 1 to 8.

VSNDRM1.SRC 475–481

            
GWAVE 3501–3508

            

For each echo: add its frequency to its timer; if the timer's bit 7 is set, add the echo's amplitude. Each echo has half the amplitude of the one before.

VSNDRM1.SRC 482–495

            
GWAVE 3509–3526

            

Output the sum. TEMPB counts 256 samples before the frequencies change.

VSNDRM1.SRC 496–498

            
GWAVE 3527–3532

            

Every non-zero frequency drops by 1. When one reaches $37, the next echo starts at $41. The scream ends when all frequencies are 0.

VSNDRM1.SRC 499–514

            
GWAVE 3533–3547

            

Return, with X at the end of the table.

VSNDRM1.SRC 515

            
GWAVE 3548–3549

            

Organ

ORGANT · ORGANN · ORGANL · ORGAN · ORGTAB · NOTTAB

Eight square waves an octave apart, added together. A mask chooses which octaves sound, and a delay built as code in RAM sets the pitch. Command 27 followed by a tune number plays a tune. Command 28 followed by three more commands, the two halves of the oscillator mask and a note number, plays a single note.

The assembler computes each duration from a note time, a tempo and a length. For example TD/PHANC/2*1 is (49096 shifted right once) ÷ 3 ÷ 2 = 4091. GWAVE stores the results. The Phantom's last note is 20,618 ($508A), as in the source; the released Red Label ROM has $508B.

The delay for each note of the scale.

VSNDRM1.SRC 1062–1066

            
GWAVE 2383–2397

            

ORGANT only sets the flag negative. The next command is the tune number.

VSNDRM1.SRC 517–520

            
GWAVE 3016–3019

            

Find the tune: each entry starts with its length, and a length of 0 ends the table. An invalid number returns through IRQ3.

VSNDRM1.SRC 521–535

            
GWAVE 3578–3602

            

For each 4-byte note: the oscillator mask, the delay and the duration go to ORGANL, which builds the delay and plays the note.

VSNDRM1.SRC 536–550

            
GWAVE 3603–3614

            

ORGANN sets the flag to 3 for the three commands that follow.

VSNDRM1.SRC 552–556

            
GWAVE 3020–3024

            

Each of the next two commands, minus 1, is half of the oscillator mask: the mask shifts left 4 bits and the value is added. Then BRA * waits for the next command.

VSNDRM1.SRC 557–567

            
GWAVE 3616–3626, 2873–2876

            

The third command picks the note from NOTTAB (the first note for numbers past the table). The note plays with duration $FFFF, again and again, until the next command.

VSNDRM1.SRC 568–579

            
GWAVE 3627–3640

            

ORGANL writes code into RAM at RDELAY: one NOP (2 cycles) for every 2 counts of delay, a CMPA 0 (3 cycles) for an odd delay, then JMP ORGAN1. The pitch is set by that code's run time, which organDelayCycles() computes; organLoadCycles() is the time ORGANL takes to write it.

VSNDRM1.SRC 581–604

            
GWAVE 2754–2767

            

One sample per pass. TEMPB counts up, so its bit n is a square wave 2ⁿ⁺¹ samples long. The output is 16 × the number of set bits in TEMPB AND OSCIL; popCount() replaces the seven LSRB/ADCA pairs. A pass is 72 cycles plus the delay. LDAB TEMPB is written as bytes ($F6 and an address), the extended form, one cycle longer than the direct form the assembler would choose.

VSNDRM1.SRC 606–639

            
GWAVE 3552–3568

            

Diagnostic

NMI

The diagnostic switch on the board pulls NMI. The ROM checks itself and plays a sound in a loop.

Sum the ROM from $FFFF down to $F801 and compare with the checksum byte at $F800: 16 cycles a byte (ADCB 5, DEX 4, CPX 3, BNE 4) for 2,047 bytes. A bad ROM stops at WAI; GWAVE's ROM is always good.

VSNDRM1.SRC 974–986

            
GWAVE 2964–2973

            

Play FOSHIT (VARI vector 1), check for speech, and start again. SEI keeps commands out until a reset.

VSNDRM1.SRC 987–994

            
GWAVE 2974–2978

            

From DAC to speaker

board hardware

The ROM ends at the DAC. GWAVE also models what happens to the voltage: it averages the DAC level over each audio sample and applies the board's output filter.

integrate() returns the area under that staircase for one audio sample: each DAC value times the cycles it was held. Scheduled commands are applied at their exact cycle along the way.

Sound board

The DAC holds each value until the next write. Its output is a staircase that changes at exact CPU cycles.

GWAVE 2851–2866

            

DacRenderer divides by the cycles per sample (894,886 ÷ the sample rate) to get the average level, then centres it on 128.

Sound board

SOUND ($0400) → PIA port A → MC1408 DAC → TDA2002 amplifier → C14 (800 µF) → 8 Ω speaker

GWAVE 3665–3675

            

The runtime applies that high-pass as a one-pole filter after rendering.

Sound board

C14 and the speaker form a high-pass filter at 1 / (2π × 8 Ω × 800 µF), about 25 Hz.

GWAVE 3677–3681, 3727–3738

            

An AudioWorklet runs the board on the audio thread and posts snapshots to the page for the meters and displays.

Sound board

The board's sound goes to the cabinet speaker.

GWAVE 3792–3808

            

With the CABINET switch on, GWAVE adds a 110 Hz high-pass and a 4.8 kHz low-pass after the board.

Sound board

The cabinet's speaker and enclosure shape the sound further.

GWAVE 4424–4436, 4481–4484