Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/AutoWahPedal.swift
T
josh f29ab609bd Add Chorus, Sustainer, Ring Modulator pedals + pedal-info UI
Pedals (each registered, with PedalType static, enclosure color, palette order,
summary, and tests):
- Chorus: true-stereo widener (two anti-phase modulated delay lines), distinct
  from the mono-summed Modulation chorus.
- Sustainer: one-knob compressor (sustain drives threshold/ratio/makeup via
  LinLin) + tone low-pass.
- Ring Modulator: dry × tunable sine carrier.

Pedal-info UI:
- Pedal.summary (open var, overridden by all 21 pedals; mandatory going forward).
- PedalRegistry.summary(for:) for the picker.
- PedalPaletteView rows show the summary as a subtitle.
- PedalView gains an ⓘ button → PedalInfoView sheet showing the description and
  the effect controls (knobs/sliders/switches) with ranges/options — excludes
  the common Mix/Level/bypass.

Tests: per-pedal build/param-change/knob-list; every built-in pedal has a
non-empty summary; info excludes common controls. 183 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 18:05:30 -07:00

124 lines
4.3 KiB
Swift
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.
// AutoWahPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Amplitude-tracked auto-wah pedal built from discrete tracking + filter stages.
///
/// Unlike `MutantPedal` (which wraps the single fused `MuTronIII` generator), this pedal
/// wires the envelope path explicitly: an `AmplitudeFollower` tracks the dry signal level,
/// the envelope is scaled by `sensitivity` and clamped to `[0, 1]`, then mapped through an
/// exponential `LinExp` curve to a cutoff frequency that sweeps a resonant `SVF` bandpass.
/// Louder playing opens the filter — the classic "wah" vowel that follows your picking.
///
/// ## Signal path
/// ```
/// dry → AmplitudeFollower → ×sensitivity → Clip[0,1] → LinExp(freqLo…range) → SVF.bandpass
/// ↑freq
/// ```
///
/// ## Knobs
/// - `sensitivity`: How hard the envelope drives the sweep; higher reaches the top of the range sooner.
/// - `resonance`: Bandpass Q. Higher values sharpen the vowel and add emphasis.
/// - `range`: Upper cutoff in Hz reached at full envelope. Sets the sweep span over `freqLo`.
public final class AutoWahPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Touch-sensitive wah that sweeps a resonant filter from your playing dynamics."
}
// MARK: - Parameters
/// Envelope drive into the cutoff sweep. Higher values open the filter on quieter input.
@UIParam public var sensitivity: Double = 2.0
/// Bandpass resonance (SVF quality factor). Higher values sharpen the wah vowel.
@UIParam public var resonance: Double = 3.0
/// Upper cutoff frequency in Hz at maximum envelope.
@UIParam public var range: Double = 2400.0
// MARK: - Constants
private static let defaultMix: Double = 1.0
/// Cutoff at zero envelope, in Hz. `LinExp` requires a strictly positive lower bound.
private let freqLo: Double = 200.0
/// Envelope-follower attack/release times, in seconds.
private let attackTime: Double = 0.01
private let releaseTime: Double = 0.12
/// Clamp bounds for the scaled envelope before the exponential frequency map.
private let envFloor: Double = 0.0
private let envCeiling: Double = 1.0
// MARK: - Ranges
private let sensitivityRange: ClosedRange<Double> = 0.0 ... 4.0
private let resonanceRange: ClosedRange<Double> = 0.5 ... 8.0
private let rangeRange: ClosedRange<Double> = 500.0 ... 5000.0
// MARK: - Knobs
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Sensitivity", node: $sensitivity, range: sensitivityRange),
PedalKnob(label: "Resonance", node: $resonance, range: resonanceRange),
PedalKnob(label: "Range", node: $range, range: rangeRange),
]
}
// MARK: - Init
public init(inputBus: Int = 0, outputBus: Int = 0) {
super.init(
name: "Auto-Wah",
inputBus: inputBus,
outputBus: outputBus,
initialMix: AutoWahPedal.defaultMix
)
}
// MARK: - Effect
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
// Track the dry signal's amplitude envelope.
let envelope: AmplitudeFollower.Audio = AmplitudeFollower.Audio(
in: dry,
attackTime: attackTime,
releaseTime: releaseTime
)
// Scale by sensitivity and clamp to [0, 1] so the exponential map stays in range
// and the swept cutoff never exceeds `range` (and thus never approaches Nyquist).
let driven: Clip.Audio = Clip.Audio(
envelope * $sensitivity,
lo: envFloor,
hi: envCeiling
)
// Map the clamped envelope to an exponential cutoff sweep from freqLo to range.
let cutoff: LinExp.Audio = LinExp.Audio(
driven,
inLo: envFloor,
inHi: envCeiling,
outLo: freqLo,
outHi: $range
)
// Resonant bandpass swept by the tracked envelope — the wah voice.
let filtered: SVF.Audio = SVF.Audio(
input: dry,
freq: cutoff,
q: $resonance
)
return filtered.bandpass
}
}