pcmout
Plays an emulator core's own sound chip output: the PCM a core's `spec.audio.drain(m)` hands over (interleaved stereo f32 at `spec.audio.rate`) goes into an engine audio stream on a small audio entity that follows the console, placed in the room (spatial) so the sound comes from…
pcmout
Plays an emulator core's own sound chip output: the PCM a core's spec.audio.drain(m) hands over
(interleaved stereo f32 at spec.audio.rate) goes into an engine audio stream on a small audio entity
that follows the console, placed in the room (spatial) so the sound comes from the TV or the handheld.
local Pcm = require("stations.pcmout")
local out = Pcm.new(consoleEntity, { rate = spec.audio.rate, spatial = true, maxDistance = 12 })
-- each frame, after the machine ran:
local buf, frames = spec.audio.drain(machine)
out:push(buf, frames, volume)
out:close() -- when the game stops or the station goes
Rate matching: every push is resampled (linear, continuous across pushes) by a ratio a PI controller
sets from where the stream's queue will stand against its target. At full speed the ratio stays within
1 ± 0.8 % (inaudible) and nothing changes; on a peer that cannot emulate the core's full frame rate the
integral learns the shortfall (50 of 59.185 frames/s settles at 1.18: a little lower pitch instead of gaps),
and after a hitch the burst is absorbed rather than dropped. The ratio is clamped to 0.6–1.6; anything
past the queue's target plus 60 ms is still cut as a last resort. out.ratio / out.drift show it.
Tests: luau /zero/source/neogeo.package/tests/pcmout_tests.luau.
Scoped to this part · feeds back into the world's score.