8000 feat(waveform): Ableton-grade hi-res waveforms (Triage + Editor) by johannboehme · Pull Request #59 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

feat(waveform): Ableton-grade hi-res waveforms (Triage + Editor) - #59

Merged
johannboehme merged 4 commits into
mainfrom
claude/waveform-hd
Jun 20, 2026
Merged

johannboehme merged 4 commits into
mainfrom
claude/waveform-hd

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Was & warum

Die Waveforms in Triage und im Editor wirkten beim Reinzoomen niedrig aufgelöst und stark geglättet — schlecht zum Arbeiten im Non-Snap-Modus, weil man Beat-Onsets optisch nicht präzise trifft. Ziel: Ableton-Qualität — scharfe, transienten-genaue Waveform, bei der Zoom echtes Detail freilegt.

Root causes (im Code bestätigt)

  • Zu grobe Quelle. Triage zeichnete eine 10-Hz-RMS-Hüllkurve (ein Wert pro 100 ms); der Editor 4000 feste Buckets über den ganzen Song (~0,9 s/Bucket bei stundenlangen Aufnahmen). Beim Zoomen wurde nur zwischen wenigen Punkten interpoliert.
  • RMS statt Min/Max (Triage) mittelt Transienten weg.
  • 3-Tap-Smoothing in beiden Views verwischt das verbleibende Detail.
  • Retina-Untersampling: die Zeichenschleifen liefen über CSS- statt Geräte-Pixel.

Ansatz

Ein gemeinsamer, transienten-genauer Waveform-Engine für Triage, Editor und SeamStrip.

Neue Module (rein, unit-getestet):

  • local/waveform/peak-pyramid.ts — Multi-Resolution Min/Max-Pyramide aus dem vollen PCM (Basis 64 Samples ≈ 2,9 ms; transienten-erhaltend). Plus pickLevel / bucketRangeForTime / aggregateColumn / rawPcmColumn und ein Hüllkurven-Fallback.
  • local/waveform/draw-waveform.ts — Zeichen-Engine auf Geräte-Pixel-Granularität, ohne Smoothing; gibt das Spalten-Max zurück, damit Triages Silence-Tint an der Silhouette klebt.
  • local/waveform/build-pyramid-async.ts — chunked Build (kein Jank bei stundenlangem PCM).
  • local/waveform/pyramid-cache.ts + neuer IndexedDB-Store — Pyramide wird im Sync-Schritt vorberechnet und persistiert, Triage lädt sie sofort (kein Coarse→Sharp-Pop).

Per-View: Editor normalisiert absolut (Ableton-ehrlich), Triage peak (Lane bleibt gefüllt, Silence-Threshold konsistent). Editor behält seine Per-Arrangement-Segment-Projektion via mapXToTime-Closure; Long-form-Lücken bleiben Lücken. Retired: timeline-waveform.ts und das 4000-Bucket waveform-peaks.ts.

Während des Live-Tests gefundene & gefixte Bugs

  • Flache Waveform beim Reinzoomen — der Store entlädt sein PCM nach dem Load (length 0, aber truthy); der Roh-PCM-Pfad lief auf dem leeren Array und gab pro Spalte {0,0} → flache Linie. Fix: useRaw auf pcm.length > 0 absichern; gebaute Pyramide behalten statt auf die Hüllkurve zurückzufallen.
  • Kollaps bei Extrem-Zoom — bei Sub-Sample-Zoom (min == max) hatte die gefüllte Fläche null Höhe und verschwand. Fix: garantierte Mindesthöhe, die die echten Sample-Werte als dünne Linie nachzeichnet.

Verifikation

  • TDD (Red→Green): 36 neue Unit-Tests für die reinen Funktionen (Transienten-Erhalt, Geräte-Pixel-Anzahl, kein Smoothing, Long-form-Lücken, Normalisierung, Detached-PCM-Fallback, Mindesthöhe).
  • Volle Suite 1125 grün, tsc -b sauber.
  • Live am echten Job: bei Voll-Zoom, ~12 s und ~1,5 s Fenster durchgehend scharfe, transienten-genaue Waveform (nach dem Detached-PCM-Fix).

Hinweise für Review

  • DB-Schema: neuer additiver Store waveform-pyramid; DB_VERSION landete bei 11 (Dev-Iteration). Der Store wird in upgrade angelegt, sobald er fehlt — die exakte Nummer ist egal. Bei Bedarf auf 8→9 umnummerierbar.
  • Die Pyramiden-Persistenz wirkt für neu gesyncte Jobs sofort; Altjobs cachen beim ersten Öffnen nach (abgesichert gegen das Speichern halb-leerer Pyramiden, falls das PCM mid-build detacht).

🤖 Generated with Claude Code

johannboehme and others added 4 commits June 20, 2026 15:32
Replace the coarse, over-smoothed waveform sources with a shared,
transient-accurate engine used by Triage, the Editor and SeamStrip.

Root causes fixed:
- Coarse source data — Triage drew a 10 Hz RMS envelope (100 ms/value);
  the Editor drew 4000 fixed buckets over the whole song (~0.9 s/bucket
  on hour-long recordings). Now both read a multi-resolution min/max peak
  pyramid built off the full PCM (2.9 ms base buckets, transient-preserving).
- RMS averaging — replaced by min/max so beat onsets keep their attack edge.
- 3-tap smoothing — removed; the body is drawn crisp.
- Retina under-sampling — the draw loop now steps DEVICE pixels (one vertex
  per device pixel at x=i/dpr) instead of CSS pixels.

New shared modules (pure, unit-tested):
- local/waveform/peak-pyramid.ts — buildPeakPyramid + pickLevel /
  bucketRangeForTime / aggregateColumn / rawPcmColumn, plus an
  envelope-derived fallback for the cached-open race.
- local/waveform/draw-waveform.ts — device-pixel draw engine; returns the
  per-CSS-column max so Triage's silence tint/dB guides stay locked to the body.
- local/waveform/build-pyramid-async.ts — chunked build so hour-long PCM
  doesn't jank the main thread.

Per-view: Editor normalizes absolute (Ableton-honest), Triage peak (lane
stays filled, silence threshold consistent). Editor keeps its
per-arrangement-segment projection via a mapXToTime closure; long-form gaps
stay gaps. Retired timeline-waveform.ts and the 4000-bucket waveform-peaks.ts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
At sub-sample zoom the raw-PCM path returns min==max per column, so the
filled body had zero height and vanished — only the centre line remained
and the Triage waveform read as a flat stroke. Enforce a minimum body
half-height (expandToMinThickness) so a too-thin column is expanded
symmetrically around its value; the band then traces the real sample
values as a thin line instead of collapsing. No effect at normal zoom
where bodies are far taller than the floor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reported: the Triage waveform went flat as soon as you zoomed in even a
little (fine when zoomed out; reload reproduced it). Root cause, confirmed
live via console: the triage store detaches its PCM buffer a few seconds
after load (BPM re-detection / worker transfer), leaving a length-0 — but
still truthy — Float32Array. The draw engine's raw-PCM path was gated on
`!!pcm`, which stays true for an empty array; zooming in dropped
samples-per-pixel below the bucket size, switched to the raw path, and
rawPcmColumn(empty) returned {0,0} for every column → a flat line.

- Guard useRaw on `pcm.length > 0` so a detached buffer falls back to the
  pyramid instead of producing zeros (regression test added).
- Keep the crisp PCM pyramid once built instead of dropping to the coarse
  10 Hz envelope when `pcm` later empties (Triage + SeamStrip).

Verified live at full / 12 s / 1.5 s zoom: crisp transient-accurate body
at every level.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Triage showed a coarse envelope first and then "snapped" to the high-res
waveform after a while: it rebuilt the pyramid in-memory on every open, and
the chunked build yields to a busy load thread, so the swap-in was visibly
delayed.

Precompute it once where the master PCM is already decoded (jobs.ts, next to
the audio-analysis step) and persist it per job in a new IDB store. Triage now
reads it from cache on open → instant high-res, no coarse→sharp pop.

- New "waveform-pyramid" IDB store (created whenever missing in `upgrade`, so
  it self-heals; additive, no data migration). Accessors on jobsDb.
- pyramid-cache.ts: getCachedPyramid / savePyramid / getOrComputePyramid
  (mirrors the audio-analysis cache; payload carries its own version + sr).
- jobs.ts sync step builds + persists the pyramid (non-blocking, from the
  clean non-detached decode PCM).
- Triage + SeamStrip prefer the cached pyramid; lazy in-memory build is the
  fallback for jobs synced before this existed, and backfills the cache — but
  only when the source PCM survived the whole build (guard against persisting a
  half-zeroed pyramid if the store detaches its buffer mid-build).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@johannboehme
johannboehme merged commit 0de3f45 into main Jun 20, 2026
1 check passed
@johannboehme
johannboehme deleted the claude/waveform-hd branch June 20, 2026 14:49
johannboehme added a commit that referenced this pull request Jun 20, 2026
Resolves the jobs-db.ts conflict: keeps the new ColorGradeRecord /
FilterSlotRecord + VITE_DB_NAME override AND adopts main's DB_VERSION 11
(waveform-pyramid store from #59). Other files auto-merged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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