// ScriptPhaserPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Script phaser — the classic one-knob, four-stage orange phaser (the script-logo voicing). /// /// A single **Speed** knob sweeps a fixed four-stage all-pass cascade; there is no depth or /// feedback knob, just the signature liquid whoosh. A **Voicing** switch picks the character: the /// smoother *Script* voicing (lower feedback, gentler notch) or the more resonant *Block* voicing /// (more feedback, sharper notch) — the two eras of the hardware. /// /// Distinct from the general-purpose ``PhaserPedal`` (six stages, with rate **and** feedback knobs): /// this is deliberately the fixed, four-stage, one-knob classic. Wraps the shared `Phaser.Audio` /// generator run fully wet; the base `Pedal` `mix` sets the wet/dry blend. /// /// ## Knobs /// - `speed`: LFO sweep rate in Hz. Range `[0.05, 5.0]`. /// /// ## Switches /// - `voicing` (two-state): `0` = Script (smoother), `1` = Block (more resonant). public final class ScriptPhaserPedal: Pedal { /// One-line description shown in the picker and info panel. public override var summary: String { "The one-knob four-stage orange phaser — liquid whoosh, script or block voicing." } // MARK: - Parameters /// LFO sweep rate in Hz. Range [0.05, 5.0]. @UIParam public var speed: Double = 0.5 /// Voicing selector. `0` = Script (smoother, lower feedback), `1` = Block (more resonant). @UIParam public var voicing: Double = 0.0 // MARK: - Constants /// Default wet/dry blend — an even mix for the classic comb-filter sweep. private static let defaultMix: Double = 0.5 /// Internal `Phaser.Audio` mix — `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 range. private let phaserDepth: Double = 0.9 /// Center frequency in Hz for the all-pass coefficient sweep. private let phaserCenterFreq: Double = 800.0 /// Four cascaded all-pass stages — the defining topology of this phaser (`Phaser.Audio` /// requires 4, 6, or 8). private let phaserStages: Int = 4 /// Feedback for the Script voicing — low, for a smooth gentle notch. private let scriptFeedbackValue: Double = 0.2 /// Feedback for the Block voicing — higher, for a sharper, more resonant notch. private let blockFeedbackValue: Double = 0.45 // MARK: - Switch values private let voicingScriptValue: Double = 0.0 private let voicingBlockValue: Double = 1.0 /// Smoothing time in seconds for the voicing→feedback change, so flipping Script↔Block glides /// the feedback coefficient instead of stepping it (which could tick on a live toggle). private let voicingSmoothTime: Double = 0.03 // MARK: - Ranges private let speedRange: ClosedRange = 0.05 ... 5.0 // MARK: - Knobs public override var tempoSyncableParams: [TempoSyncableParam] { [ TempoSyncableParam(key: "speed", label: "Speed", node: $speed, kind: .rate, range: speedRange), ] } public override var effectKnobs: [PedalKnob] { [ PedalKnob(label: "Speed", node: $speed, range: speedRange), ] } // MARK: - Switches public override var effectSwitches: [PedalSwitch] { [ PedalSwitch( label: "Voicing", node: $voicing, options: [ PedalSwitch.Option(title: "Script", value: voicingScriptValue), PedalSwitch.Option(title: "Block", value: voicingBlockValue), ] ) ] } // MARK: - Init /// Creates a script-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: "Script Phaser", inputBus: inputBus, outputBus: outputBus, initialMix: ScriptPhaserPedal.defaultMix ) } // MARK: - Effect public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { // Voicing (0 = Script, 1 = Block) selects the feedback amount live — a linear map between the // two fixed values, no rebuild needed since feedback is a live Phaser parameter. A short Lag // glides the coefficient on a Script↔Block toggle so it doesn't step audibly. let feedbackSpan: Double = blockFeedbackValue - scriptFeedbackValue let voicedFeedback: any ValidGeneratorInput = ($voicing * feedbackSpan) + scriptFeedbackValue let smoothedFeedback: Lag.Audio = Lag.Audio(input: voicedFeedback, time: voicingSmoothTime) return Phaser.Audio( input: dry, rate: $speed, depth: phaserDepth, centerFreq: phaserCenterFreq, feedback: smoothedFeedback, stages: phaserStages, mix: phaserInternalMix, sampleRate: sampleRate ) } }