Files
ShoeGaze/docs/plans/1.2-new-pedals.md
T
josh a334a76f7c Add Reverse Delay pedal and ReverseDelay generator
New RT-safe ReverseDelay generator (ShoeGaze): double-buffered segmented
recorder that plays each segment back reversed, ping-ponging record/play
buffers at each boundary with a linear edge-fade to de-click the wrap and
optional feedback for layered reverse trails. Buffers pre-allocated for
maxDelay; delay/feedback read at control rate; segment length changes only
at a boundary.

ReverseDelayPedal wraps it (Time/Feedback), registered with enclosure
color + palette slot. Tests: build/non-silent, feedback-changes-output,
knobs, preset round-trip, registry. Suite 237.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 21:28:45 -07:00

191 lines
10 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 1.2 New Pedals — Plan
Eight pedals targeted for 1.2 (Wah deferred — pending MIDI-control hardware). Grounded against the
Lyrebird generators actually available. Each entry lists the signal path, the generators used,
controls, channel kind, the per-pedal checklist (registry / `PedalType` / enclosure color / palette
order / tests), and effort.
Effort legend: **S** = thin wrapper over existing generators; **M** = composite graph; **L** =
needs a new RT-safe generator first.
Build order recommendation: Flanger → Vibrato → Distortion → Harmonizer → Rotary → Shimmer Reverb →
Reverse Delay → Bitcrusher. (Cheap/whole-cloth-available first; new-generator pedals last.)
---
## 1. Flanger — **S**
Lyrebird already ships `Flanger.Audio(input:delayTime:depth:rate:feedback:mix:sampleRate:maxDelayTime:)`.
Thin wrapper like `ModulationPedal`.
- **Path:** `dry → Flanger.Audio → wet` (base `mix`/`level`/bypass handle blend).
- **Controls (knobs):** Rate (0.05–8 Hz), Depth (0–1), Feedback (0–0.95), Manual/center delay
(0.001–0.01 s, optional). Mix inherited.
- **Channel:** `.processor` (mono). A stereo `.widener` variant (two LFOs anti-phase, like
`ChorusPedal`) is a nice follow-up but not required.
- **Effort:** S.
## 2. Vibrato — **S**
Pitch wobble = a single swept delay line, fully wet (no dry blend). Mirrors `ChorusPedal.voice` but
`initialMix = 1.0` and one voice.
- **Path:** `dry → DelayLine(delay: OscSin(rate, mul: depth, add: base)) → wet`, `mix = 1.0`.
- **Controls:** Rate (0.1–8 Hz), Depth (0.0005–0.006 s). (Expose Depth as "Depth"; keep mix locked
fully wet — vibrato is not a blend effect.)
- **Channel:** `.processor`.
- **Effort:** S. Distinct from Tremolo (amplitude) — document the difference in `summary`.
## 3. Distortion — **S**
Mid-gain clipper between Overdrive (soft) and Fuzz (extreme). Reuse the `Tanh.Audio` drive trick
from `BassOctaverPedal`, plus a tone tilt and output clamp.
- **Path:** `dry → HPF(~80) → Tanh(mul: drive) → tone (RBJLowPass, freq from Tone knob) → Clip(-1,1)
→ wet`. (Optionally `Waveshaper` with a fixed asymmetric table for more character.)
- **Controls:** Drive (1–50), Tone (500–6000 Hz), Level (inherited). Mix default 1.0.
- **Channel:** `.processor`.
- **Effort:** S. Pick clipping flavor at impl: `Tanh` (smooth), `Clip` (hard), or `Fold` (octave-y).
Recommend `Tanh` → `Clip` cascade.
## 4. Harmonizer — **M** (user priority)
Two pitch-shifted harmony voices at **fixed, user-picked interval ratios**, mixed under the dry
signal. Uses `PitchShift.Audio` (granular, real-time, mono, `pitchRatio` clamped 0.25–4.0).
- **Path:**
```
dry ─┬───────────────────────────────── direct·directLevel
├─ PitchShift(pitchRatio: r1) ····· × voice1Level
└─ PitchShift(pitchRatio: r2) ····· × voice2Level → sum
```
- **Interval ratios:** semitone → ratio `2^(n/12)`. Offer a musical set, e.g.
`-12, -7, -5, -3, 0, +3, +4, +5, +7, +12` semitones (octave/5th/4th/3rds). Map each option's
`value` to the ratio at build time.
- **Controls:**
- **Voice 1 Interval** + **Voice 2 Interval** — the "knob pickers" for fixed ratios.
- **Voice 1 Level**, **Voice 2 Level**, **Direct** (dry) level knobs (OC-2-style, like
`BassOctaverPedal`).
- **Picker control (decided):** add a new **`PedalSelectorKnob`** — a knob that snaps to labeled
stops. Reusable for future discrete-knob pedals. Interval stops must include minor- and major-3rd
**above and below**: `-12, -7, -5, -4, -3, 0, +3, +4, +5, +7, +12` semitones (m3 = ±3, M3 = ±4,
P4 = ±5, P5 = ±7, octave = ±12, 0 = unison/off). Each stop's value maps to ratio `2^(n/12)`.
Default voices: Voice 1 = +4 (M3 up), Voice 2 = +7 (P5 up).
- **Channel:** `.processor` (sum to mono). Optional `.widener` (pan the two voices L/R) as a follow-up.
- **Effort:** M. Watch granular latency/CPU with two `PitchShift` instances; verify under the
512-block engine. Consider `windowSize` tuning per voice for smoothness.
## 5. Rotary / Leslie — **M**
Leslie = amplitude modulation (volume throb) + frequency modulation (Doppler pitch wobble) +
stereo spread, with a two-speed (Chorale/Tremolo) ramp.
- **Path (per channel, `.widener`):**
`dry → DelayLine(delay: OscSin(rate, mul: depth, add: base)) → ×(0.5 + 0.5·OscSin(rate, phase))`,
left/right LFOs offset (≈180°) for rotating stereo image. AM and FM share the rotor `rate`.
- **Controls:** Speed switch (Chorale ≈0.8 Hz / Tremolo ≈6.5 Hz) via `PedalSwitch`; **Accel** knob
(ramp time between speeds); **Depth**/**Mix**. Acceleration ramp = a `Lag`/`Decay` on the rate
target so speed changes glide (authentic spin-up/down).
- **Alternative:** `PanAzDistance.Audio` gives real Doppler but outputs 4 channels — would need a
4→2 downmix; the LFO-AM+FM approach above stays stereo and is simpler. Recommend the simple path
for 1.2.
- **Channel:** `.widener`.
- **Effort:** M.
## 6. Shimmer Reverb — **M** (with caveat)
Octave-up sparkle over a reverb tail. Built on an existing reverb (`PlateReverb` or `GVerb`) plus
`PitchShift(pitchRatio: 2.0)`.
- **Caveat — no true regeneration:** Lyrebird's per-synth graph is an acyclic DAG, so a real
*regenerating* shimmer feedback loop (tail → pitch-up → back into tail) isn't expressible inside
one pedal. For 1.2 ship the **parallel** approximation:
```
dry ─┬─ Reverb ───────────────── tail
└─ PitchShift(×2) → Reverb → shimmer → blend
```
This gives the shimmer character without infinite regeneration. True regenerative shimmer needs a
bus-feedback structure (cross-block) or a new feedback-capable generator — note as a future item.
- **Controls:** Room/Decay, Shimmer amount (pitch-voice level), Damp, Mix.
- **Channel:** `.widener` (reverbs output stereo — keep L/R).
- **Effort:** M. Confirm which reverb `ReverbPedal` already uses to avoid duplication; pick the other
(or add an algorithm switch).
## 7. Reverse Delay — **L** (needs new generator)
No reverse-capable delay exists in Lyrebird. Add a new RT-safe generator (in ShoeGaze, or upstream
in Lyrebird Delays).
- **New generator `ReverseDelay`:** pre-allocated segment buffer (max length fixed at init, no RT
alloc); record forward into a segment, play it back reversed; segment length = delay time;
optional feedback. Crossfade at segment boundaries to avoid clicks. Follow Lyrebird generator
rules (`GeneratorBase`, `_checkCount`, pre-allocated buffers, no RT alloc/locks).
- **Pedal path:** `dry → ReverseDelay(time, feedback) → wet`.
- **Controls:** Time (0.05–2 s), Feedback (0–0.9), Mix.
- **Channel:** `.processor`.
- **Effort:** L (generator + tests first, then the thin pedal). Run `lyrebird_external_review` on the
new generator for RT safety.
## 8. Bitcrusher / Lo-Fi — **L** (needs new generators)
No decimation/bit-reduction generators exist. Add two small RT-safe generators.
- **New generators:**
- `SampleRateDecimate` — sample-and-hold at a reduced rate (hold last sample for N input samples;
rate or downsample-factor parameter).
- `BitReduce` — quantize amplitude to `2^bits` levels.
(Both trivial per-sample math, pre-allocated state only.)
- **Pedal path:** `dry → SampleRateDecimate(rate) → BitReduce(bits) → (optional RBJLowPass tone) →
wet`.
- **Controls:** Sample Rate / Downsample (knob), Bits (1–16, stepped), Tone, Mix.
- **Channel:** `.processor`.
- **Effort:** L (two generators + tests, then pedal). Consider contributing the generators upstream
to Lyrebird since they're broadly useful.
---
## Cross-cutting checklist (every pedal)
Per `CLAUDE.md` "Adding a new pedal":
1. `Sources/LyrebirdShoeGaze/Pedals/<Name>Pedal.swift` — subclass `Pedal`, override `effect`/
`wideEffect`, `effectKnobs`/`effectSwitches`/`effectSliders`.
2. **`summary`** (mandatory, one line).
3. Register in `PedalRegistry.builtIn["<DisplayName>"]`.
4. Add `PedalType.<name>`.
5. Enclosure color in `PedalView.enclosureColor(for:)`.
6. Add to `PedalPaletteView.preferredOrder` (group with family: gain near Overdrive/Fuzz; modulation
near Chorus/Phaser; pitch near the octavers; delay/reverb near their families).
7. Tests in `Tests/LyrebirdShoeGazeTests/<Name>PedalTests.swift` — builds + non-silent, each param
measurably changes output, knob/switch list assertions, preset round-trip if it has
switches/sliders.
8. Use `PedalType` static members at call sites.
## Shimmer scope (true regenerative) — findings
Investigated the regenerative path. The per-pedal graph is acyclic; the only feedback mechanisms in
Lyrebird are (a) generators that close their own loop internally (`DelayLineFeedback`, the reverbs)
and (b) cross-block bus read/write. Pedals use inherited `input(bus:)` / `output(bus:)` In/Out
nodes, but **no pedal allocates an internal scratch/feedback bus** — there's no precedent or
lifecycle hook for that. A bus-feedback shimmer would mean new pedal infrastructure (allocate +
release an internal feedback bus, ordered Out→In with a one-block delay) — fragile and off-pattern.
**Conclusion:** true regenerative shimmer is best built as a **new closed-loop generator**
(`ShimmerReverb`) that holds a reverb + an in-loop pitch-shift + damped feedback internally, the same
way `DelayLineFeedback` contains its own feedback. That's a substantial RT-safe DSP generator
(pre-allocated buffers, denormal guards, feedback clamp for stability, granular/FFT pitch latency in
the loop) — larger than Reverse Delay or Bitcrush, and needing its own stability tuning + RT review.
**Recommendation:** build Reverse Delay and Bitcrusher first (self-contained), then take
`ShimmerReverb` as its own focused task. If it proves too large for the 1.2 window, ship the
parallel-pitch-into-reverb approximation for 1.2 and schedule the regenerative generator for 1.3.
**Decision pending:** regenerative `ShimmerReverb` now, or parallel approximation for 1.2 + defer.
## Decisions (resolved)
- **Harmonizer picker:** new `PedalSelectorKnob` (stepped knob) with the ±3rd interval set above.
Build the Harmonizer first to evaluate the control.
- **New generators (Reverse Delay, Bitcrush):** land in the **ShoeGaze package** (self-contained;
no Lyrebird-release dependency for 1.2).
- **Shimmer:** scope a **true regenerative** version (cross-block bus feedback) rather than the
parallel approximation — larger, may slip 1.2.