Add stereo Diffuser pedal
A .widener pedal that splits the dry signal into overlapping RBJ band-pass bands and pans each by frequency (low to left, high to right); the spread knob fans the spectrum from mono (spread 0) to a wide diffuse image (spread 1), using linear pan expressed purely as node arithmetic. Registered, with PedalType.diffuser, enclosure color, palette order, summary, and tests (non-silent stereo; L == R at spread 0; L != R at full spread). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@ signal (no hardware needed) or on live guitar through an audio input.
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **21 modeled pedals** across drive, dynamics, EQ/filter, modulation, delay/reverb, and
|
- **22 modeled pedals** across drive, dynamics, EQ/filter, modulation, delay/reverb, and
|
||||||
pitch — see the catalog below.
|
pitch — see the catalog below.
|
||||||
- **Multi-board rigs** — build several boards and a board-mixer bar to **Solo** one (amp-channel
|
- **Multi-board rigs** — build several boards and a board-mixer bar to **Solo** one (amp-channel
|
||||||
style) or **Blend** any subset, each with its own level and a click-free crossfade.
|
style) or **Blend** any subset, each with its own level and a click-free crossfade.
|
||||||
@@ -30,7 +30,7 @@ signal (no hardware needed) or on live guitar through an audio input.
|
|||||||
|---|---|
|
|---|---|
|
||||||
| Drive & dynamics | Overdrive, Fuzz, Compressor, Sustainer, Limiter, Noise Gate |
|
| Drive & dynamics | Overdrive, Fuzz, Compressor, Sustainer, Limiter, Noise Gate |
|
||||||
| EQ & filter | Graphic EQ, Auto-Wah, Mutant, Phaser |
|
| EQ & filter | Graphic EQ, Auto-Wah, Mutant, Phaser |
|
||||||
| Modulation | Tremolo, Modulation, Chorus, Ring Modulator |
|
| Modulation | Tremolo, Modulation, Chorus, Ring Modulator, Diffuser |
|
||||||
| Delay & reverb | Delay, Feedback Delay, Multi-Tap Delay, Ping-Pong, Reverb |
|
| Delay & reverb | Delay, Feedback Delay, Multi-Tap Delay, Ping-Pong, Reverb |
|
||||||
| Pitch & octave | Octave Splitter, Bass Octaver |
|
| Pitch & octave | Octave Splitter, Bass Octaver |
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
- **Sustainer** — one-knob compressor tuned for long, even sustain, with a tone control.
|
- **Sustainer** — one-knob compressor tuned for long, even sustain, with a tone control.
|
||||||
- **Ring Modulator** — multiplies the signal by a tunable sine carrier for metallic / bell /
|
- **Ring Modulator** — multiplies the signal by a tunable sine carrier for metallic / bell /
|
||||||
robotic tones.
|
robotic tones.
|
||||||
|
- **Diffuser** — stereo widener that fans the frequency spectrum across L/R, with a `spread`
|
||||||
|
control from mono to a wide, diffuse image.
|
||||||
|
|
||||||
### Pedal info UI
|
### Pedal info UI
|
||||||
- Every pedal now has a one-line description (`summary`).
|
- Every pedal now has a one-line description (`summary`).
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public extension PedalType {
|
|||||||
static let modulation = PedalType("Modulation")
|
static let modulation = PedalType("Modulation")
|
||||||
static let chorus = PedalType("Chorus")
|
static let chorus = PedalType("Chorus")
|
||||||
static let ringModulator = PedalType("Ring Modulator")
|
static let ringModulator = PedalType("Ring Modulator")
|
||||||
|
static let diffuser = PedalType("Diffuser")
|
||||||
|
|
||||||
// Dynamics (additional)
|
// Dynamics (additional)
|
||||||
static let sustainer = PedalType("Sustainer")
|
static let sustainer = PedalType("Sustainer")
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
// DiffuserPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Stereo diffuser pedal: fans the frequency spectrum across the left and right channels.
|
||||||
|
///
|
||||||
|
/// A `.widener` pedal. The dry signal is split into overlapping frequency bands; each band is
|
||||||
|
/// panned by its centre frequency — lows toward the left, highs toward the right — and the
|
||||||
|
/// `spread` knob sets how far the bands fan out. At `spread = 0` every band sits centre (a mono
|
||||||
|
/// collapse); at `spread = 1` the spectrum is splayed hard across the stereo field, giving a
|
||||||
|
/// wide, diffuse image without time smearing.
|
||||||
|
///
|
||||||
|
/// Signal path (inside `wideEffect(_:)`), per band `k` at position `pos_k ∈ [-1, 1]`:
|
||||||
|
/// ```
|
||||||
|
/// dry → RBJBandPass(freq_k) → ×gainL_k → Σ → left
|
||||||
|
/// → ×gainR_k → Σ → right
|
||||||
|
/// gainL_k = 0.5 − 0.5·pos_k·spread, gainR_k = 0.5 + 0.5·pos_k·spread (linear pan)
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// The wet/dry blend and bypass are handled by the `Pedal` base class.
|
||||||
|
///
|
||||||
|
/// ## Parameters
|
||||||
|
///
|
||||||
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - spread: Stereo spectral spread. `0` = centred (mono), `1` = fully fanned L↔R.
|
||||||
|
/// Range `[0, 1]`. Defaults to `0.6`.
|
||||||
|
public final class DiffuserPedal: Pedal {
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// Stereo spectral spread in [0, 1]. `0` = mono, `1` = full fan.
|
||||||
|
@UIParam public var spread: Double = 0.6
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// Centre pan gain (each band's gain when `spread == 0` or it sits dead-centre).
|
||||||
|
private let centerGain: Double = 0.5
|
||||||
|
|
||||||
|
/// RBJ band-pass width in octaves — wide enough that adjacent bands overlap and recombine.
|
||||||
|
private let bandwidthOctaves: Double = 1.5
|
||||||
|
|
||||||
|
/// The frequency bands and their base stereo positions (low = left, high = right).
|
||||||
|
/// `position ∈ [-1, 1]`; multiplied by `spread` to place the band.
|
||||||
|
private let bands: [(freq: Double, position: Double)] = [
|
||||||
|
(150.0, -1.0),
|
||||||
|
(400.0, -0.5),
|
||||||
|
(1000.0, 0.0),
|
||||||
|
(2500.0, 0.5),
|
||||||
|
(6000.0, 1.0),
|
||||||
|
]
|
||||||
|
|
||||||
|
// MARK: - UI knobs
|
||||||
|
|
||||||
|
private let spreadRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Spread", node: $spread, range: spreadRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Channel topology
|
||||||
|
|
||||||
|
public override var channelKind: PedalChannelKind { .widener }
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a stereo diffuser 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: "Diffuser",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: DiffuserPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
public override var summary: String {
|
||||||
|
"Stereo diffuser that fans the frequency spectrum across the left and right channels."
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
/// Splits the dry signal into frequency bands and pans each across the field by `spread`.
|
||||||
|
///
|
||||||
|
/// - Parameter dry: Dry mono input signal.
|
||||||
|
/// - Returns: The left and right diffused signals.
|
||||||
|
public override func wideEffect(
|
||||||
|
_ dry: any ValidGeneratorInput
|
||||||
|
) -> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) {
|
||||||
|
var left: (any ValidGeneratorInput)?
|
||||||
|
var right: (any ValidGeneratorInput)?
|
||||||
|
|
||||||
|
for band: (freq: Double, position: Double) in bands {
|
||||||
|
let bandPass: RBJBandPass.Audio = RBJBandPass.Audio(
|
||||||
|
input: dry,
|
||||||
|
freq: band.freq,
|
||||||
|
bandwidth: bandwidthOctaves
|
||||||
|
)
|
||||||
|
// Linear pan, fully expressible as node arithmetic (no per-sample trig):
|
||||||
|
// gainL = centerGain − (0.5·position)·spread
|
||||||
|
// gainR = centerGain + (0.5·position)·spread
|
||||||
|
let halfPosition: Double = centerGain * band.position
|
||||||
|
let gainL: any ValidGeneratorInput = ($spread * (-halfPosition)) + centerGain
|
||||||
|
let gainR: any ValidGeneratorInput = ($spread * halfPosition) + centerGain
|
||||||
|
let leftContribution: any ValidGeneratorInput = bandPass * gainL
|
||||||
|
let rightContribution: any ValidGeneratorInput = bandPass * gainR
|
||||||
|
left = left.map { $0 + leftContribution } ?? leftContribution
|
||||||
|
right = right.map { $0 + rightContribution } ?? rightContribution
|
||||||
|
}
|
||||||
|
|
||||||
|
return (left ?? dry, right ?? dry)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,6 +52,7 @@ public enum PedalRegistry {
|
|||||||
"Chorus": { ChorusPedal() },
|
"Chorus": { ChorusPedal() },
|
||||||
"Sustainer": { SustainerPedal() },
|
"Sustainer": { SustainerPedal() },
|
||||||
"Ring Modulator": { RingModulatorPedal() },
|
"Ring Modulator": { RingModulatorPedal() },
|
||||||
|
"Diffuser": { DiffuserPedal() },
|
||||||
]
|
]
|
||||||
|
|
||||||
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public struct PedalPaletteView: View {
|
|||||||
private static let preferredOrder: [String] = [
|
private static let preferredOrder: [String] = [
|
||||||
"Overdrive", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
|
"Overdrive", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz",
|
||||||
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus",
|
"Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus",
|
||||||
"Auto-Wah", "Mutant", "Ring Modulator", "Bass Octaver", "Octave Splitter",
|
"Auto-Wah", "Mutant", "Ring Modulator", "Diffuser", "Bass Octaver", "Octave Splitter",
|
||||||
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverb",
|
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverb",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ private func enclosureColor(for displayName: String) -> Color {
|
|||||||
case "Chorus": return Color(red: 0.16, green: 0.50, blue: 0.64) // aqua
|
case "Chorus": return Color(red: 0.16, green: 0.50, blue: 0.64) // aqua
|
||||||
case "Sustainer": return Color(red: 0.22, green: 0.46, blue: 0.30) // pine green
|
case "Sustainer": return Color(red: 0.22, green: 0.46, blue: 0.30) // pine green
|
||||||
case "Ring Modulator": return Color(red: 0.64, green: 0.30, blue: 0.10) // burnt amber
|
case "Ring Modulator": return Color(red: 0.64, green: 0.30, blue: 0.10) // burnt amber
|
||||||
|
case "Diffuser": return Color(red: 0.34, green: 0.30, blue: 0.62) // periwinkle
|
||||||
default: return Color(red: 0.36, green: 0.36, blue: 0.38) // steel gray
|
default: return Color(red: 0.36, green: 0.36, blue: 0.38) // steel gray
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
// DiffuserPedalTests.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("DiffuserPedal")
|
||||||
|
struct DiffuserPedalTests {
|
||||||
|
|
||||||
|
/// Renders the diffuser as a stereo widener, returning (leftSamples, rightSamples).
|
||||||
|
private func renderStereo(spread: Double) throws -> (left: [Float], right: [Float]) {
|
||||||
|
let renderDuration: Double = 0.1
|
||||||
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64)
|
||||||
|
defer { try? FileManager.default.removeItem(at: url) }
|
||||||
|
|
||||||
|
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dstL: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dstR: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
defer {
|
||||||
|
engine.busAllocator.releaseAudioBus(srcBus)
|
||||||
|
engine.busAllocator.releaseAudioBus(dstL)
|
||||||
|
engine.busAllocator.releaseAudioBus(dstR)
|
||||||
|
}
|
||||||
|
|
||||||
|
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||||
|
let pedal: DiffuserPedal = DiffuserPedal(inputBus: srcBus.index, outputBus: dstL.index)
|
||||||
|
pedal.outputBusRight = dstR.index
|
||||||
|
pedal.spread = spread
|
||||||
|
let master: DiffuserStereoSplitMaster = DiffuserStereoSplitMaster(left: dstL.index, right: dstR.index)
|
||||||
|
try engine.add(source)
|
||||||
|
try engine.add(pedal, position: NodePosition.after(source))
|
||||||
|
try engine.add(master, position: NodePosition.after(pedal))
|
||||||
|
try engine.start()
|
||||||
|
|
||||||
|
let samples: [Float] = readStereoCAF(url: url)
|
||||||
|
let skipFrames: Int = 2048
|
||||||
|
let windowFrames: Int = 2048
|
||||||
|
var left: [Float] = []
|
||||||
|
var right: [Float] = []
|
||||||
|
guard samples.count >= 2 * (skipFrames + windowFrames) else { return ([], []) }
|
||||||
|
for frame: Int in skipFrames ..< (skipFrames + windowFrames) {
|
||||||
|
left.append(samples[2 * frame])
|
||||||
|
right.append(samples[2 * frame + 1])
|
||||||
|
}
|
||||||
|
return (left, right)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func ssd(_ a: [Float], _ b: [Float]) -> Double {
|
||||||
|
zip(a, b).reduce(0.0) { acc, pair in
|
||||||
|
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||||
|
let (left, right): ([Float], [Float]) = try renderStereo(spread: 0.6)
|
||||||
|
#expect(hasNonSilentOutput(left), "diffuser left channel was silent")
|
||||||
|
#expect(hasNonSilentOutput(right), "diffuser right channel was silent")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func zeroSpreadIsMono() throws {
|
||||||
|
// At spread 0 every band sits centre → left and right are identical.
|
||||||
|
let (left, right): ([Float], [Float]) = try renderStereo(spread: 0.0)
|
||||||
|
#expect(hasNonSilentOutput(left))
|
||||||
|
#expect(ssd(left, right) == 0, "spread 0 should collapse to mono (L == R)")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func spreadWidensTheImage() throws {
|
||||||
|
// At full spread the spectrum fans across the field → channels differ.
|
||||||
|
let (left, right): ([Float], [Float]) = try renderStereo(spread: 1.0)
|
||||||
|
#expect(ssd(left, right) > 0, "full spread should make L and R differ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Routes two mono board buses to hardware left (0) and right (1) so a widener's channels can be
|
||||||
|
/// captured separately by `readStereoCAF`.
|
||||||
|
@MainActor
|
||||||
|
private final class DiffuserStereoSplitMaster: SynthesizerBase {
|
||||||
|
private let left: Int
|
||||||
|
private let right: Int
|
||||||
|
|
||||||
|
init(left: Int, right: Int) {
|
||||||
|
self.left = left
|
||||||
|
self.right = right
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func build() {
|
||||||
|
output(bus: 0, source: input(bus: left))
|
||||||
|
output(bus: 1, source: input(bus: right))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user