0f69c27772
- Flanger: wraps Lyrebird Flanger (Rate/Depth/Feedback), run fully wet. - Vibrato: sine-swept delay line, fully wet pitch wobble (Rate/Depth). - Distortion: DC-block → tanh drive → tone LPF → hard clip (Drive/Tone); sits between Overdrive and Fuzz. - Harmonizer interval pickers gain minor/major sixths above and below. Each registered (PedalType + registry + enclosure color + palette slot) with build/non-silent + parameter-change + registry tests. Suite 227. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
99 lines
3.0 KiB
Swift
99 lines
3.0 KiB
Swift
// DistortionPedal.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
|
|
/// Mid-gain distortion — more saturated than `OverdrivePedal`, more controlled than `FuzzPedal`.
|
|
///
|
|
/// A DC-blocking high-pass feeds a `tanh` soft-clipper driven hard by the `Drive` knob; a
|
|
/// post-clip low-pass `Tone` control tames the harmonics, and a final hard clip guarantees the
|
|
/// output stays bounded.
|
|
///
|
|
/// ## Knobs
|
|
/// - `drive`: Pre-clip gain into the `tanh` stage. Range `[1, 50]`.
|
|
/// - `tone`: Post-clip low-pass cutoff in Hz. Range `[500, 6000]`.
|
|
public final class DistortionPedal: Pedal {
|
|
|
|
/// One-line description shown in the picker and info panel.
|
|
public override var summary: String {
|
|
"Mid-gain saturated distortion sitting between overdrive and fuzz."
|
|
}
|
|
|
|
// MARK: - Parameters
|
|
|
|
/// Pre-clip gain into the `tanh` stage. Range [1, 50].
|
|
@UIParam public var drive: Double = 12.0
|
|
|
|
/// Post-clip low-pass cutoff in Hz. Range [500, 6000].
|
|
@UIParam public var tone: Double = 3000.0
|
|
|
|
// MARK: - Constants
|
|
|
|
/// Distortion is heard fully wet; the `Level` knob sets output gain.
|
|
private static let defaultMix: Double = 1.0
|
|
|
|
/// DC-blocking high-pass cutoff in Hz, applied before the clipper.
|
|
private let dcBlockFreq: Double = 80.0
|
|
|
|
/// Butterworth Q (no resonant peak) for the conditioning filters.
|
|
private let filterQ: Double = 0.707
|
|
|
|
/// Output hard-clip bounds — guarantees a bounded signal after tone shaping.
|
|
private let clipLow: Double = -1.0
|
|
private let clipHigh: Double = 1.0
|
|
|
|
// MARK: - Ranges
|
|
|
|
private let driveRange: ClosedRange<Double> = 1.0 ... 50.0
|
|
private let toneRange: ClosedRange<Double> = 500.0 ... 6000.0
|
|
|
|
// MARK: - Knobs
|
|
|
|
public override var effectKnobs: [PedalKnob] {
|
|
[
|
|
PedalKnob(label: "Drive", node: $drive, range: driveRange),
|
|
PedalKnob(label: "Tone", node: $tone, range: toneRange),
|
|
]
|
|
}
|
|
|
|
// MARK: - Init
|
|
|
|
/// Creates a distortion 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: "Distortion",
|
|
inputBus: inputBus,
|
|
outputBus: outputBus,
|
|
initialMix: DistortionPedal.defaultMix
|
|
)
|
|
}
|
|
|
|
// MARK: - Effect
|
|
|
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
|
let dcBlocked: RBJHighPass.Audio = RBJHighPass.Audio(
|
|
input: dry,
|
|
freq: dcBlockFreq,
|
|
q: filterQ
|
|
)
|
|
let driven: Tanh.Audio = Tanh.Audio(dcBlocked, mul: $drive)
|
|
let toned: RBJLowPass.Audio = RBJLowPass.Audio(
|
|
input: driven,
|
|
freq: $tone,
|
|
q: filterQ
|
|
)
|
|
return Clip.Audio(toned, lo: clipLow, hi: clipHigh)
|
|
}
|
|
}
|