XL1200-EMU Symbolics XL1200 Emulator
Plans & Roadmap SpecsTODO docs/audio-plan.md

XL1200 Console Audio & Beeper Implementation Plan (sdl_audio.c)

Status: Future / Proposed Design Plan (Tier 1, Priority #2) — Not yet implemented. See docs/ROADMAP.md for overall sequencing and docs/emulator/peripherals-and-backends.md for 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:

  1. Merlin-II VIDEO_CTRL Register (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:%beep writes 1, sleeps duration microseconds (cl:sleep), then writes 0 inside unwind-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.c already latches con->speaker_bit = ((next_ctrl & VIDEO_CTRL_AUDIO_ENABLE) != 0U), but the host SDL3 shell currently ignores it.
  2. SLB Console Commands (genera-original/sys.sct/i-sys/console.lisp:357-377):
    • (setf console-real-volume) transmits %console-set-volume with a 6-bit volume value (0..63, mapped via cvt-to-funny-volume) over DUSCC Channel A TX to the Symbolics Console / SLB.
    • (console-beep shared-imach-console) invokes local-console-beep (which toggles VIDEO_CTRL or issues an SLB beep command depending on console flavor).
    • (Note: console-audio-exists-p returns NIL on shared-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) == 278528U remain unchanged (IVORY_CORE_ABI_VERSION == 4U).
  • Zero SDL Dependencies in libivory_core: console_hw.c records audio transitions in a compact lock-free state/event ring inside Xl1200Console (reusing existing speaker_bit + adding atomic audio_ctrl_bits, audio_volume_6b, and a tiny 16-slot event timestamp ring if room exists inside Xl1200Console without growing MerlinBoard, or passing an optional Xl1200AudioCallback pointer in console_hw.c following the exact Xl1200SerialCallbacks pattern!).
    • 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 to MerlinBoard if stored in a host-side struct or reusing an existing padding slot, and zero hot-path overhead because VIDEO_CTRL writes are rare.
  • SDL_DECOUPLED Preserved: sdl_audio.c (or audio hooks in sdl_console.c) depends only on SDL3 and ivory_emu.h, with zero microui / ui_workbench dependencies.
flowchart LR
    GUEST["Genera 8.3<br/>(sys:%beep / tv:beep / setf volume)"] -->|"Write 0x4402C000 &lt;3:4&gt;<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 (1 channel) opened lazily via SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, audio_cb, ctx) when not --headless and 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 (alternate VIDEO_CTRL<4> pitch).
  • 2 ms Raised-Cosine Attack/Release Envelope: Smoothly ramps gain 0.0 → target_gain on enable and target_gain → 0.0 on disable, eliminating speaker pops on short tv:beep pulses.
  • Volume Scaling: effective_gain = muted ? 0.0f : (host_volume_0_100 / 100.0f) * (slb_vol_6b / 63.0f) * 0.25f (capped at -12 dBFS peak 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 to 0.0 so 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.

3.2 Controls, Configuration & CLI

  • CLI:
    • --no-audio — disables SDL3 audio initialization.
    • --audio-volume <0..100> — sets initial host speaker volume (default 60).
  • Scheme Config ((define-machine ...)):
    • :audio #t | #f (default #t), :audio-volume 60.
  • Workbench UI (emu/src/ui_workbench.c):
    • View menu: Mute Console Audio toggle (with * checkmark).
    • Machine Setup → Firmware & Memory (or View): Host Volume slider/presets (Mute / 25% / 60% / 100%) + Test Beep button.
  • 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 .y4m recording is active (Xl1200VideoRec), optionally write a companion <base>.wav (48 kHz 16-bit PCM) driven by the guest virtual microsecond clock (cur_clock_us) so audio stays frame-exact with the .y4m virtual 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.mp4 hint in the Video Recording workbench window when audio sidecar is enabled.

4. Phased Implementation & Verification Gates

PhaseDeliverablesVerification & Gate Criteria
Phase 1: Core Event Hook & SDL3 Beep SynthAdd 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 UIDecode 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 SidecarVirtual-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

FileActionPurpose
emu/include/ivory_emu.h, emu/src/console_hw.cEditTimestamped VIDEO_CTRL<3:4> + SLB volume audio transition hook (zero MerlinBoard growth)
emu/include/ivory_audio.h, emu/src/sdl_audio.cNewSDL3 audio stream synthesizer, envelope, pause/mute gating, optional .wav writer
emu/src/main.c, emu/src/emu_script.c, emu/src/debug_ctl.cEdit--no-audio / --audio-volume, :audio config persistence, audio IPC command
emu/src/ui_workbench.cEditView -> Mute Console Audio, volume presets, optional .wav sidecar toggle
emu/tests/test_console.c, test_s7_config.c, emu/MakefileEditAudio ring/synth unit tests & build wiring (SHELL_SRCS)
Related Chip Datasheets (1)All Component Datasheets →