Add Harmonizer pedal and a stepped selector-knob control

Harmonizer: two granular PitchShift voices at fixed musical intervals
(ratio 2^(semitones/12) via Exp), mixed under the dry signal with V1/V2/
Direct level knobs. Two interval "knob pickers" snap through octave,
fifth, fourth, and minor/major third and sixth above and below.

New reusable control:
- PedalSelectorKnob (model) + PedalSelectorKnobView (rotary knob that snaps
  to labelled stops; drag up/down to step, shows the stop caption).
- Pedal.effectSelectors hook; PedalView renders a selector row.
- PedalState.selectorValues for preset round-trip (forward-compatible).

Registered + PedalType.harmonizer + enclosure color + palette slot.
Tests: build/non-silent, interval-change-changes-output, selector preset
round-trip, registry. Full suite 213 passing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-27 20:50:22 -07:00
parent f0b30379c7
commit eafc68d283
12 changed files with 703 additions and 2 deletions
+170
View File
@@ -0,0 +1,170 @@
# 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.
## 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.