1.0 release
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
// 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 {
|
||||
|
||||
// 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
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user