Files
hyperframes/packages
Vance Ingalls 1b93359330 fix(core): give the chorus and phaser LFOs a phase
`lfo.start()` with no argument puts an OscillatorNode at phase zero at
*attach* time. Offline that is clip-relative — the graph is built at ctx
time 0 and the source starts at 0 — but preview rebuilds the graph
whenever the shape changes, and a seek or a scrub does the same. So a
chorus attached 3.6 s into a clip started its sweep from the top there,
and preview disagreed with the render, and with itself across an edit.

An OscillatorNode's phase cannot be set, and `start(when)` clamps a past
`when` to now. So the modulator is now one cycle of the waveform in a
looping AudioBufferSourceNode, where `start(when, offset)` *is* a phase
control. `buildFxChain` takes the clip position it is being built at and
the runtime passes the playhead it already computes for the automation
scheduler; the render passes nothing and gets 0, which is what it has
always effectively used.

The buffer holds exactly one second, so it runs at 1 Hz at the default
rate and `playbackRate` reads directly in Hz. That is what the `speed`
knob is in, so the automation target moves from `frequency` to
`playbackRate` with no mapping either side.

Two consequences worth naming:

- The phaser's waveform is baked into the buffer, so switching Triangular
  to Sinusoidal is a shape change now — `shapeOf` carries it, the same
  way it already carries a one-pole filter's fixed cutoff. Pushed into
  the running graph it would have been a no-op.
- Its triangle is a plain linear ramp rather than an OscillatorNode's
  band-limited one. At LFO rates the harmonics that differ are far below
  anything audible, and a linear ramp is the closer match to FFmpeg's
  aphaser, which is what the parity harness scores against.

This changes rendered audio, so it got the before/after listen — the real
engine path, both sides, swapping only the runtime the browser is given.
Written up with the numbers in `~/audio-fx-lfo-ab/README.md`: the chorus
differs by 76.5 dB down, the Triangular phaser by 63.7, the Sinusoidal
one by 88.1, and a 440 Hz tone with nothing to mask it by 87.6. Worst
single sample anywhere is 0.00027. Inaudible, as expected — a render
builds at position 0, so only the modulator's generation changed.

The half that motivated the fix cannot be rendered at all, since a render
never builds mid-clip, so it is asserted in tests instead. Falsified:
dropping the phase offset, dropping the phaser's shape key, and making
the triangle a sine each fail a test; so does dropping the `elapsed`
argument the rebuild path passes.

Note for whoever runs this next: `src/generated/audio-fx-runtime-inline.ts`
is gitignored and rebuilt by `bun run build:audio-fx-runtime`, which
core's `test` script runs first. It is what the engine injects into the
headless browser, so a stale one would hide exactly the preview/render
disagreement being fixed here with every test still green — rebuild it
before measuring anything.

core 1725 passing (110 files), engine services 736 passing / 3 skipped.
2026-08-10 15:38:56 -07:00
..
2026-08-03 22:48:00 -07:00
2026-08-03 22:48:00 -07:00
2026-08-03 22:48:00 -07:00
2026-08-03 22:48:00 -07:00
2026-08-03 22:48:00 -07:00
2026-08-03 22:48:00 -07:00