Skip to content

fix(engine): duck before quantising, chunk the PCM, reschedule on rate change - #3174

Merged
vanceingalls merged 482 commits into
mainfrom
wa-19b-render-fixes
Aug 13, 2026
Merged

fix(engine): duck before quantising, chunk the PCM, reschedule on rate change#3174
vanceingalls merged 482 commits into
mainfrom
wa-19b-render-fixes

Conversation

@vanceingalls

Copy link
Copy Markdown
Collaborator

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

@miga-heygen miga-heygen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 rescheduleElementFxHandle.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

vanceingalls and others added 23 commits August 13, 2026 01:29
* 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
Base automatically changed from wa-19a-audio-fixes to main August 13, 2026 10:48
@github-actions

Copy link
Copy Markdown

Fallow audit report

Found 12 findings.

Duplication (10)
Severity Rule Location Description
minor fallow/code-duplication packages/core/src/runtime/audioFx.test.ts:470 Code clone group 1 (36 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/audioFx.test.ts:545 Code clone group 2 (14 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/audioFx.test.ts:578 Code clone group 2 (14 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/audioFx.test.ts:672 Code clone group 1 (36 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/webAudioTransport.test.ts:169 Code clone group 3 (7 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/webAudioTransport.test.ts:240 Code clone group 3 (7 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/webAudioTransport.test.ts:248 Code clone group 4 (6 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/webAudioTransport.test.ts:329 Code clone group 4 (6 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/webAudioTransport.test.ts:381 Code clone group 5 (6 lines, 2 instances)
minor fallow/code-duplication packages/core/src/runtime/webAudioTransport.test.ts:429 Code clone group 5 (6 lines, 2 instances)
Health (2)
Severity Rule Location Description
minor fallow/high-complexity packages/engine/src/services/audioFxRender.ts:253 'applyAudioFxChain' has cyclomatic complexity 23 (threshold: 20) and cognitive complexity 23 (threshold: 15)
minor fallow/high-crap-score packages/engine/src/services/audioVolumeEnvelope.ts:41 'parseWavLayout' has CRAP score 49.5 (threshold: 30.0, cyclomatic 13)

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>
@vanceingalls
vanceingalls merged commit ea03441 into main Aug 13, 2026
62 of 64 checks passed
@vanceingalls
vanceingalls deleted the wa-19b-render-fixes branch August 13, 2026 12:23
vanceingalls added a commit that referenced this pull request Aug 13, 2026
# Conflicts:
#	plans/audio-automation-lanes/SPEC.md
#	plans/automation-lanes-shared-rows.md
#	plans/automation-time-selection-design.md
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