// OctaveUpSplitterPedal.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import LyrebirdSynth import LyrebirdUI /// Widener pedal: clean signal on the left, an octave-up fuzz on the right (1 → 2). /// /// A ``PedalChannelKind/widener``. It takes a mono input and produces two distinct wet /// channels, widening the board chain from mono to stereo: /// /// - **Left**: the dry signal, passed through clean. /// - **Right**: an octave-up voice produced by full-wave rectification (`Abs`, which doubles /// the perceived frequency), DC-removed, driven into a `tanh` saturator, and tone-shaped — /// the classic "Octavia"-style octave fuzz. /// /// After this pedal the chain is stereo; subsequent mono pedals auto-stereoize across both /// channels, so you can, for example, add a delay that processes the clean and octave voices /// independently. /// /// ## Parameters /// /// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus: /// /// - Parameters: /// - drive: Pre-gain into the octave-channel saturator. Higher = thicker octave fuzz. /// Range `[1, 40]`. Defaults to `12.0`. /// - tone: Octave-channel low-pass cutoff in Hz. Range `[500, 8000]`. Defaults to `4000.0`. public final class OctaveUpSplitterPedal: Pedal { /// One-line description shown in the picker and info panel. public override var summary: String { "Splits a clean octave-up voice alongside your dry signal in stereo." } // MARK: - Parameters /// Pre-gain into the octave-channel saturator. Range [1, 40]; higher = thicker octave fuzz. @UIParam public var drive: Double = 12.0 /// Octave-channel tone low-pass cutoff in Hz. Range [500, 8000]. @UIParam public var tone: Double = 4000.0 // MARK: - Constants /// Gain applied to the rectified signal before drive, compensating the level drop from /// full-wave rectification. private let rectifyGain: Double = 2.0 /// DC-removal high-pass cutoff in Hz. Rectification introduces a DC offset that must be /// removed before the octave voice reaches the output. private let dcBlockFreq: Double = 30.0 /// Q factor for the tone low-pass (Butterworth, no resonant peak). private let toneQ: Double = 0.707 /// High-pass Q (Butterworth). private let dcBlockQ: Double = 0.707 /// Output trim after the saturator (`tanh` output is roughly ±1). private let outputTrim: Double = 0.6 // MARK: - UI knobs /// Drive knob range (octave-channel saturator pre-gain). private let driveRange: ClosedRange = 1.0 ... 40.0 /// Tone knob range in Hz (octave-channel low-pass cutoff). private let toneRange: ClosedRange = 500.0 ... 8000.0 // MARK: - Channel kind /// This pedal widens mono → stereo. public override var channelKind: PedalChannelKind { .widener } // MARK: - Init /// Creates an octave-up splitter pedal. /// /// - Parameters: /// - inputBus: Audio bus index to read the dry input from. Defaults to `0`. /// - outputBus: Audio bus index to write the left output to. Defaults to `0`. public init( inputBus: Int = 0, outputBus: Int = 0 ) { super.init( name: "Octave Splitter", inputBus: inputBus, outputBus: outputBus, initialMix: 1.0 ) } public override var effectKnobs: [PedalKnob] { [ PedalKnob(label: "Drive", node: $drive, range: driveRange), PedalKnob(label: "Tone", node: $tone, range: toneRange), ] } // MARK: - Effect /// Produces the clean left channel and the octave-up right channel. /// /// - Parameter dry: Dry mono input signal. /// - Returns: `(left: clean dry, right: octave-up fuzz)`. public override func wideEffect(_ dry: any ValidGeneratorInput) -> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) { // Full-wave rectification doubles the perceived frequency (octave up). let rectified: Abs.Audio = Abs.Audio(dry, mul: rectifyGain) // Remove the DC offset rectification introduces before it reaches the output. let dcBlocked: RBJHighPass.Audio = RBJHighPass.Audio( input: rectified, freq: dcBlockFreq, q: dcBlockQ ) // Drive into a saturator for the octave-fuzz texture, then tone-shape. let driven: any ValidGeneratorInput = dcBlocked * $drive let saturated: Tanh.Audio = Tanh.Audio(driven, mul: outputTrim) let shaped: RBJLowPass.Audio = RBJLowPass.Audio( input: saturated, freq: $tone, q: toneQ ) return (left: dry, right: shaped) } }