Construct OfflineAudioContext with its required render parameters - #5813
Open
lukemelia wants to merge 1 commit into
Open
Construct OfflineAudioContext with its required render parameters#5813lukemelia wants to merge 1 commit into
lukemelia wants to merge 1 commit into
Conversation
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
force-pushed
the
cs-12550-flacoggm4a-waveform-extraction-always-fails
branch
from
August 18, 2026 20:58
3979831 to
d7f84e2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
The audio waveform decoder picks its constructor via
OfflineAudioContext ?? AudioContext ?? webkitAudioContextand previously invoked it with zero arguments.OfflineAudioContextrequires its render parameters (numberOfChannels,length,sampleRate) — onlyAudioContexttolerates a zero-arg construction — and every environment this code runs in (headless Chrome in the prerender/indexing pass, all real browsers) hasOfflineAudioContext, so the chain always selected the one constructor that cannot be zero-arg constructed. The throw was caught and persisted asdecodeStatus: 'failed', so every FLAC, Ogg, and M4A file indexed cleanly but rendered "No waveform" with:WAV and MP3 read their envelopes without this decoder (PCM envelope / frame side-info), which is why the most-tested formats masked the gap.
decodeAudioDatais 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).decodeAudioDataresamples decoded audio to the context's rate, so using the header-stated rate keeps the analysis at native resolution.waveformForthreadsbudget.sampleRateHz— which every caller already read from the container header for the budget check — into the extraction.AudioContext/webkitAudioContextfallback (for environments without the offline constructor) still constructs with no arguments, which is that constructor's contract.decodeStatus: 'failed'rather than escaping the extract.Test plan
packages/host/tests/unit/audio-metadata-extractor-test.tsgains a "waveform decode (real Web Audio)" module that drivesextractAudioWaveformthrough 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.Unit | audio metadata extractorsmodule: 93 tests, 198 assertions, passing locally against a full dev stack.Fixes CS-12550.
🤖 Generated with Claude Code