XL1200 Console Audio & Beeper Implementation Plan (sdl_audio.c)
Status: Future / Proposed Design Plan (Tier 1, Priority #2) — Not yet implemented. See
docs/ROADMAP.mdfor overall sequencing anddocs/emulator/peripherals-and-backends.mdfor the current console hardware implementation.
Target Emulator: C11 XL1200 Emulator (emu/)
Reference Sources (local-only developer assets): genera-original/sys.sct/i-sys/{audio.lisp,console.lisp,io-register-definitions.lisp}, docs/hardware-reference/05-xl1200-workstation-peripherals.md, emu/src/console_hw.c
1. Executive Summary & Authentic Hardware Audit
The Symbolics XL1200 workstation does not have a PCM sound card; its console audio is an authentic hardware tone beeper driven through two verified paths in Genera 8.3:
- Merlin-II
VIDEO_CTRLRegister (PMA 0x4402C000,genera-original/sys.sct/i-sys/audio.lisp:43-53,console.lisp:120-121):- Bit
<3>(%merlin-audio-enable/VIDEO_CTRL_AUDIO_ENABLE = 0x08):sys:%beepwrites1, sleepsdurationmicroseconds (cl:sleep), then writes0insideunwind-protect. - Bit
<4>(%merlin-audio-frequency/VIDEO_CTRL_AUDIO_FREQ = 0x10): Selects the hardware oscillator frequency (standard ~880–1000 Hz vs alternate pitch). emu/src/console_hw.calready latchescon->speaker_bit = ((next_ctrl & VIDEO_CTRL_AUDIO_ENABLE) != 0U), but the host SDL3 shell currently ignores it.
- Bit
- SLB Console Commands (
genera-original/sys.sct/i-sys/console.lisp:357-377):(setf console-real-volume)transmits%console-set-volumewith a 6-bit volume value (0..63, mapped viacvt-to-funny-volume) over DUSCC Channel A TX to the Symbolics Console / SLB.(console-beep shared-imach-console)invokeslocal-console-beep(which togglesVIDEO_CTRLor issues an SLB beep command depending on console flavor).- (Note:
console-audio-exists-preturnsNILonshared-imach-console, confirming no DMA PCM playback exists on standard XL1200s.)
This plan wires authentic, click-free SDL3 audio playback to these hardware paths while keeping libivory_core 100% SDL-free, preserving all frozen ABI sizes, and adding clean GUI mute/volume controls plus optional .wav sidecar capture for .y4m video recordings.
2. Core vs. Shell Boundary & ABI Invariants
- Zero Core ABI Changes:
sizeof(IvoryCpu) == 4096U,sizeof(IvoryMem) == 32768U,sizeof(MerlinBoard) == 278528Uremain unchanged (IVORY_CORE_ABI_VERSION == 4U). - Zero SDL Dependencies in
libivory_core:console_hw.crecords audio transitions in a compact lock-free state/event ring insideXl1200Console(reusing existingspeaker_bit+ adding atomicaudio_ctrl_bits,audio_volume_6b, and a tiny16-slot event timestamp ring if room exists insideXl1200Consolewithout growingMerlinBoard, or passing an optionalXl1200AudioCallbackpointer inconsole_hw.cfollowing the exactXl1200SerialCallbackspattern!).- Recommended approach: Use an optional
Xl1200AudioCallback(void (*on_audio_change)(void *ctx, uint64_t guest_us, bool enabled, bool freq_hi, uint8_t slb_vol)) registered from the host shell — zero bytes added toMerlinBoardif stored in a host-side struct or reusing an existing padding slot, and zero hot-path overhead becauseVIDEO_CTRLwrites are rare.
- Recommended approach: Use an optional
SDL_DECOUPLEDPreserved:sdl_audio.c(or audio hooks insdl_console.c) depends only on SDL3 andivory_emu.h, with zeromicroui/ui_workbenchdependencies.
flowchart LR
GUEST["Genera 8.3<br/>(sys:%beep / tv:beep / setf volume)"] -->|"Write 0x4402C000 <3:4><br/>or SLB TX cmd"| CHW["console_hw.c (Core)<br/>Latch enable, freq_hi, slb_vol<br/>Emit timestamped transition"]
CHW -->|"SPSC Ring (atomic)"| AUD["sdl_audio.c (Host Shell)<br/>SDL_OpenAudioDeviceStream (48 kHz S16)<br/>Oscillator + 2 ms Cosine Envelope"]
AUD --> SPK["Host Audio Device<br/>(PulseAudio / PipeWire / WASAPI)"]
AUD -.->|"Optional when recording .y4m"| WAV["Synchronized .wav Sidecar<br/>(Virtual-Clock Sample Accounting)"]3. Technical Design
3.1 Tone Synthesis & Click-Free Envelope (emu/src/sdl_audio.c)
- Output Format:
SDL_AUDIO_S16,48000 Hz, mono (1channel) opened lazily viaSDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, audio_cb, ctx)when not--headlessand not--no-audio. - Oscillator: Band-limited or soft-clipped square/triangle wave (classic Lisp Machine console chime character, without harsh aliasing):
freq_hi == 0:880 Hz(default XL1200 beep tone).freq_hi == 1:1320 Hz(alternateVIDEO_CTRL<4>pitch).
- 2 ms Raised-Cosine Attack/Release Envelope: Smoothly ramps gain
0.0 → target_gainon enable andtarget_gain → 0.0on disable, eliminating speaker pops on shorttv:beeppulses. - Volume Scaling:
effective_gain = muted ? 0.0f : (host_volume_0_100 / 100.0f) * (slb_vol_6b / 63.0f) * 0.25f(capped at-12 dBFSpeak so beeps are pleasant and never clip). - Pause / Power-Off / Underrun Safety:
- Whenever
con->cpu_paused || dbg->powered_off || cpu->halted, the audio callback ramps immediately to0.0so pausing mid-beep never latches a stuck continuous tone! - If no audio device exists (e.g., headless CI, Wine without sound, or
SDL_AUDIODRIVER=dummy),sdl_audio_init()logs a non-fatal notice and silently disables playback without affecting emulator startup.
- Whenever
3.2 Controls, Configuration & CLI
- CLI:
--no-audio— disables SDL3 audio initialization.--audio-volume <0..100>— sets initial host speaker volume (default60).
- Scheme Config (
(define-machine ...))::audio #t | #f(default#t),:audio-volume 60.
- Workbench UI (
emu/src/ui_workbench.c):Viewmenu:Mute Console Audiotoggle (with*checkmark).Machine Setup→Firmware & Memory(orView): Host Volume slider/presets (Mute/25%/60%/100%) +Test Beepbutton.
- Debug IPC (
emu/src/debug_ctl.c):audio [on|off|mute|unmute|volume <0..100>|status]
3.3 Optional Video Recording Audio Sidecar (.wav)
- When
.y4mrecording is active (Xl1200VideoRec), optionally write a companion<base>.wav(48 kHz16-bit PCM) driven by the guest virtual microsecond clock (cur_clock_us) so audio stays frame-exact with the.y4mvirtual FPS even if the host pauses or runs faster/slower than real time! - Show the combined
ffmpeg -i out.y4m -i out.wav -c:v libx264 -c:a aac out.mp4hint in theVideo Recordingworkbench window when audio sidecar is enabled.
4. Phased Implementation & Verification Gates
| Phase | Deliverables | Verification & Gate Criteria |
|---|---|---|
| Phase 1: Core Event Hook & SDL3 Beep Synth | Add SPSC audio transition ring / callback in console_hw.c; implement emu/src/sdl_audio.c (SDL_OpenAudioDeviceStream, 880/1320 Hz oscillator, 2 ms ramp, pause/halt silence); wire --no-audio & --audio-volume in main.c. | emu/tests/test_console.c: verify VIDEO_CTRL <3:4> transitions push accurate timestamps, pause/halt forces zero amplitude, and SDL_AUDIODRIVER=dummy succeeds cleanly on Linux & Wine. |
| Phase 2: SLB Volume, Config & Workbench UI | Decode SLB %console-set-volume in console_hw.c; add :audio / :audio-volume in emu_script.c; add View -> Mute Console Audio, volume control, and debug_ctl audio command. | test_s7_config round-trip, test_ui_workbench mute toggle, and live Genera (sys:%beep 1000 150000) + (tv:beep) audio playback test. |
Phase 3 (Optional): .y4m Synchronized .wav Sidecar | Virtual-clock PCM sample generator synced to video_rec_start/maybe_capture/stop + checkbox in Video Recording window. | Unit test verifying .wav RIFF/WAVE header & exact sample count matching frames_written / fps * 48000. |
5. File Impact Summary
| File | Action | Purpose |
|---|---|---|
emu/include/ivory_emu.h, emu/src/console_hw.c | Edit | Timestamped VIDEO_CTRL<3:4> + SLB volume audio transition hook (zero MerlinBoard growth) |
emu/include/ivory_audio.h, emu/src/sdl_audio.c | New | SDL3 audio stream synthesizer, envelope, pause/mute gating, optional .wav writer |
emu/src/main.c, emu/src/emu_script.c, emu/src/debug_ctl.c | Edit | --no-audio / --audio-volume, :audio config persistence, audio IPC command |
emu/src/ui_workbench.c | Edit | View -> Mute Console Audio, volume presets, optional .wav sidecar toggle |
emu/tests/test_console.c, test_s7_config.c, emu/Makefile | Edit | Audio ring/synth unit tests & build wiring (SHELL_SRCS) |
- Signetics SCN68562 / SCN26562 —
signetics_1991_IC019_data_comm_SCN68562.pdf(mirror)