Add Flanger, Vibrato, and Distortion pedals; 6th intervals on Harmonizer
- 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>
This commit is contained in:
@@ -45,6 +45,7 @@ public extension PedalType {
|
|||||||
|
|
||||||
// Drive & dynamics
|
// Drive & dynamics
|
||||||
static let overdrive = PedalType("Overdrive")
|
static let overdrive = PedalType("Overdrive")
|
||||||
|
static let distortion = PedalType("Distortion")
|
||||||
static let fuzz = PedalType("Fuzz")
|
static let fuzz = PedalType("Fuzz")
|
||||||
static let compressor = PedalType("Compressor")
|
static let compressor = PedalType("Compressor")
|
||||||
static let limiter = PedalType("Limiter")
|
static let limiter = PedalType("Limiter")
|
||||||
@@ -60,6 +61,8 @@ public extension PedalType {
|
|||||||
static let tremolo = PedalType("Tremolo")
|
static let tremolo = PedalType("Tremolo")
|
||||||
static let modulation = PedalType("Modulation")
|
static let modulation = PedalType("Modulation")
|
||||||
static let chorus = PedalType("Chorus")
|
static let chorus = PedalType("Chorus")
|
||||||
|
static let flanger = PedalType("Flanger")
|
||||||
|
static let vibrato = PedalType("Vibrato")
|
||||||
static let ringModulator = PedalType("Ring Modulator")
|
static let ringModulator = PedalType("Ring Modulator")
|
||||||
static let diffuser = PedalType("Diffuser")
|
static let diffuser = PedalType("Diffuser")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
// 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
// FlangerPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Classic jet-flanger.
|
||||||
|
///
|
||||||
|
/// A short LFO-swept delay summed with the dry signal produces the sweeping comb-filter notches;
|
||||||
|
/// feedback sharpens them into the metallic "jet" whoosh. Wraps Lyrebird's `Flanger` generator,
|
||||||
|
/// run fully wet so the pedal's own `Mix` knob sets the wet/dry blend.
|
||||||
|
///
|
||||||
|
/// ## Knobs
|
||||||
|
/// - `rate`: LFO sweep rate in Hz. Range `[0.05, 8]`.
|
||||||
|
/// - `depth`: Sweep depth as a fraction of the center delay. Range `[0, 1]`.
|
||||||
|
/// - `feedback`: Comb feedback (resonance). Range `[0, 0.95]`.
|
||||||
|
public final class FlangerPedal: Pedal {
|
||||||
|
|
||||||
|
/// One-line description shown in the picker and info panel.
|
||||||
|
public override var summary: String {
|
||||||
|
"Sweeping comb-filter jet flanger, with feedback for that metallic whoosh."
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// LFO sweep rate in Hz. Range [0.05, 8].
|
||||||
|
@UIParam public var rate: Double = 0.4
|
||||||
|
|
||||||
|
/// Sweep depth as a fraction of the center delay. Range [0, 1].
|
||||||
|
@UIParam public var depth: Double = 0.6
|
||||||
|
|
||||||
|
/// Comb feedback (resonance). Range [0, 0.95].
|
||||||
|
@UIParam public var feedback: Double = 0.3
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Default wet/dry blend — flanger sits under the dry signal.
|
||||||
|
private static let defaultMix: Double = 0.5
|
||||||
|
|
||||||
|
/// Center delay the LFO sweeps around, in seconds.
|
||||||
|
private let centerDelayTime: Double = 0.005
|
||||||
|
|
||||||
|
/// Maximum delay the line is allocated for, in seconds. Covers `centerDelayTime · (1 + maxDepth)`.
|
||||||
|
private let maxDelayTime: Double = 0.05
|
||||||
|
|
||||||
|
/// The wrapped generator runs fully wet; the `Pedal` base `Mix` knob does the blend.
|
||||||
|
private let fullyWetMix: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - Ranges
|
||||||
|
|
||||||
|
private let rateRange: ClosedRange<Double> = 0.05 ... 8.0
|
||||||
|
private let depthRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
private let feedbackRange: ClosedRange<Double> = 0.0 ... 0.95
|
||||||
|
|
||||||
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||||||
|
PedalKnob(label: "Depth", node: $depth, range: depthRange),
|
||||||
|
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a flanger 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: "Flanger",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: FlangerPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
Flanger.Audio(
|
||||||
|
input: dry,
|
||||||
|
delayTime: centerDelayTime,
|
||||||
|
depth: $depth,
|
||||||
|
rate: $rate,
|
||||||
|
feedback: $feedback,
|
||||||
|
mix: fullyWetMix,
|
||||||
|
sampleRate: sampleRate,
|
||||||
|
maxDelayTime: maxDelayTime
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// VibratoPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Pitch vibrato.
|
||||||
|
///
|
||||||
|
/// A single delay line whose time is swept by a sine LFO produces a periodic pitch wobble. Unlike
|
||||||
|
/// `TremoloPedal` (which modulates *volume*), vibrato modulates *pitch*, and unlike `ChorusPedal`
|
||||||
|
/// it is heard fully wet — there is no dry voice underneath, so the result is pure pitch movement.
|
||||||
|
///
|
||||||
|
/// ## Knobs
|
||||||
|
/// - `rate`: LFO rate in Hz. Range `[0.1, 8]`.
|
||||||
|
/// - `depth`: Delay-sweep depth in seconds (half-swing around the base delay). Range
|
||||||
|
/// `[0.0005, 0.006]`.
|
||||||
|
public final class VibratoPedal: Pedal {
|
||||||
|
|
||||||
|
/// One-line description shown in the picker and info panel.
|
||||||
|
public override var summary: String {
|
||||||
|
"Periodic pitch wobble — a sine-swept delay heard fully wet."
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// LFO rate in Hz. Range [0.1, 8].
|
||||||
|
@UIParam public var rate: Double = 5.0
|
||||||
|
|
||||||
|
/// Delay-sweep depth in seconds. Range [0.0005, 0.006].
|
||||||
|
@UIParam public var depth: Double = 0.002
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Vibrato is pure pitch movement — fully wet, no dry voice underneath.
|
||||||
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// Base delay around which the LFO sweeps, in seconds.
|
||||||
|
private let baseDelayTime: Double = 0.006
|
||||||
|
|
||||||
|
/// Maximum delay the line is allocated for, in seconds. Covers `baseDelayTime + max depth`.
|
||||||
|
private let maxDelayTime: Double = 0.02
|
||||||
|
|
||||||
|
// MARK: - Ranges
|
||||||
|
|
||||||
|
private let rateRange: ClosedRange<Double> = 0.1 ... 8.0
|
||||||
|
private let depthRange: ClosedRange<Double> = 0.0005 ... 0.006
|
||||||
|
|
||||||
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||||||
|
PedalKnob(label: "Depth", node: $depth, range: depthRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a vibrato 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: "Vibrato",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: VibratoPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
let sweep: OscSin.Audio = OscSin.Audio(
|
||||||
|
freq: $rate,
|
||||||
|
phase: 0.0,
|
||||||
|
mul: $depth,
|
||||||
|
add: baseDelayTime
|
||||||
|
)
|
||||||
|
return DelayLine(
|
||||||
|
input: dry,
|
||||||
|
maxDelay: maxDelayTime,
|
||||||
|
delay: sweep,
|
||||||
|
sampleRate: sampleRate,
|
||||||
|
interpolation: .linear
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ public enum PedalRegistry {
|
|||||||
/// to a board via `board.add(_:)`.
|
/// to a board via `board.add(_:)`.
|
||||||
public static let builtIn: [String: @MainActor () -> Pedal] = [
|
public static let builtIn: [String: @MainActor () -> Pedal] = [
|
||||||
"Overdrive": { OverdrivePedal() },
|
"Overdrive": { OverdrivePedal() },
|
||||||
|
"Distortion": { DistortionPedal() },
|
||||||
"Delay": { DelayPedal() },
|
"Delay": { DelayPedal() },
|
||||||
"Reverb": { ReverbPedal() },
|
"Reverb": { ReverbPedal() },
|
||||||
"Modulation": { ModulationPedal() },
|
"Modulation": { ModulationPedal() },
|
||||||
@@ -51,6 +52,8 @@ public enum PedalRegistry {
|
|||||||
"Noise Gate": { NoiseGatePedal() },
|
"Noise Gate": { NoiseGatePedal() },
|
||||||
"Graphic EQ": { GraphicEQPedal() },
|
"Graphic EQ": { GraphicEQPedal() },
|
||||||
"Chorus": { ChorusPedal() },
|
"Chorus": { ChorusPedal() },
|
||||||
|
"Flanger": { FlangerPedal() },
|
||||||
|
"Vibrato": { VibratoPedal() },
|
||||||
"Sustainer": { SustainerPedal() },
|
"Sustainer": { SustainerPedal() },
|
||||||
"Ring Modulator": { RingModulatorPedal() },
|
"Ring Modulator": { RingModulatorPedal() },
|
||||||
"Diffuser": { DiffuserPedal() },
|
"Diffuser": { DiffuserPedal() },
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public struct PedalPaletteView: View {
|
|||||||
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is
|
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is
|
||||||
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
|
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
|
||||||
private static let preferredOrder: [String] = [
|
private static let preferredOrder: [String] = [
|
||||||
"Overdrive", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
|
"Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
|
||||||
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus",
|
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato",
|
||||||
"Auto-Wah", "Mutant", "Ring Modulator", "Diffuser", "Bass Octaver", "Octave Splitter",
|
"Auto-Wah", "Mutant", "Ring Modulator", "Diffuser", "Bass Octaver", "Octave Splitter",
|
||||||
"Harmonizer",
|
"Harmonizer",
|
||||||
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverb",
|
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverb",
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import LyrebirdShoeGaze
|
|||||||
private func enclosureColor(for displayName: String) -> Color {
|
private func enclosureColor(for displayName: String) -> Color {
|
||||||
switch displayName {
|
switch displayName {
|
||||||
case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange
|
case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange
|
||||||
|
case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust
|
||||||
case "Delay": return Color(red: 0.10, green: 0.55, blue: 0.55) // teal
|
case "Delay": return Color(red: 0.10, green: 0.55, blue: 0.55) // teal
|
||||||
case "Reverb": return Color(red: 0.30, green: 0.18, blue: 0.65) // indigo
|
case "Reverb": return Color(red: 0.30, green: 0.18, blue: 0.65) // indigo
|
||||||
case "Modulation": return Color(red: 0.12, green: 0.58, blue: 0.22) // green
|
case "Modulation": return Color(red: 0.12, green: 0.58, blue: 0.22) // green
|
||||||
@@ -32,6 +33,8 @@ private func enclosureColor(for displayName: String) -> Color {
|
|||||||
case "Noise Gate": return Color(red: 0.24, green: 0.26, blue: 0.30) // gunmetal
|
case "Noise Gate": return Color(red: 0.24, green: 0.26, blue: 0.30) // gunmetal
|
||||||
case "Graphic EQ": return Color(red: 0.14, green: 0.40, blue: 0.50) // deep teal
|
case "Graphic EQ": return Color(red: 0.14, green: 0.40, blue: 0.50) // deep teal
|
||||||
case "Chorus": return Color(red: 0.16, green: 0.50, blue: 0.64) // aqua
|
case "Chorus": return Color(red: 0.16, green: 0.50, blue: 0.64) // aqua
|
||||||
|
case "Flanger": return Color(red: 0.28, green: 0.52, blue: 0.78) // steel blue
|
||||||
|
case "Vibrato": return Color(red: 0.42, green: 0.30, blue: 0.70) // violet-blue
|
||||||
case "Sustainer": return Color(red: 0.22, green: 0.46, blue: 0.30) // pine green
|
case "Sustainer": return Color(red: 0.22, green: 0.46, blue: 0.30) // pine green
|
||||||
case "Ring Modulator": return Color(red: 0.64, green: 0.30, blue: 0.10) // burnt amber
|
case "Ring Modulator": return Color(red: 0.64, green: 0.30, blue: 0.10) // burnt amber
|
||||||
case "Diffuser": return Color(red: 0.34, green: 0.30, blue: 0.62) // periwinkle
|
case "Diffuser": return Color(red: 0.34, green: 0.30, blue: 0.62) // periwinkle
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
// DistortionPedalTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
@testable import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("DistortionPedal")
|
||||||
|
struct DistortionPedalTests {
|
||||||
|
|
||||||
|
private func render(
|
||||||
|
configure: (DistortionPedal) -> Void
|
||||||
|
) throws -> [Float] {
|
||||||
|
let renderDuration: Double = 0.2
|
||||||
|
let numAudioBuses: Int = 64
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||||
|
duration: renderDuration,
|
||||||
|
numAudioBuses: numAudioBuses
|
||||||
|
)
|
||||||
|
defer { try? FileManager.default.removeItem(at: url) }
|
||||||
|
|
||||||
|
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
defer {
|
||||||
|
engine.busAllocator.releaseAudioBus(srcBus)
|
||||||
|
engine.busAllocator.releaseAudioBus(dstBus)
|
||||||
|
}
|
||||||
|
|
||||||
|
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||||
|
let pedal: DistortionPedal = DistortionPedal(inputBus: srcBus.index, outputBus: dstBus.index)
|
||||||
|
configure(pedal)
|
||||||
|
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||||
|
|
||||||
|
try engine.add(source)
|
||||||
|
try engine.add(pedal, position: NodePosition.after(source))
|
||||||
|
try engine.add(master, position: NodePosition.after(pedal))
|
||||||
|
try engine.start()
|
||||||
|
|
||||||
|
return readStereoCAF(url: url)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func windowedSSD(_ a: [Float], _ b: [Float]) -> Double {
|
||||||
|
let skipSamples: Int = 2048
|
||||||
|
let windowSize: Int = 2048
|
||||||
|
guard a.count >= skipSamples + windowSize,
|
||||||
|
b.count >= skipSamples + windowSize else { return 0.0 }
|
||||||
|
let aWindow: ArraySlice<Float> = a[skipSamples..<(skipSamples + windowSize)]
|
||||||
|
let bWindow: ArraySlice<Float> = b[skipSamples..<(skipSamples + windowSize)]
|
||||||
|
return zip(aWindow, bWindow).reduce(0.0) { acc, pair in
|
||||||
|
let diff: Double = Double(pair.0 - pair.1)
|
||||||
|
return acc + diff * diff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||||
|
let samples: [Float] = try render { _ in }
|
||||||
|
#expect(!samples.isEmpty)
|
||||||
|
#expect(hasNonSilentOutput(samples), "distortion output was silent")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func driveChangesOutput() throws {
|
||||||
|
let low: [Float] = try render { pedal in pedal.drive = 2.0 }
|
||||||
|
let high: [Float] = try render { pedal in pedal.drive = 45.0 }
|
||||||
|
#expect(hasNonSilentOutput(high), "high-drive distortion was silent")
|
||||||
|
#expect(windowedSSD(low, high) > 0, "changing drive did not change the output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func toneChangesOutput() throws {
|
||||||
|
let dark: [Float] = try render { pedal in pedal.drive = 30.0; pedal.tone = 700.0 }
|
||||||
|
let bright: [Float] = try render { pedal in pedal.drive = 30.0; pedal.tone = 5500.0 }
|
||||||
|
#expect(hasNonSilentOutput(bright), "bright distortion was silent")
|
||||||
|
#expect(windowedSSD(dark, bright) > 0, "changing tone did not change the output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesDriveToneKnobs() throws {
|
||||||
|
let pedal: DistortionPedal = DistortionPedal()
|
||||||
|
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||||
|
#expect(labels == ["Drive", "Tone"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func registeredInBuiltInRegistry() throws {
|
||||||
|
let pedal: Pedal? = PedalRegistry.makePedal(type: "Distortion")
|
||||||
|
#expect(pedal is DistortionPedal)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
// FlangerPedalTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
@testable import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("FlangerPedal")
|
||||||
|
struct FlangerPedalTests {
|
||||||
|
|
||||||
|
private func render(
|
||||||
|
configure: (FlangerPedal) -> Void
|
||||||
|
) throws -> [Float] {
|
||||||
|
let renderDuration: Double = 0.2
|
||||||
|
let numAudioBuses: Int = 64
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||||
|
duration: renderDuration,
|
||||||
|
numAudioBuses: numAudioBuses
|
||||||
|
)
|
||||||
|
defer { try? FileManager.default.removeItem(at: url) }
|
||||||
|
|
||||||
|
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
defer {
|
||||||
|
engine.busAllocator.releaseAudioBus(srcBus)
|
||||||
|
engine.busAllocator.releaseAudioBus(dstBus)
|
||||||
|
}
|
||||||
|
|
||||||
|
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||||
|
let pedal: FlangerPedal = FlangerPedal(inputBus: srcBus.index, outputBus: dstBus.index)
|
||||||
|
configure(pedal)
|
||||||
|
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||||
|
|
||||||
|
try engine.add(source)
|
||||||
|
try engine.add(pedal, position: NodePosition.after(source))
|
||||||
|
try engine.add(master, position: NodePosition.after(pedal))
|
||||||
|
try engine.start()
|
||||||
|
|
||||||
|
return readStereoCAF(url: url)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func windowedSSD(_ a: [Float], _ b: [Float]) -> Double {
|
||||||
|
let skipSamples: Int = 2048
|
||||||
|
let windowSize: Int = 2048
|
||||||
|
guard a.count >= skipSamples + windowSize,
|
||||||
|
b.count >= skipSamples + windowSize else { return 0.0 }
|
||||||
|
let aWindow: ArraySlice<Float> = a[skipSamples..<(skipSamples + windowSize)]
|
||||||
|
let bWindow: ArraySlice<Float> = b[skipSamples..<(skipSamples + windowSize)]
|
||||||
|
return zip(aWindow, bWindow).reduce(0.0) { acc, pair in
|
||||||
|
let diff: Double = Double(pair.0 - pair.1)
|
||||||
|
return acc + diff * diff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||||
|
let samples: [Float] = try render { _ in }
|
||||||
|
#expect(!samples.isEmpty)
|
||||||
|
#expect(hasNonSilentOutput(samples), "flanger output was silent")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func depthChangesOutput() throws {
|
||||||
|
let shallow: [Float] = try render { pedal in pedal.depth = 0.1; pedal.mix = 1.0 }
|
||||||
|
let deep: [Float] = try render { pedal in pedal.depth = 0.95; pedal.mix = 1.0 }
|
||||||
|
#expect(hasNonSilentOutput(deep), "deep flanger was silent")
|
||||||
|
#expect(windowedSSD(shallow, deep) > 0, "changing depth did not change the output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func feedbackChangesOutput() throws {
|
||||||
|
let dry: [Float] = try render { pedal in pedal.feedback = 0.0; pedal.mix = 1.0 }
|
||||||
|
let resonant: [Float] = try render { pedal in pedal.feedback = 0.85; pedal.mix = 1.0 }
|
||||||
|
#expect(hasNonSilentOutput(resonant), "resonant flanger was silent")
|
||||||
|
#expect(windowedSSD(dry, resonant) > 0, "changing feedback did not change the output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesRateDepthFeedbackKnobs() throws {
|
||||||
|
let pedal: FlangerPedal = FlangerPedal()
|
||||||
|
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||||
|
#expect(labels == ["Rate", "Depth", "Feedback"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func registeredInBuiltInRegistry() throws {
|
||||||
|
let pedal: Pedal? = PedalRegistry.makePedal(type: "Flanger")
|
||||||
|
#expect(pedal is FlangerPedal)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
// VibratoPedalTests.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
@testable import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
@Suite("VibratoPedal")
|
||||||
|
struct VibratoPedalTests {
|
||||||
|
|
||||||
|
private func render(
|
||||||
|
configure: (VibratoPedal) -> Void
|
||||||
|
) throws -> [Float] {
|
||||||
|
let renderDuration: Double = 0.2
|
||||||
|
let numAudioBuses: Int = 64
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||||
|
duration: renderDuration,
|
||||||
|
numAudioBuses: numAudioBuses
|
||||||
|
)
|
||||||
|
defer { try? FileManager.default.removeItem(at: url) }
|
||||||
|
|
||||||
|
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
defer {
|
||||||
|
engine.busAllocator.releaseAudioBus(srcBus)
|
||||||
|
engine.busAllocator.releaseAudioBus(dstBus)
|
||||||
|
}
|
||||||
|
|
||||||
|
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||||
|
let pedal: VibratoPedal = VibratoPedal(inputBus: srcBus.index, outputBus: dstBus.index)
|
||||||
|
configure(pedal)
|
||||||
|
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||||
|
|
||||||
|
try engine.add(source)
|
||||||
|
try engine.add(pedal, position: NodePosition.after(source))
|
||||||
|
try engine.add(master, position: NodePosition.after(pedal))
|
||||||
|
try engine.start()
|
||||||
|
|
||||||
|
return readStereoCAF(url: url)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func windowedSSD(_ a: [Float], _ b: [Float]) -> Double {
|
||||||
|
let skipSamples: Int = 2048
|
||||||
|
let windowSize: Int = 2048
|
||||||
|
guard a.count >= skipSamples + windowSize,
|
||||||
|
b.count >= skipSamples + windowSize else { return 0.0 }
|
||||||
|
let aWindow: ArraySlice<Float> = a[skipSamples..<(skipSamples + windowSize)]
|
||||||
|
let bWindow: ArraySlice<Float> = b[skipSamples..<(skipSamples + windowSize)]
|
||||||
|
return zip(aWindow, bWindow).reduce(0.0) { acc, pair in
|
||||||
|
let diff: Double = Double(pair.0 - pair.1)
|
||||||
|
return acc + diff * diff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||||
|
let samples: [Float] = try render { _ in }
|
||||||
|
#expect(!samples.isEmpty)
|
||||||
|
#expect(hasNonSilentOutput(samples), "vibrato output was silent")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func depthChangesOutput() throws {
|
||||||
|
let shallow: [Float] = try render { pedal in pedal.depth = 0.0006 }
|
||||||
|
let deep: [Float] = try render { pedal in pedal.depth = 0.006 }
|
||||||
|
#expect(hasNonSilentOutput(deep), "deep vibrato was silent")
|
||||||
|
#expect(windowedSSD(shallow, deep) > 0, "changing depth did not change the output")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func exposesRateDepthKnobs() throws {
|
||||||
|
let pedal: VibratoPedal = VibratoPedal()
|
||||||
|
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||||
|
#expect(labels == ["Rate", "Depth"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func registeredInBuiltInRegistry() throws {
|
||||||
|
let pedal: Pedal? = PedalRegistry.makePedal(type: "Vibrato")
|
||||||
|
#expect(pedal is VibratoPedal)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user