Skip to content

feat(core): support PCM through the shared audio stream interface - #1481

Open
opencode-agent[bot] wants to merge 3 commits into
mainfrom
adjust-pcm-1480
Open

feat(core): support PCM through the shared audio stream interface#1481
opencode-agent[bot] wants to merge 3 commits into
mainfrom
adjust-pcm-1480

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Add PCM as a format of the existing audio stream interface, from TypeScript through the native ABI. This is an updated version of #1480 on an upstream branch because the bot cannot push to the original fork branch.

const stream = await audio.playStream(source, {
  format: "pcm",
  sampleFormat: "f32le",
  sampleRate: 44100,
  channels: 2,
})
await stream.closed
  • One native audioCreateStream / audioWriteStream / audioEndStream contract. Creation takes the format plus its input rate/channels; writes accept and return byte counts. The native export file is unchanged from main.
  • TypeScript uses the same source pump, backpressure, readiness, controls, cancellation, and completion for PCM, MP3, and FLAC. No PCM-specific stream class, native method family, sample conversion loop, or additional worker.
  • Native PCM ingestion handles unaligned little-endian input, partial frames, and finite-sample validation in bounded batches. Miniaudio converts directly into the existing stereo mixer ring.
  • Remove unused pause/clear controls, sound reconstruction, and duplicated PCM counters. Preserve the EOF-tail fix so fractional downsampling latency cannot discard short audio.
  • Update the byte-contract/ABI, fragmentation, ownership, cancellation, fairness, resampling, and EOF regressions, plus docs and the generated-tone example. PCM reconnect remains explicitly unsupported.

Validation status

  • Native PCM tests: 8 passed; broader native stream tests: 41 passed.
  • Shared FFI/ABI tests: 26 passed. Typecheck, formatting, lint, documentation validation, and independent code review passed.
  • Full native suite: 2,164 passed, 8 skipped, one existing X11 socket-directory failure, previously reproduced on the original PR head. Clipboard source is unchanged.
  • The local ReleaseFast rebuild is still compiling. Bun/Node runtime revalidation and packed-distribution checks against the rebuilt library are pending. Earlier runtime attempts loaded the stale pre-refactor library and are not valid results for this revision; no full-runtime pass is claimed yet.

Requested by: @neriousy (Filip via Slack); simplification requested by @kommander (Sebastian via Slack)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants