// PhaserPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Phaser pedal: cascaded all-pass filter swept by a sine LFO. /// /// Signal chain (inside `effect(_:)`): /// ``` /// dry → Phaser.Audio(rate:, feedback:, mix: 1.0) → mono out /// ``` /// /// `Phaser.Audio` is mono-in / mono-out. Its internal `mix` is set to `1.0` (fully /// wet) so the base `Pedal` class handles the dry/wet blend uniformly via its own /// `mix` parameter. /// /// The wet/dry mix and bypass switching are handled by the `Pedal` base class. /// /// ## Parameters /// /// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus: /// /// - Parameters: /// - rate: LFO sweep rate in Hz. Range `[0.05, 5.0]`. Defaults to `0.5`. /// - feedback: Feedback gain in `[0, 0.9]`. Higher values deepen the notches. /// Range `[0.0, 0.9]`. Defaults to `0.5`. public final class PhaserPedal: Pedal { /// One-line description shown in the picker and info panel. public override var summary: String { "Sweeping phase shifter for swirling, watery motion." } // MARK: - Parameters /// LFO sweep rate in Hz. Range [0.05, 5.0]. @UIParam public var rate: Double = 0.5 /// Feedback gain in [0, 0.9]. Deepens the all-pass notches. @UIParam public var feedback: Double = 0.5 // MARK: - Constants /// Default wet/dry blend — even mix for classic phaser comb-filter sweep. private static let defaultMix: Double = 0.5 /// Internal `Phaser.Audio` mix — set to 1.0 so the base `Pedal` handles dry/wet. private let phaserInternalMix: Double = 1.0 /// LFO depth fraction — sweeps the all-pass coefficient across its full range. private let phaserDepth: Double = 0.9 /// Center frequency in Hz for the all-pass coefficient sweep. private let phaserCenterFreq: Double = 800.0 /// Number of cascaded all-pass stages. Must be 4, 6, or 8. private let phaserStages: Int = 6 // MARK: - UI knobs /// Rate knob range in Hz (LFO sweep frequency). private let rateRange: ClosedRange = 0.05 ... 5.0 /// Feedback knob range (all-pass feedback gain). private let feedbackRange: ClosedRange = 0.0 ... 0.9 public override var effectKnobs: [PedalKnob] { [ PedalKnob(label: "Rate", node: $rate, range: rateRange), PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange), ] } // MARK: - Init /// Creates a phaser 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: "Phaser", inputBus: inputBus, outputBus: outputBus, initialMix: PhaserPedal.defaultMix ) } // MARK: - Effect /// Applies cascaded all-pass phasing and returns the fully-wet signal. /// /// `Phaser.Audio` is mono-in / mono-out. The base `Pedal` class mixes this with /// the dry signal according to the `mix` parameter. /// /// - Parameter dry: Dry mono input signal. /// - Returns: Wet mono phaser output. public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { Phaser.Audio( input: dry, rate: $rate, depth: phaserDepth, centerFreq: phaserCenterFreq, feedback: $feedback, stages: phaserStages, mix: phaserInternalMix, sampleRate: sampleRate ) } }