Skip to content

feat(core): the levelling script — "Even Out Levels" - #3180

Merged
vanceingalls merged 647 commits into
mainfrom
wa-20a4-leveller
Aug 13, 2026
Merged

feat(core): the levelling script — "Even Out Levels"#3180
vanceingalls merged 647 commits into
mainfrom
wa-20a4-leveller

Conversation

@vanceingalls

Copy link
Copy Markdown
Collaborator

An adaptive script, the same shape as carve: measure in an OfflineAudioContext, then generate an automation lane. Two things the tests forced, and both matter:

The target is the 80th percentile of the track's own speaking windows, not an absolute level. The first version derived it from the peak, which pulled an already-even track bodily up or down — a volume change wearing a levelling label.

The lane rides a gain node, not the track volume, because VOLUME_RANGE is 0..1 and can only attenuate; levelling has to be able to lift.

It goes in FRONT of a trailing limiter (insertAt, not append). Clean Voice ends in a Peak Ceiling, and appending put up to 12 dB of lift after the ceiling that exists to bound the chain.

🤖 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: feat(core): the levelling script — "Even Out Levels" — #3180

Verdict: LGTM

All three PR-body invariants are enforced in code AND tested with counterfactual assertions that would fail under the old assumption.

Invariant 1: 80th percentile of own speaking windows. sorted[Math.floor(sorted.length * 0.8)] on speaking (which filters out -Infinity silence windows). The test creates a mostly-quiet track (6s at 0.08, 1s burst at 0.8, 5s at 0.08) — the 80th percentile sits at the body level (-25 dB), NOT the burst (-5 dB), so correction at t=3 asserts < 3 dB. Under a peak-based target, the quiet body would get ~17 dB of correction (well over 3). Clean proof.

Invariant 2: Lane rides a gain node, not volume. type: "gain" with target fxAutomationTarget(id, "gain"). VOLUME_RANGE is 0..1 and normaliseEnvelope clamps to that range, so a volume lane literally cannot express a value > 1 (unity) — lifts are impossible. The gain effect's range is -60..+12 dB, and MAX_LIFT_DB = 12 matches the effect's ceiling exactly. The test verifies node.type === "gain" and the lane target format.

Invariant 3: Insert FRONT of trailing limiter. chain.nodes[chain.nodes.length - 1]?.type === "limiter" → insert at length - 1. The test applies voice-clean (ending in "Peak Ceiling" limiter), runs the leveller, and asserts types[N-1] === "limiter" and types[N-2] === "gain". The !existing guard on re-run uses replace-in-place (preserving position), not the insert path. Correct.

Idempotence via fromLeveller replace-in-place: reuses the existing node's id so the lane target remains valid across re-runs. The map chain.nodes.map(n => n.fromLeveller ? node : n) guarantees exactly one. Round-trip test verifies fromLeveller persists through serialize/parse.

Edge cases covered: silent/empty tracks return [] immediately, all-silence (no finite windows) filters to empty speaking, room tone below FLOOR_BELOW_PEAK_DB = 42 is excluded from correction, already-even tracks return [] with "Already even" summary.

One observation (non-blocking): at strength = 0, minimum correction is 25% (levellerProfile(0).correction = 0.25). "Leave it alone" still corrects a quarter of the difference. This is intentional (the gentlest setting should still be perceptible) and the test asserts > 0 at strength 0, so it's by design.

No blocking issues. Consistent with the carve pattern and the design record from #3176.


Review by Miga

🤖 Generated with Claude Code

TimelineLanes.tsx hit 620 lines. Extracted the three per-clip pointer
gestures (resize-start, pointer-down move-arm, click/razor-split) into
createClipGestureHandlers — one factory call per rendered clip instead of
~120 lines of inline handler bodies in the render loop. 529 lines now.
# Conflicts:
#	packages/studio/src/player/components/TimelineLanes.tsx
…hreshold

Moving the ~120-line gesture logic into timelineClipGestureHandlers.ts
concentrated it into two functions fallow flagged (onPointerDown at CRAP
63.6, onResizeStart at 31.6). Split the decision logic (which gesture a
pointerdown implies) into a pure resolvePointerDownAction, then split
its own intent-blocking check into isIntentBlocked. onResizeStart's guard
moved into canStartResize. Every function now scores under 30.
vanceingalls and others added 25 commits August 13, 2026 01:37
* 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-20a3-tone-module to main August 13, 2026 14:19
@github-actions

Copy link
Copy Markdown

Fallow audit report

Found 9 findings.

Duplication (2)
Severity Rule Location Description
minor fallow/code-duplication packages/core/src/audioCarve.ts:661 Code clone group 1 (92 lines, 2 instances)
minor fallow/code-duplication packages/core/src/audioLeveller.ts:77 Code clone group 1 (92 lines, 2 instances)
Health (7)
Severity Rule Location Description
major fallow/high-crap-score packages/core/src/audioFx.ts:879 'nodes' has CRAP score 71.3 (threshold: 30.0, cyclomatic 16)
major fallow/high-crap-score packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx:209 'setCarve' has CRAP score 97.0 (threshold: 30.0, cyclomatic 19)
minor fallow/high-crap-score packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx:282 'carvedAgainstBy' has CRAP score 37.1 (threshold: 30.0, cyclomatic 11)
minor fallow/high-crap-score packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx:499 'runLeveller' has CRAP score 31.6 (threshold: 30.0, cyclomatic 10)
critical fallow/high-crap-score packages/studio/src/components/editor/propertyPanelAudioFxGroup.tsx:549 'analyse' has CRAP score 148.4 (threshold: 30.0, cyclomatic 24)
critical fallow/high-crap-score packages/studio/src/components/editor/propertyPanelFxSection.tsx:277 'FxCarveModule' has CRAP score 148.4 (threshold: 30.0, cyclomatic 24)
minor fallow/high-cognitive-complexity packages/studio/src/components/editor/propertyPanelFxSection.tsx:679 'FxSection' has cognitive complexity 19 (threshold: 15)

Generated by fallow.

@vanceingalls
vanceingalls merged commit 71066fc into main Aug 13, 2026
56 of 58 checks passed
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