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

94 lines
2.9 KiB
Swift

// OverdrivePedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Overdrive pedal: soft-clipping saturation followed by a tonal low-pass filter.
///
/// Signal chain (inside `effect(_:)`):
/// ```
/// dry → SoftClip(drive:) → RBJLowPass(freq: tone, q: 0.707) → mono out
/// ```
///
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
///
/// ## Parameters
///
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
///
/// - Parameters:
/// - drive: Saturation amount. Higher values push more of the signal into soft-clip
/// territory. Range `[1, 20]`. Defaults to `4.0`.
/// - tone: Low-pass tone cutoff in Hz. Roll off high-frequency harshness.
/// Range `(0, 20000]`. Defaults to `4000.0`.
public final class OverdrivePedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Warm soft-clip overdrive with a tone control, from gentle grit to singing sustain."
}
// MARK: - Parameters
/// Saturation drive amount. Range [1, 20]; higher = more clipping.
@UIParam public var drive: Double = 4.0
/// Tone filter cutoff frequency in Hz. Range (0, 20000].
@UIParam public var tone: Double = 4000.0
// MARK: - Constants
/// Q factor for the tone low-pass filter. Butterworth response (no resonant peak).
private let toneQ: Double = 0.707
// MARK: - Init
/// Creates an overdrive 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: "Overdrive", inputBus: inputBus, outputBus: outputBus)
}
// MARK: - UI knobs
/// Drive knob range (waveshaper input gain).
private let driveRange: ClosedRange<Double> = 1.0 ... 20.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: "Drive", node: $drive, range: driveRange),
PedalKnob(label: "Tone", node: $tone, range: toneRange),
]
}
// MARK: - Effect
/// Applies soft-clip saturation followed by a tonal low-pass filter.
///
/// Output is mono.
///
/// - Parameter dry: Dry mono input signal.
/// - Returns: Saturated and tone-shaped mono output.
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
let saturated: SoftClip.Audio = SoftClip.Audio(dry, drive: $drive)
return RBJLowPass.Audio(
input: saturated,
freq: $tone,
q: toneQ
)
}
}