fix(engine): duck before quantising, chunk the PCM, reschedule on rate change - #3174
Conversation
7a1adbc to
834dcb6
Compare
b1041a0 to
bfca12b
Compare
miga-heygen
left a comment
There was a problem hiding this comment.
Review: fix(engine): duck before quantising, chunk the PCM, reschedule on rate change — #3174
Verdict: LGTM
Three fixes that each change what you hear, and each backed by a test that listens.
Duck before quantising — the architectural change. The volume envelope now travels into applyAudioFxChain and is multiplied onto the float samples the chain produces, BEFORE writeWav quantises them. The old path: FX → clamp ±1 → duck in mixer. A chain at +6 dB into a 0.5 duck: old path clips 1.8 to 1.0 then halves to 0.5 with the tops sheared off; new path ducks 1.8 to 0.9 intact, then writeWav clamps nothing. The return type change from string to { path, envelopeBaked } is breaking but all callers are updated in this PR.
The createEnvelopeWalker extraction from applyVolumeEnvelopeToWav is clean — same O(N+M) cursor walk, same logic, just lifted for reuse. The walker is frame-outer (not plane-outer) because the cursor only advances — restarting per-channel would hand the second one the tail gain for its entire length.
The test is especially thorough: stereo with a step partway through proves (a) the envelope is walked once across all channels, not restarted per plane, (b) the crest factor confirms no clipping distortion (1.35+ vs ≤1.15 for squared-off), and (c) the step landed, so the envelope was sampled over time, not once.
Chunked PCM transfer — 8 MiB chunks, multiple of 4 (Float32 boundary), so chunk boundaries never split a float. Input is stored as arrays of Uint8Array page-side and reassembled before the render, then dropped before the render allocates — so the page doesn't hold two copies at once. Output is read back in the same chunks. The 45s stereo round-trip test with a monotonic ramp catches reordered/duplicated/over-read chunks anywhere in the file.
Rate change reschedule — ElementFxHandle.setRate(rate) rebases the frame at the current playhead and reschedules all params. The frame becomes mutable to prevent elapsed from advancing at the old rate after the change. Three tests: re-aiming, measuring later edits from the new rate, and ignoring invalid rates (0, NaN). The transport's setRate properly calls source.fx?.setRate(safeRate) on each active source.
No issues found.
Review by Miga
🤖 Generated with Claude Code
bfca12b to
5476058
Compare
834dcb6 to
636d181
Compare
5476058 to
2afc5b8
Compare
636d181 to
8de6fe6
Compare
2afc5b8 to
155137b
Compare
8de6fe6 to
db651f1
Compare
155137b to
ccc6566
Compare
db651f1 to
7d740db
Compare
# Conflicts: # packages/core/src/audio/audioFxGraph.ts # packages/core/src/audioFx.ts
* feat(core): carve against every voice over a bed, always dynamically A bed usually runs under a whole sequence — a narrator, an interview answer, a second presenter — and carving against one of them left the others fighting it. `source` becomes `sources`, and `mixCarveSources` sums every voice onto the BED's clock before anything is measured. That is what keeps one analysis sufficient: the chain is fixed, so there is no per-voice filter to switch between, and bands drawn from all the speech there is with envelopes that rise wherever any of it happens answer the actual question — where and when is speech masking this bed. Summed rather than averaged: two people talking at once mask more than either alone. Audio before the bed starts is dropped rather than folded in at zero, since it plays over nothing and shifting it would put a cut where there is no voice. `dynamic` is gone. A fixed depth thins the bed through every pause, and once both have been heard there is no reason to want it, so every carve follows the speech. Two helpers the panel and the headless script now share instead of each carrying a copy — two definitions of "what does this name suggest" drift, and then the two disagree about which track is the voice: - `classifyAudioName` reads a track's kind from its id and filename together. `unknown` is deliberately common: treating an unrecognised name as "not a voice" would hide the one track somebody needs to pick. - `clipsOverlap` keeps out a voice that never plays while the bed does. An unwritten duration counts as unbounded, not zero — refusing a clip whose length the composition leaves to the media would drop the commonest case there is. Files written before this still load: a single `source` reads as a one-voice list, a stored `dynamic` is ignored, and an absent attribute means the defaults whole. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(core): stop \b from missing underscore-separated names, guard clipsOverlap's negative duration \b treats `_` as a word character, so \bbed\b never matched bed_01, music_bed_loop, or theme_song, and \bvo\b/\bvox\b/\btts\b had the same gap — an underscore-separated bed classified as "unknown" and could end up offered as its own carve source. Replaced the short hints with a boundary that actually excludes letters and digits on both sides. clipsOverlap computed end = start + duration without guarding sign, so a negative duration put end before start — an interval that does not describe anything, and one specific case showed it silently dropping a real overlap (a shorter, earlier broken end rejected a clip that genuinely contained the point). Duration clamps to zero instead: a clip cannot un-play time, and a zero-length clip at its start is the sane reading of "duration nobody wrote down as positive." Review by Miga (PR #3212). --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
#3212 (accidentally squash-merged into this branch instead of main) changed HfCarveSettings from a single `source` + `dynamic` toggle to a `sources` list with dynamic mode removed outright — the multi-voice UI consumer that goes with that shape lands in the very next PR, so this branch was left with a type that no longer matched its own code. Minimal port, not the multi-voice redesign that PR does properly: the "Listen to" picker and analyse() treat sources[0] as the one voice this UI still understands, and every dynamic-mode branch (the automated envelope lanes, the toggle, the checkbox) is gone along with the field — a carve is now always the static value the analysis computes, matching what the type change made permanent. Test suite trimmed the same way: the automation-lane and toggle tests covered behavior that no longer exists.
# Conflicts: # packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx # packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx # packages/studio/src/components/editor/propertyPanelFxSection.tsx
# Conflicts: # packages/studio/src/components/editor/propertyPanelAudioFxGroup.test.tsx # packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx # packages/studio/src/components/editor/propertyPanelFxSection.tsx # skills-manifest.json # skills/hyperframes-audio/SKILL.md # skills/hyperframes-audio/references/attributes.md # skills/hyperframes-audio/scripts/carve.mjs
Fallow audit reportFound 12 findings. Duplication (10)
Health (2)
Generated by fallow. |
The "render command explicit composition" test drives the full render.js command handler, which takes the plan-based execute.ts path instead of the renderLocal path the other tests in this file exercise. That path calls ensureBrowser directly, bypassing the mocked preflight.js, and performs a real network install of chrome-headless-shell into the shared ~/.cache/hyperframes/chrome cache as a side effect of running the test suite. In CI this raced with the engine's audioFxRender browser tests running in a parallel worker against the same HOME, producing an intermittent EACCES on the partially-installed binary. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
# Conflicts: # plans/audio-automation-lanes/SPEC.md # plans/automation-lanes-shared-rows.md # plans/automation-time-selection-design.md
The three fixes in the old #3156 that change what you hear.
The FX output is ducked before it is quantised, not after. The old order clipped the chain's output to ±1 and then applied the volume lane, so a hot chain lost everything above full scale before the duck brought it back down. Measured on real narration: the level-matched difference is audible distortion, not rounding.
FX automation reschedules when the transport changes rate. Lanes are committed to absolute context times, so a lowpass sweeping over ten clip-seconds kept its wall-clock plan while the audio underneath ran at 2×.
A track's PCM crosses the wire in bounded chunks — a long track was ~184 MB in a single
page.evaluate.🤖 Generated with Claude Code