Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/AutoWahPedal.swift
T
josh 5040ea1518 Rename Mu-Tron pedal to Mutant (de-trademark)
Rename the user-facing 'Mu-Tron' pedal to the non-proprietary 'Mutant':
displayName, registry key, PedalType.mutant, enclosure color, palette order,
and the class (MuTronPedal -> MutantPedal) + test file. The underlying Lyrebird
MuTronIII generator (and its Mode/Sweep types) keep their names — that's the
dependency's DSP type, not user-facing.

Note: displayName doubles as the rig-save key, so rigs saved with 'Mu-Tron'
won't match on load (acceptable pre-1.0; nothing released).

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

119 lines
4.1 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 {
// 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
}
}