diff --git a/Sources/LyrebirdShoeGaze/PedalType.swift b/Sources/LyrebirdShoeGaze/PedalType.swift index 97f560c..cb62d15 100644 --- a/Sources/LyrebirdShoeGaze/PedalType.swift +++ b/Sources/LyrebirdShoeGaze/PedalType.swift @@ -92,6 +92,7 @@ public extension PedalType { static let chorus = PedalType("Chorus") static let flanger = PedalType("Flanger") static let vibrato = PedalType("Vibrato") + static let vibe = PedalType("Vibe") static let rotary = PedalType("Rotary") static let ringModulator = PedalType("Ring Modulator") static let diffuser = PedalType("Diffuser") diff --git a/Sources/LyrebirdShoeGaze/Pedals/VibePedal.swift b/Sources/LyrebirdShoeGaze/Pedals/VibePedal.swift new file mode 100644 index 0000000..73fa5df --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/VibePedal.swift @@ -0,0 +1,154 @@ +// VibePedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// Photocell "vibe" pedal: four staggered all-pass stages swept by one shared LFO. +/// +/// Signal chain (inside `effect(_:)`): +/// ``` +/// dry → RBJAllPass(freq₀(t)) → RBJAllPass(freq₁(t)) → RBJAllPass(freq₂(t)) → RBJAllPass(freq₃(t)) → wet +/// out = wet·wetAmount + dry·dryAmount (mode: chorus blends dry+wet, vibrato is wet only) +/// ``` +/// +/// Unlike a phaser (evenly-spaced stages producing symmetric notches), the vibe cascades all-pass +/// stages at **staggered** centre frequencies, so the phase relationships between stages produce the +/// characteristic uneven, vocal throb. A single low-frequency sine modulates every stage's centre +/// frequency together; the `intensity` knob scales the sweep depth and the `speed` knob sets the LFO +/// rate. In *chorus* mode the swept signal is blended 50/50 with the dry signal (comb-filter throb); +/// in *vibrato* mode only the swept (phase-modulated) signal passes, for a pitch-vibrato-like warble. +/// +/// The bypass switching is handled by the `Pedal` base class. The base `mix` is fixed fully wet — the +/// chorus/vibrato dry blend is handled internally so the two modes behave correctly. +/// +/// ## Parameters +/// +/// Inherits `bypass` and `level` from `Pedal`, plus: +/// +/// - Parameters: +/// - speed: LFO sweep rate in Hz. Range `[0.1, 12.0]`. Defaults to `3.0`. +/// - intensity: Sweep depth as a fraction of each stage's centre frequency. Range `[0, 0.7]`. +/// Defaults to `0.5`. +/// - mode: `0` = chorus (dry + swept), `1` = vibrato (swept only). Defaults to chorus. +public final class VibePedal: Pedal { + + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Throbbing photocell vibe — swirling chorus and warbling pitch-vibrato motion." + } + + // MARK: - Parameters + + /// LFO sweep rate in Hz. Range [0.1, 12.0]. + @UIParam public var speed: Double = 3.0 + + /// Sweep depth as a fraction of each stage's centre frequency. Range [0, 0.7]. + @UIParam public var intensity: Double = 0.5 + + /// Mode select: `0` = chorus (dry + swept), `1` = vibrato (swept only). + @UIParam public var mode: Double = 0.0 + + // MARK: - Constants + + /// Default wet/dry blend — fully wet; the chorus/vibrato dry mix is handled inside `effect`. + private static let defaultMix: Double = 1.0 + + /// Q for each all-pass stage. Gentle phase transition for a smooth, vocal vibe (not sharp notches). + private let vibeQ: Double = 0.6 + + /// Staggered all-pass stage centre frequencies in Hz. Unequal spacing is what distinguishes the + /// vibe's uneven throb from an evenly-spaced phaser. + private let stageCenterFreqs: [Double] = [300.0, 620.0, 1300.0, 2200.0] + + /// `mode` value selecting chorus (dry + swept). + private let modeChorusValue: Double = 0.0 + + /// `mode` value selecting vibrato (swept only). + private let modeVibratoValue: Double = 1.0 + + /// Wet gain at chorus mode (`mode == 0`); the swept signal sits 50/50 with dry. + private let chorusWetGain: Double = 0.5 + + // MARK: - UI knobs + + /// Speed knob range in Hz (LFO sweep rate). + private let speedRange: ClosedRange = 0.1 ... 12.0 + + /// Intensity knob range (sweep depth fraction). Capped below `1.0` so a stage's swept frequency + /// never collapses toward `0 Hz` at the bottom of the sweep. + private let intensityRange: ClosedRange = 0.0 ... 0.7 + + 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), + PedalKnob(label: "Intensity", node: $intensity, range: intensityRange), + ] + } + + public override var effectSwitches: [PedalSwitch] { + [ + PedalSwitch( + label: "Mode", + node: $mode, + options: [ + PedalSwitch.Option(title: "Chorus", value: modeChorusValue), + PedalSwitch.Option(title: "Vibrato", value: modeVibratoValue), + ] + ), + ] + } + + // MARK: - Init + + /// Creates a vibe 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: "Vibe", + inputBus: inputBus, + outputBus: outputBus, + initialMix: VibePedal.defaultMix + ) + } + + // MARK: - Effect + + /// Cascades four staggered all-pass stages swept by a shared sine LFO, then blends per mode. + /// + /// - Parameter dry: Dry mono input signal. + /// - Returns: Wet mono vibe output. + public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { + // One shared low-frequency sine drives every stage: ±1 scaled by intensity gives the sweep. + let lfo: any ValidGeneratorInput = OscSin.Audio(freq: $speed) + let sweep: any ValidGeneratorInput = lfo * $intensity // ±intensity + + // Cascade the stages. Each stage's centre frequency is centre·(1 + sweep) = centre + centre·sweep. + var signal: any ValidGeneratorInput = dry + for center: Double in stageCenterFreqs { + let stageFreq: any ValidGeneratorInput = sweep * center + center + signal = RBJAllPass.Audio(input: signal, freq: stageFreq, q: vibeQ) + } + let wet: any ValidGeneratorInput = signal + + // Blend by mode. Chorus (mode 0): 0.5·dry + 0.5·wet. Vibrato (mode 1): wet only. + let wetAmount: any ValidGeneratorInput = $mode * chorusWetGain + chorusWetGain // 0.5 → 1.0 + let dryAmount: any ValidGeneratorInput = (modeVibratoValue - $mode) * chorusWetGain // 0.5 → 0.0 + return wet * wetAmount + dry * dryAmount + } +} diff --git a/Sources/LyrebirdShoeGaze/Presets/Factory/FactoryRigLibrary.swift b/Sources/LyrebirdShoeGaze/Presets/Factory/FactoryRigLibrary.swift index fa3729d..a774154 100644 --- a/Sources/LyrebirdShoeGaze/Presets/Factory/FactoryRigLibrary.swift +++ b/Sources/LyrebirdShoeGaze/Presets/Factory/FactoryRigLibrary.swift @@ -79,6 +79,7 @@ public enum FactoryRigLibrary { dubDelayThrow, ringModTexture, rockabillySlapback, + psychVibeLead, ] // MARK: Shoegaze walls @@ -508,6 +509,36 @@ public enum FactoryRigLibrary { } } + /// Fuzz swirled by a throbbing vibe into delay and plate — vintage psychedelic lead. + static let psychVibeLead: FactoryRig = FactoryRig( + id: stableID("Psych Vibe Lead"), + name: "Psychedelic Vibe Lead", + blurb: "Thick fuzz swirled by a throbbing photocell vibe, into delay and plate — the " + + "late-'60s psychedelic lead voice. Hold notes and let the vibe pulse underneath.", + category: .classic + ) { _, board in + try board.append(FuzzPedal()) { p in + p.fuzz = 30.0 + p.tone = 3000.0 + } + try board.append(VibePedal()) { p in + p.speed = 2.5 + p.intensity = 0.6 + // Chorus mode: dry + swept, the classic vibe throb. + p.mode = 0.0 + } + try board.append(DelayPedal()) { p in + p.time = 0.4 + p.feedback = 2.0 + } + try board.append(PlateReverbPedal()) { p in + p.decay = 0.6 + p.tone = 0.75 + p.damp = 0.3 + p.mod = 0.5 + } + } + // MARK: - Seeding /// Builds every factory rig into a ``RigEntry`` snapshot suitable for the rig library. diff --git a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift index 3edd427..92a452c 100644 --- a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift +++ b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift @@ -91,6 +91,7 @@ public enum PedalRegistry { "Chorus": { ChorusPedal() }, "Flanger": { FlangerPedal() }, "Vibrato": { VibratoPedal() }, + "Vibe": { VibePedal() }, "Rotary": { RotaryPedal() }, "Sustainer": { SustainerPedal() }, "Ring Modulator": { RingModulatorPedal() }, diff --git a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift index 2cb16db..a682933 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift @@ -56,7 +56,7 @@ public struct PedalPaletteView: View { private static let preferredOrder: [String] = [ "California", "British", "British Plexi", "British JTM", "British Bluesbreaker", "British Master", "British Dual", "Boutique Lead", "Boutique OD", "Cali Hi-Gain", "Command", "Citrus", "Sixties Combo", "Magna Vibrato", "Anaheim", "Modern High-Gain", "Chime", "Chime 15", "Chime Normal", "Chime Baby", "Fullerton Reverb", "Fullerton Deluxe", "Fullerton Ivy League", "Fullerton Drive", "Jazz Clean", "Chime Top Boost", "Cabinet", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", "Volume", - "Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary", + "Graphic EQ", "Tremolo", "Phaser", "Vibe", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary", "Auto-Wah", "Wah", "Mutant", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator", "Auto Granulator", "Bass Octaver", "Octave Splitter", "Harmonizer", "Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverse Delay", "Reverb", diff --git a/Sources/LyrebirdShoeGazeUI/PedalView.swift b/Sources/LyrebirdShoeGazeUI/PedalView.swift index 161aa99..0d93e66 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalView.swift @@ -56,6 +56,7 @@ private func enclosureColor(for displayName: String) -> Color { case "Fuzz": return Color(red: 0.55, green: 0.10, blue: 0.10) // deep crimson case "Tremolo": return Color(red: 0.20, green: 0.38, blue: 0.72) // cobalt blue case "Phaser": return Color(red: 0.60, green: 0.22, blue: 0.62) // violet + case "Vibe": return Color(red: 0.28, green: 0.20, blue: 0.62) // deep indigo case "Compressor": return Color(red: 0.18, green: 0.42, blue: 0.32) // forest green case "Mutant": return Color(red: 0.70, green: 0.12, blue: 0.48) // magenta / plum case "Auto-Wah": return Color(red: 0.80, green: 0.62, blue: 0.10) // gold diff --git a/Tests/LyrebirdShoeGazeTests/VibePedalTests.swift b/Tests/LyrebirdShoeGazeTests/VibePedalTests.swift new file mode 100644 index 0000000..899f1be --- /dev/null +++ b/Tests/LyrebirdShoeGazeTests/VibePedalTests.swift @@ -0,0 +1,104 @@ +// VibePedalTests.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("VibePedal") +struct VibePedalTests { + + /// Renders the test loop through a vibe pedal configured by `configure`, returning stereo samples. + private func render(configure: (VibePedal) -> Void) throws -> [Float] { + let renderDuration: Double = 0.2 + let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration) + 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: VibePedal = VibePedal(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) + } + + /// Sum of squared differences over a mid-render window, guarding on length. + private func windowSSD(_ a: [Float], _ b: [Float]) -> Double { + let skip: Int = 1024 + let window: Int = 2048 + guard a.count >= skip + window, b.count >= skip + window else { return 0 } + let aw: ArraySlice = a[skip..<(skip + window)] + let bw: ArraySlice = b[skip..<(skip + window)] + return zip(aw, bw).reduce(0.0) { acc, pair in + let d: Double = Double(pair.0 - pair.1) + return acc + d * d + } + } + + @Test func buildsAndProducesNonSilentOutput() throws { + let samples: [Float] = try render { _ in } + #expect(!samples.isEmpty) + #expect(hasNonSilentOutput(samples), "VibePedal produced silence") + } + + @Test func speedChangesOutput() throws { + let slow: [Float] = try render { $0.speed = 1.0 } + let fast: [Float] = try render { $0.speed = 8.0 } + #expect(hasNonSilentOutput(slow)) + #expect(hasNonSilentOutput(fast)) + #expect(windowSSD(slow, fast) > 0, "vibe speed did not change output") + } + + @Test func intensityChangesOutput() throws { + let shallow: [Float] = try render { $0.intensity = 0.1 } + let deep: [Float] = try render { $0.intensity = 0.7 } + #expect(windowSSD(shallow, deep) > 0, "vibe intensity did not change output") + } + + @Test func modeChangesOutput() throws { + let chorus: [Float] = try render { $0.mode = 0.0 } + let vibrato: [Float] = try render { $0.mode = 1.0 } + #expect(hasNonSilentOutput(chorus)) + #expect(hasNonSilentOutput(vibrato)) + #expect(windowSSD(chorus, vibrato) > 0, "chorus and vibrato modes produced identical output") + } + + @Test func exposesSpeedIntensityKnobsAndModeSwitch() { + let pedal: VibePedal = VibePedal() + #expect(pedal.effectKnobs.map { $0.label } == ["Speed", "Intensity"]) + #expect(pedal.effectSwitches.map { $0.label } == ["Mode"]) + #expect(pedal.effectSwitches.first?.options.map { $0.title } == ["Chorus", "Vibrato"]) + } + + @Test func stateRoundTripsThroughPreset() { + let pedal: VibePedal = VibePedal() + pedal.speed = 6.5 + pedal.intensity = 0.42 + pedal.mode = 1.0 + + let state: PedalState = pedal.captureState() + let restored: VibePedal = VibePedal() + restored.applyState(state) + + #expect(restored.speed == 6.5) + #expect(restored.intensity == 0.42) + #expect(restored.mode == 1.0) + } +}