// WahPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Foot-swept wah pedal — a resonant bandpass whose cutoff follows the expression-pedal position. /// /// Reuses the same filter voice as ``AutoWahPedal`` (a resonant `SVF` bandpass swept through an /// exponential `LinExp` frequency map) but drives the sweep from the `position` knob instead of an /// amplitude follower: `0` = heel (low, dark) → `1` = toe (high, bright). The position is smoothed /// so hand or MIDI sweeps are click-free. /// /// ## Signal path /// ``` /// position → Lag → LinExp(freqLo…freqHi) → SVF.bandpass(q: resonance) /// ↑freq /// ``` /// /// ## Knobs /// - `position`: Sweep position in `[0, 1]`. `0` = low cutoff, `1` = high cutoff. /// - `resonance`: Bandpass Q. Higher values sharpen the wah vowel. public final class WahPedal: Pedal { /// One-line description shown in the picker and info panel. public override var summary: String { "Foot-swept resonant filter — the classic wah voice, driven by pedal position." } // MARK: - Parameters /// Expression-pedal position in `[0, 1]`. `0` = heel (low cutoff), `1` = toe (high cutoff). @UIParam public var position: Double = 0.5 /// Bandpass resonance (SVF quality factor). Higher values sharpen the wah vowel. @UIParam public var resonance: Double = 3.0 // MARK: - Constants private static let defaultMix: Double = 1.0 /// Cutoff at heel (`position == 0`), in Hz. `LinExp` requires a strictly positive lower bound. private let freqLo: Double = 400.0 /// Cutoff at toe (`position == 1`), in Hz. private let freqHi: Double = 2200.0 /// Smoothing time constant in seconds for the position sweep — prevents zipper noise when the /// position jumps (e.g. coarse 0–127 steps from a MIDI expression pedal). private let smoothingTime: Double = 0.02 // MARK: - Ranges private let positionRange: ClosedRange = 0.0 ... 1.0 private let resonanceRange: ClosedRange = 0.5 ... 8.0 // MARK: - Knobs public override var effectKnobs: [PedalKnob] { [ PedalKnob(label: "Position", node: $position, range: positionRange), PedalKnob(label: "Resonance", node: $resonance, range: resonanceRange), ] } // MARK: - Init /// Creates a wah pedal. /// /// - Parameters: /// - inputBus: Audio bus to read the dry input from. Defaults to `0`; set by the board. /// - outputBus: Audio bus to write the filtered output to. Defaults to `0`; set by the board. public init(inputBus: Int = 0, outputBus: Int = 0) { super.init( name: "Wah", inputBus: inputBus, outputBus: outputBus, initialMix: WahPedal.defaultMix ) } // MARK: - Effect public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { // Smooth the position, map it exponentially to a cutoff sweep, and drive a resonant // bandpass — the wah voice following the pedal rather than the signal envelope. let smoothed: Lag.Control = Lag.Control(input: $position, time: smoothingTime) let cutoff: LinExp.Audio = LinExp.Audio( smoothed, inLo: 0.0, inHi: 1.0, outLo: freqLo, outHi: freqHi ) let filtered: SVF.Audio = SVF.Audio( input: dry, freq: cutoff, q: $resonance ) return filtered.bandpass } }