8000 fix(fx): synth-voice ADSR envelope — kill fit-to-region stretching by johannboehme · Pull Request #23 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

fix(fx): synth-voice ADSR envelope — kill fit-to-region stretching - #23

Merged
johannboehme merged 2 commits into
mainfrom
claude/confident-allen-3cffe3
May 2, 2026
Merged

johannboehme merged 2 commits into
mainfrom
claude/confident-allen-3cffe3

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

Fixes two bugs in the P-FX ADSR envelope (frontend/src/editor/fx/envelope.ts) where attack didn't behave like a real synth voice.

1. Live-hold bug (commit a1aec2d): While the user held a pad, tickFxHold kept outS = playhead + overshoot so the active-resolver's exclusive-end check stayed true. The envelope's holding=true branch then rescaled A and D against this moving regionDurS, dynamically squeezing attack onto the elapsed time → localT/A returned ~1 within the first frame regardless of slider. Vignette (and every other P-FX) appeared to have no attack ramp on live recording.

2. Quick-tap bug (commit cb2df2d): Non-holding fit-to-region rescaled A+D to fit regionDur - R, so a brief tap with high attack would complete the attack inside the held window and release from peak. A real synth freezes attack mid-ramp on key-up and fades from the partial amplitude.

Changes

  • Removed the fit-to-region rescaling in both branches.
  • Release now samples the natural envelope at regionDurS - R and fades from that amplitude — synth-voice semantics.
  • A, D, R always reflect the user's slider exactly.
  • Sub-R sliver (regionDur < R with A > 0, only reachable via manual trim) renders silent — synth analogue: tapped too briefly to make any sound.

Affects all P-FX (Vign, Wear, RGB, Zoom, UV, Echo, Tape) since they share envelopeAt.

Test plan

  • npx vitest run --project=unit src/editor/fx/envelope.test.ts — 22/22 passing (rewrote 2 tests that pinned old fit-to-region behavior, added 4 new for synth-voice semantics + holding repro)
  • npx vitest run --project=unit src/editor/ — 553/553 passing, no regressions
  • Smoketest in dev: Vignette FX, attack at max, hold pad → effect fades in over full attack time
  • Manual: brief tap with high attack → effect peaks at partial amplitude, releases from there (no swell-to-peak)
  • Manual: regression check on other P-FX (Wear/RGB/Zoom/UV/Echo/Tape) with non-trivial envelopes

🤖 Generated with Claude Code

johannboehme and others added 2 commits May 3, 2026 00:20
…ed during live hold

While the user holds an FX pad, tickFxHold keeps outS at
playhead+overshoot so the active-resolver's exclusive-end check
stays true. The envelope's holding branch then rescaled A and D
against this moving regionDurS, dynamically squeezing attack onto
the elapsed time — so localT/A returned ~1 within the first frame
regardless of slider. Vignette (and every other P-FX) appeared to
have no attack ramp at all on live recording.

Removed the rescaling inside `if (holding) { ... }`; the existing
phase logic at the bottom already handles attack/decay/sustain
correctly when A and D are left raw (release is short-circuited
out by the `if (holding) return S` guard). Non-holding fit-to-
region path is unchanged — that's the intended "release is the
protected slot" behavior pinned by the existing test suite.

Added a `holding` describe block in envelope.test.ts covering the
Vignette repro (A=2.0, regionDurS≈localT+overshoot), normal decay
during hold, sustain-after-A+D, no release while held, and no
zero-out at/past outS while held.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…attack amplitude

Quick tap with a high attack value used to swell the effect to full
peak and only then release. A real synth voice freezes attack mid-
ramp on key-up and fades from whatever partial amplitude was reached.
Old fit-to-region rescaling forced A+D into `regionDur - R`, so the
attack always completed within the held window — wrong.

Removed the fit-to-region scaling entirely (both holding-branch was
already gone, now non-holding too). Release now samples the natural
envelope at `regionDurS - R` and fades from that amplitude to 0 over
R. Sub-R sliver (regionDurS < R, only reachable via manual trim with
A>0) renders silent — the synth-correct answer.

Tests:
- Rewrote `compresses A+D to fit (region - R)` → now asserts synth-
  voice partial-attack release (50ms held + R=200ms, A=100ms peaks
  at 0.5, releases from there).
- Rewrote `clamps R alone when even R exceeds the region` → now
  asserts silent for sub-R sliver with A>0.
- Added boundary case: A=0 sub-R sliver still plays (sustain fades
  down across the available time).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@johannboehme
johannboehme merged commit 8918137 into main May 2, 2026
1 check passed
@johannboehme
johannboehme deleted the claude/confident-allen-3cffe3 branch May 2, 2026 22:47
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

0