class

Swanium::Core::Apu

Inherits Reference < Object

Deterministic WonderSwan sound unit. It produces interleaved signed 16-bit stereo PCM at 24 kHz from the 3.072 MHz machine clock.

Constants

CYCLES_PER_SAMPLE = 128_u32
MASTER_CLOCK = 3072000_u32
MIX_SCALE = 32
OUTPUT_SAMPLE_RATE = 24000_u32

Constructors

Instance methods

drain_samples

Transfers the completed PCM buffer to the audio backend and starts a fresh producer buffer. This makes consuming audio a single operation instead of relying on callers to remember a separate clear step.

Source
load_state(io : IO) : Nil
Source
read_output_port(port : UInt8, ports : Bytes) : UInt8

CPU-visible digital mixer registers 0x96--0x9B are derived from the current oscillator state; they are not ordinary writable latches.

Source
reset
Source
reset_noise_lfsr(ports : Bytes) : Nil
Source
samples_snapshot

Returns a copy for inspection without exposing the APU's producer buffer to callers.

Source
save_state(io : IO) : Nil
Source
tick(cycles : UInt32, wram : Bytes, ports : Bytes, color_hardware : Bool = false, color_rendering_enabled : Bool = color_hardware) : Nil
Source
write_voice(sample : UInt8) : Nil

Channel 2 voice mode streams signed PCM through port 0x89. Games such as Last Alive alternate two streams at roughly twice the audio rate; the hardware's analog stage averages adjacent writes. Feeding this at write time (rather than sampling the port once per audio frame) removes the characteristic harsh multiplex buzz.

Source