Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/OctaveUpSplitterPedal.swift
T
josh f29ab609bd Add Chorus, Sustainer, Ring Modulator pedals + pedal-info UI
Pedals (each registered, with PedalType static, enclosure color, palette order,
summary, and tests):
- Chorus: true-stereo widener (two anti-phase modulated delay lines), distinct
  from the mono-summed Modulation chorus.
- Sustainer: one-knob compressor (sustain drives threshold/ratio/makeup via
  LinLin) + tone low-pass.
- Ring Modulator: dry × tunable sine carrier.

Pedal-info UI:
- Pedal.summary (open var, overridden by all 21 pedals; mandatory going forward).
- PedalRegistry.summary(for:) for the picker.
- PedalPaletteView rows show the summary as a subtitle.
- PedalView gains an ⓘ button → PedalInfoView sheet showing the description and
  the effect controls (knobs/sliders/switches) with ranges/options — excludes
  the common Mix/Level/bypass.

Tests: per-pedal build/param-change/knob-list; every built-in pedal has a
non-empty summary; info excludes common controls. 183 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 18:05:30 -07:00

132 lines
4.7 KiB
Swift

// 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<Double> = 1.0 ... 40.0
/// Tone knob range in Hz (octave-channel low-pass cutoff).
private let toneRange: ClosedRange<Double> = 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)
}
}