Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/FuzzPedal.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

118 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.
// FuzzPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Fuzz pedal: high-gain `tanh` saturation followed by a tonal low-pass filter.
///
/// Signal chain (inside `effect(_:)`):
/// ```
/// dry → (× fuzz drive) → Tanh → RBJLowPass(freq: tone, q: 0.707) → mono out
/// ```
///
/// The `fuzz` knob is a pre-gain (drive): it multiplies the input hard before the
/// `tanh` saturator, which squares the waveform off into the thick, sustaining fuzz
/// texture. Because `tanh` saturates toward ±1, the output level stays roughly constant
/// as `fuzz` rises — more drive means more grit and sustain, never less signal. A tone
/// filter then rolls off high-frequency harshness.
///
/// > Note: This deliberately differs from the earlier crossover-distortion model, where
/// > the knob set a silent dead-zone width and large values muted quiet signals.
///
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
///
/// ## Parameters
///
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
///
/// - Parameters:
/// - fuzz: Pre-gain drive into the `tanh` saturator. Higher = more saturation and
/// sustain. Range `[1, 60]`. Defaults to `20.0`.
/// - tone: Low-pass tone cutoff in Hz. Roll off high-frequency fuzz harshness.
/// Range `[200, 8000]` Hz. Defaults to `3500.0`.
public final class FuzzPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Thick, saturated fuzz for aggressive, sustaining distortion."
}
// MARK: - Parameters
/// Pre-gain drive into the saturator. Range [1, 60]; higher = more fuzz.
@UIParam public var fuzz: Double = 20.0
/// Tone filter cutoff frequency in Hz. Range [200, 8000].
@UIParam public var tone: Double = 3500.0
// MARK: - Constants
/// Default wet/dry blend — fully wet so fuzz completely replaces dry signal.
private static let defaultMix: Double = 1.0
/// Q factor for the tone low-pass filter. Butterworth response (no resonant peak).
private let toneQ: Double = 0.707
/// Output trim applied after the `tanh` saturator so the fuzz sits at a sane level
/// relative to the other pedals (`tanh` output is roughly ±1).
private let outputTrim: Double = 0.6
// MARK: - UI knobs
/// Fuzz knob range (saturator pre-gain / drive).
private let fuzzRange: ClosedRange<Double> = 1.0 ... 60.0
/// Tone knob range in Hz (low-pass cutoff).
private let toneRange: ClosedRange<Double> = 200.0 ... 8000.0
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Fuzz", node: $fuzz, range: fuzzRange),
PedalKnob(label: "Tone", node: $tone, range: toneRange),
]
}
// MARK: - Init
/// Creates a 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: "Fuzz",
inputBus: inputBus,
outputBus: outputBus,
initialMix: FuzzPedal.defaultMix
)
}
// MARK: - Effect
/// Drives the input hard into a `tanh` saturator, then applies a tonal low-pass.
///
/// Output is mono.
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: Fuzzed and tone-shaped mono output.
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
// Pre-gain the signal hard, then saturate. `tanh` squares the waveform off as the
// drive rises while keeping the level bounded — the hallmark of a fuzz.
let driven: any ValidGeneratorInput = dry * $fuzz
let saturated: Tanh.Audio = Tanh.Audio(driven, mul: outputTrim)
return RBJLowPass.Audio(
input: saturated,
freq: $tone,
q: toneQ
)
}
}