Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/SustainFuzzPedal.swift
T
josh 75b99a547b feat(pedals): add Sustain Fuzz pedal + Gilmour/doom rigs
New "Sustain Fuzz": a mid-scooped, high-sustain fuzz distinct from the
single-stage Fuzz. Two cascaded soft-clip (softClipNormalized) stages
compress and stack harmonics for smooth violin-like sustain; a fixed
midrange scoop (RBJPeakingEQ cut at 750 Hz) hollows the mids; a tone
low-pass sets the top end. Sustain/Tone/Scoop knobs. Composed in effect(),
no new RT generator.

Registered in PedalType/PedalRegistry, enclosure colour, palette order.
Tests cover build+non-silent, each knob changing output, knob listing,
preset round-trip.

Adds two factory rigs: Comfortably Numb Lead and Doom Riff Wall.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-09 13:10:16 -07:00

151 lines
5.5 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.
// SustainFuzzPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Sustaining, mid-scooped fuzz: two cascaded soft-clipping stages into a scoop-and-tone filter.
///
/// Signal chain (inside `effect(_:)`):
/// ```
/// dry → Saturator(soft, sustain) → Saturator(soft, sustain) → RBJPeakingEQ(−scoop @ 750 Hz) → RBJLowPass(tone) → out
/// ```
///
/// This is the "wall of sustain" fuzz voice — distinct from the single-stage ``FuzzPedal``. Two
/// cascaded *soft*-clipping stages compress and stack harmonics for long, smooth, violin-like
/// sustain rather than the aggressive bite of a single hard `tanh` stage. A fixed mid **scoop**
/// (a bell cut around 750 Hz) hollows the midrange — the defining character of this fuzz family —
/// and the **tone** low-pass sets how dark or bright the top end sits.
///
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class; base `mix` is fully
/// wet so the fuzz replaces the dry signal.
///
/// ## Parameters
///
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
///
/// - Parameters:
/// - sustain: Drive into both soft-clip stages. Higher = more sustain and compression.
/// Range `[1, 30]`. Defaults to `6.0`.
/// - tone: Low-pass tone cutoff in Hz. Range `[800, 6000]`. Defaults to `2500.0`.
/// - scoop: Midrange cut depth in dB at 750 Hz (applied as a cut). Range `[0, 18]`. Defaults to `8.0`.
public final class SustainFuzzPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Sustaining, mid-scooped fuzz for smooth, violin-like leads and thick walls of sound."
}
// MARK: - Parameters
/// Drive into both cascaded soft-clip stages. Range [1, 30]; higher = more sustain.
@UIParam public var sustain: Double = 6.0
/// Tone low-pass cutoff in Hz. Range [800, 6000].
@UIParam public var tone: Double = 2500.0
/// Midrange cut depth in dB at 750 Hz. Range [0, 18].
@UIParam public var scoop: Double = 8.0
// MARK: - Constants
/// Default wet/dry blend — fully wet so the fuzz completely replaces the dry signal.
private static let defaultMix: Double = 1.0
/// Oversampling factor for the soft-clip stages — 2× keeps generated harmonics from folding back.
private let oversampleFactor: Int = 2
/// Centre frequency of the midrange scoop in Hz.
private let scoopFreq: Double = 750.0
/// Q of the midrange scoop bell. Moderately wide for a broad, hollow midrange.
private let scoopQ: Double = 0.9
/// Q of the tone low-pass. Butterworth (no resonant peak).
private let toneQ: Double = 0.707
/// Output trim after two soft-clip stages (each ≈ ±1) plus the mid cut, to sit at a sane level.
private let outputTrim: Double = 0.6
// MARK: - UI knobs
/// Sustain knob range (drive into the soft-clip stages).
private let sustainRange: ClosedRange<Double> = 1.0 ... 30.0
/// Tone knob range in Hz (low-pass cutoff).
private let toneRange: ClosedRange<Double> = 800.0 ... 6000.0
/// Scoop knob range in dB (midrange cut depth).
private let scoopRange: ClosedRange<Double> = 0.0 ... 18.0
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Sustain", node: $sustain, range: sustainRange),
PedalKnob(label: "Tone", node: $tone, range: toneRange),
PedalKnob(label: "Scoop", node: $scoop, range: scoopRange),
]
}
// MARK: - Init
/// Creates a sustain-fuzz pedal.
///
/// - Parameters:
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
public init(
inputBus: Int = 0,
outputBus: Int = 0
) {
super.init(
name: "Sustain Fuzz",
inputBus: inputBus,
outputBus: outputBus,
initialMix: SustainFuzzPedal.defaultMix
)
}
// MARK: - Effect
/// Cascades two soft-clip stages, scoops the mids, then rolls off the top with the tone control.
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: Sustained, mid-scooped, tone-shaped mono output.
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
// Two cascaded soft-clip stages. `softClipNormalized` keeps the level bounded as sustain
// rises, so stacking two stages compresses and sustains rather than runs away.
let stage1: OversampledSaturator = OversampledSaturator(
dry,
drive: $sustain,
curve: .softClipNormalized,
oversample: oversampleFactor
)
let stage2: OversampledSaturator = OversampledSaturator(
stage1,
drive: $sustain,
curve: .softClipNormalized,
oversample: oversampleFactor
)
// Fixed midrange scoop (cut) — the hollow midrange that defines this fuzz family.
let scoopCutDB: any ValidGeneratorInput = 0.0 - $scoop
let scooped: RBJPeakingEQ.Audio = RBJPeakingEQ.Audio(
input: stage2,
freq: scoopFreq,
gain: scoopCutDB,
q: scoopQ
)
// Tone low-pass rolls off the top end.
let toned: RBJLowPass.Audio = RBJLowPass.Audio(
input: scooped,
freq: $tone,
q: toneQ
)
return toned * outputTrim
}
}