Skip to content

Construct OfflineAudioContext with its required render parameters - #5813

Open
lukemelia wants to merge 1 commit into
mainfrom
cs-12550-flacoggm4a-waveform-extraction-always-fails
Open

Construct OfflineAudioContext with its required render parameters#5813
lukemelia wants to merge 1 commit into
mainfrom
cs-12550-flacoggm4a-waveform-extraction-always-fails

Conversation

@lukemelia

Copy link
Copy Markdown
Contributor

What this does

The audio waveform decoder picks its constructor via OfflineAudioContext ?? AudioContext ?? webkitAudioContext and previously invoked it with zero arguments. OfflineAudioContext requires its render parameters (numberOfChannels, length, sampleRate) — only AudioContext tolerates a zero-arg construction — and every environment this code runs in (headless Chrome in the prerender/indexing pass, all real browsers) has OfflineAudioContext, so the chain always selected the one constructor that cannot be zero-arg constructed. The throw was caught and persisted as decodeStatus: 'failed', so every FLAC, Ogg, and M4A file indexed cleanly but rendered "No waveform" with:

Failed to construct 'OfflineAudioContext': 1 argument required, but only 0 present.

WAV and MP3 read their envelopes without this decoder (PCM envelope / frame side-info), which is why the most-tested formats masked the gap.

  • The offline context is built with minimal render parameters — the render graph never runs; only decodeAudioData is used — and the sample rate the container header stated, clamped to the Web Audio-mandated [8000, 96000] band (FLAC admits rates up to 655350 Hz). decodeAudioData resamples decoded audio to the context's rate, so using the header-stated rate keeps the analysis at native resolution.
  • waveformFor threads budget.sampleRateHz — which every caller already read from the container header for the budget check — into the extraction.
  • The live AudioContext/webkitAudioContext fallback (for environments without the offline constructor) still constructs with no arguments, which is that constructor's contract.
  • Construction now happens inside the try/catch, so an unexpected constructor rejection still records an honest decodeStatus: 'failed' rather than escaping the extract.

Test plan

  • packages/host/tests/unit/audio-metadata-extractor-test.ts gains a "waveform decode (real Web Audio)" module that drives extractAudioWaveform through the environment's real Web Audio implementation with generated 16-bit PCM WAV bytes — pinning the constructor contract that the existing structural-fake tests cannot. Asserts a successful decode, the expected duration and bar count, an envelope that tracks the signal shape, and that a header-stated rate outside the supported band (FLAC's 655350 Hz ceiling) clamps and decodes rather than failing.
  • Full Unit | audio metadata extractors module: 93 tests, 198 assertions, passing locally against a full dev stack.
  • Host typecheck clean.

Fixes CS-12550.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

Preview deployments

The waveform decoder picked its constructor via OfflineAudioContext ??
AudioContext ?? webkitAudioContext and then called it with zero
arguments — but OfflineAudioContext requires (numberOfChannels, length,
sampleRate). Every environment this code runs in has
OfflineAudioContext, so the FLAC/Ogg/M4A decode path always threw
"Failed to construct 'OfflineAudioContext': 1 argument required" and
every such file persisted decodeStatus 'failed' and rendered
"No waveform". WAV and MP3 read their envelopes without this decoder,
which masked the gap.

The context is now built with minimal render parameters — the graph
never runs; only decodeAudioData is used — and the sample rate the
container header stated, clamped to the Web Audio-mandated band, so
the decode isn't resampled before analysis. New tests drive
extractAudioWaveform through the environment's real Web Audio
implementation with generated PCM WAV bytes, pinning the constructor
contract a structural fake can't.

Fixes CS-12550.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lukemelia
lukemelia force-pushed the cs-12550-flacoggm4a-waveform-extraction-always-fails branch from 3979831 to d7f84e2 Compare August 18, 2026 20:58
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.

1 participant