Add regenerative Shimmer Reverb pedal and ShimmerReverb generator

New RT-safe ShimmerReverb generator: a damped feedback tank with a
two-grain, 50%-overlap, Hann-windowed octave-up reader INSIDE the feedback
path, so the pitched tail recirculates into an ascending wash (true
regenerative shimmer, not a one-shot parallel pitch-into-reverb). Two
series Schroeder allpasses diffuse the input; a per-sample safety clamp +
denormal flush bound the loop. Buffers pre-allocated for maxDelay + grain;
Hann table precomputed at init; size/decay/shimmer/damp read at control
rate.

ShimmerReverbPedal wraps it (Size/Decay/Shimmer/Damp), registered with
enclosure color + palette slot. Tests: generator silent-in→silent-out,
decay-changes-tail; pedal build/non-silent, shimmer-changes-output, knobs,
preset round-trip, registry. Suite 254.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-27 22:00:00 -07:00
parent 077a8ad9f0
commit 17f74a4ede
9 changed files with 540 additions and 2615 deletions
@@ -0,0 +1,254 @@
// ShimmerReverb.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
import LyrebirdSynth
/// Shared zero-fill fallback block, allocated once at module load, so the RT path never allocates.
private let shimmerReverbZeroBlock: [Double] = makeSampleBuffer()
/// Regenerative shimmer reverb: a damped feedback tank with an octave-up grain reader **inside**
/// the feedback path, so the pitched-up tail recirculates and the shimmer builds and sustains
/// (rather than the one-shot parallel pitch-into-reverb approximation).
///
/// Signal path per sample:
/// ```
/// input → 2 series Schroeder allpasses (diffusion) ─┐
/// ▼
/// tank delay (size) → damping one-pole → ┬─────────→ output (wet tail)
/// │
/// octave-up grains read from the tank ───┤ (× shimmer)
/// ▼
/// feedback = decay·damped + shimmer·pitched → written back into the tank
/// ```
///
/// The octave-up is a two-grain, 50%-overlap, Hann-windowed reader running at 2× over the tank
/// buffer (a tape-style pitch raise). A per-sample safety clamp + denormal flush keep the loop
/// bounded even at high `decay` / `shimmer`.
///
/// `size`, `decay`, `shimmer`, and `damp` are read at control rate (once per block). Output is mono.
///
/// - Important: All buffers are pre-allocated at `init` for `maxDelay` seconds plus the grain
/// length — the RT path never allocates or resizes.
///
/// - Parameters:
/// - input: Audio-rate signal to reverberate.
/// - maxDelay: Maximum tank delay in seconds; sizes the pre-allocated buffer.
/// - size: Tank delay in seconds. Control rate; clamped to `[0.005, maxDelay]`.
/// - decay: Feedback gain (tail length). Control rate; clamped to `[0, 0.92]`.
/// - shimmer: Octave-up feedback amount. Control rate; clamped to `[0, 0.85]`.
/// - damp: High-frequency damping in the feedback `[0, 1]` (0 = bright, 1 = dark). Control rate.
/// - sampleRate: Sample rate used to size buffers and convert seconds → frames; match the engine.
public final class ShimmerReverb: GeneratorBase, AudioGenerator {
// MARK: - Inputs
let _input: any ValidGeneratorInput
let _inputIsGenerator: Bool
let _size: any ValidGeneratorInput
let _decay: any ValidGeneratorInput
let _shimmer: any ValidGeneratorInput
let _damp: any ValidGeneratorInput
// MARK: - Buffers + state
/// Tank delay/grain buffer (circular), length `_bufLen`.
private var _tank: [Double]
/// Two Schroeder input-diffusion allpass buffers.
private var _allpassA: [Double]
private var _allpassB: [Double]
/// Precomputed Hann window over one grain, length `_grainFrames`.
private var _hann: [Double]
private let _bufLen: Int
private let _grainFrames: Int
private let _maxDelayFrames: Int
private let _allpassALen: Int
private let _allpassBLen: Int
private var _writePos: Int = 0
private var _allpassAPos: Int = 0
private var _allpassBPos: Int = 0
private var _grainCounter: Int = 0
private var _dampState: Double = 0.0
// MARK: - Constants
private let minSizeSeconds: Double = 0.005
private let maxDecay: Double = 0.92
private let maxShimmer: Double = 0.85
private let grainSeconds: Double = 0.05
/// Schroeder allpass coefficient and (prime-ish) lengths in samples for input diffusion.
private let allpassGain: Double = 0.7
private let allpassAFrames: Int = 142
private let allpassBFrames: Int = 107
/// Hard safety bound on the recirculated value — prevents runaway / NaN at extreme settings.
private let safetyClamp: Double = 8.0
/// Below this magnitude feedback state is flushed to zero (denormal guard).
private let denormalFloor: Double = 1.0e-15
// MARK: - Init
public init(
input: any ValidGeneratorInput,
maxDelay: Double,
size: any ValidGeneratorInput,
decay: any ValidGeneratorInput,
shimmer: any ValidGeneratorInput,
damp: any ValidGeneratorInput,
sampleRate: Double
) {
let resolvedInput: any ValidGeneratorInput = input._resolvedInput()
_input = resolvedInput
_inputIsGenerator = resolvedInput is any Generator
_size = size._resolvedInput()
_decay = decay._resolvedInput()
_shimmer = shimmer._resolvedInput()
_damp = damp._resolvedInput()
let maxFrames: Int = max(1, Int((maxDelay * sampleRate).rounded()))
let grain: Int = max(2, Int((grainSeconds * sampleRate).rounded()))
_maxDelayFrames = maxFrames
_grainFrames = grain
// Buffer holds the deepest tank read plus a full grain look-back, with headroom.
_bufLen = maxFrames + grain + 2
_allpassALen = allpassAFrames
_allpassBLen = allpassBFrames
_tank = [Double](repeating: 0.0, count: _bufLen)
_allpassA = [Double](repeating: 0.0, count: allpassAFrames)
_allpassB = [Double](repeating: 0.0, count: allpassBFrames)
// Precompute the Hann window for the grain (off the RT thread).
var hann: [Double] = [Double](repeating: 0.0, count: grain)
let twoPi: Double = 2.0 * Double.pi
for i: Int in 0..<grain {
hann[i] = 0.5 - 0.5 * cos(twoPi * Double(i) / Double(grain))
}
_hann = hann
super.init()
}
// MARK: - Render
public func _computeSamples(
graph: SynthGraph,
count: Int
) -> [[Double]] {
_checkCount(count)
guard count > 0 else { return _result }
let sampleRate: Double = graph.engine.sampleRate
let sizeSeconds: Double = _size.floatValue(graph: graph)
let decay: Double = min(max(_decay.floatValue(graph: graph), 0.0), maxDecay)
let shimmer: Double = min(max(_shimmer.floatValue(graph: graph), 0.0), maxShimmer)
let damp: Double = min(max(_damp.floatValue(graph: graph), 0.0), 1.0)
let minFrames: Int = max(1, Int((minSizeSeconds * sampleRate).rounded()))
let sizeFrames: Int = min(max(Int((sizeSeconds * sampleRate).rounded()), minFrames), _maxDelayFrames)
let halfGrain: Int = _grainFrames / 2
let inputSamples: [Double] = _inputIsGenerator
? (_input.calculatedSamples(graph: graph, count: count).first ?? shimmerReverbZeroBlock)
: shimmerReverbZeroBlock
let inputCount: Int = inputSamples.count
let inputScalar: Double = _inputIsGenerator ? 0.0 : _input.floatValue(graph: graph)
var writePos: Int = _writePos
var grainCounter: Int = _grainCounter
var dampState: Double = _dampState
var allpassAPos: Int = _allpassAPos
var allpassBPos: Int = _allpassBPos
_tank.withUnsafeMutableBufferPointer { tankBuffer in
_allpassA.withUnsafeMutableBufferPointer { apABuffer in
_allpassB.withUnsafeMutableBufferPointer { apBBuffer in
_hann.withUnsafeBufferPointer { hannBuffer in
_result[0].withUnsafeMutableBufferPointer { outBuffer in
guard let tank: UnsafeMutablePointer<Double> = tankBuffer.baseAddress,
let apA: UnsafeMutablePointer<Double> = apABuffer.baseAddress,
let apB: UnsafeMutablePointer<Double> = apBBuffer.baseAddress,
let hann: UnsafePointer<Double> = hannBuffer.baseAddress,
let out: UnsafeMutablePointer<Double> = outBuffer.baseAddress
else { return }
for i: Int in 0..<count {
let x: Double = _inputIsGenerator
? (i < inputCount ? inputSamples[i] : 0.0)
: inputScalar
// Input diffusion: two series Schroeder allpasses.
let diffused: Double = ShimmerReverb.allpass(
ShimmerReverb.allpass(x, apA, &allpassAPos, _allpassALen, allpassGain),
apB, &allpassBPos, _allpassBLen, allpassGain
)
// Delayed tank read → one-pole damping (HF absorption).
let readTail: Double = tank[ShimmerReverb.wrap(writePos - sizeFrames, _bufLen)]
dampState = dampState + (1.0 - damp) * (readTail - dampState)
let damped: Double = dampState
// Octave-up: two 50%-overlapped Hann grains read at 2× over the tank.
let offsetA: Int = _grainFrames - grainCounter
let phaseB: Int = (grainCounter + halfGrain) % _grainFrames
let offsetB: Int = _grainFrames - phaseB
let pitched: Double =
hann[grainCounter] * tank[ShimmerReverb.wrap(writePos - offsetA, _bufLen)]
+ hann[phaseB] * tank[ShimmerReverb.wrap(writePos - offsetB, _bufLen)]
// Feedback: decayed damped tail + pitched shimmer, plus diffused input.
var writeVal: Double = diffused + decay * damped + shimmer * pitched
if writeVal > safetyClamp { writeVal = safetyClamp }
else if writeVal < -safetyClamp { writeVal = -safetyClamp }
tank[writePos] = writeVal
out[i] = damped
writePos += 1
if writePos >= _bufLen { writePos = 0 }
grainCounter += 1
if grainCounter >= _grainFrames { grainCounter = 0 }
}
if abs(dampState) < denormalFloor { dampState = 0.0 }
}
}
}
}
}
_writePos = writePos
_grainCounter = grainCounter
_dampState = dampState
_allpassAPos = allpassAPos
_allpassBPos = allpassBPos
return _result
}
/// One Schroeder allpass step over a circular buffer; advances `pos`. `y = -g·x + d;
/// buf = x + g·y` where `d` is the delayed sample.
private static func allpass(
_ x: Double,
_ buffer: UnsafeMutablePointer<Double>,
_ pos: inout Int,
_ length: Int,
_ gain: Double
) -> Double {
let delayed: Double = buffer[pos]
let y: Double = -gain * x + delayed
buffer[pos] = x + gain * y
pos += 1
if pos >= length { pos = 0 }
return y
}
/// Wraps `index` into `[0, length)` (handles a single negative wrap, as produced by
/// `writePos - offset` with `offset <= length`).
private static func wrap(_ index: Int, _ length: Int) -> Int {
let m: Int = index % length
return m < 0 ? m + length : m
}
}
+1
View File
@@ -78,6 +78,7 @@ public extension PedalType {
static let pingPong = PedalType("Ping-Pong")
static let reverseDelay = PedalType("Reverse Delay")
static let reverb = PedalType("Reverb")
static let shimmerReverb = PedalType("Shimmer Reverb")
// Pitch & octave
static let octaveSplitter = PedalType("Octave Splitter")
@@ -0,0 +1,100 @@
// ShimmerReverbPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Shimmer reverb — an ambient reverb whose tail rises an octave as it sustains.
///
/// Wraps the ``ShimmerReverb`` generator: a damped feedback tank with an octave-up grain reader
/// inside the feedback path, so the pitched tail regenerates into a glassy, ever-ascending wash.
/// Run fully wet internally; the pedal's `Mix` knob sets the wet/dry blend.
///
/// ## Knobs
/// - `size`: Tank size (delay) in seconds. Range `[0.01, 0.12]`.
/// - `decay`: Tail length (feedback). Range `[0, 0.92]`.
/// - `shimmer`: Octave-up regeneration amount. Range `[0, 0.85]`.
/// - `damp`: High-frequency damping `[0, 1]` (0 = bright, 1 = dark).
public final class ShimmerReverbPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Ambient reverb whose tail climbs an octave as it sustains — glassy, ascending wash."
}
// MARK: - Parameters
/// Tank size (delay) in seconds. Range [0.01, 0.12].
@UIParam public var size: Double = 0.06
/// Tail length (feedback). Range [0, 0.92].
@UIParam public var decay: Double = 0.8
/// Octave-up regeneration amount. Range [0, 0.85].
@UIParam public var shimmer: Double = 0.5
/// High-frequency damping. Range [0, 1].
@UIParam public var damp: Double = 0.4
// MARK: - Constants
/// Default wet/dry blend — reverb sits under the dry signal.
private static let defaultMix: Double = 0.35
/// Maximum tank delay the buffers are allocated for, in seconds.
private let maxDelayTime: Double = 0.12
// MARK: - Ranges
private let sizeRange: ClosedRange<Double> = 0.01 ... 0.12
private let decayRange: ClosedRange<Double> = 0.0 ... 0.92
private let shimmerRange: ClosedRange<Double> = 0.0 ... 0.85
private let dampRange: ClosedRange<Double> = 0.0 ... 1.0
// MARK: - Knobs
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Size", node: $size, range: sizeRange),
PedalKnob(label: "Decay", node: $decay, range: decayRange),
PedalKnob(label: "Shimmer", node: $shimmer, range: shimmerRange),
PedalKnob(label: "Damp", node: $damp, range: dampRange),
]
}
// MARK: - Init
/// Creates a shimmer-reverb 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: "Shimmer Reverb",
inputBus: inputBus,
outputBus: outputBus,
initialMix: ShimmerReverbPedal.defaultMix
)
}
// MARK: - Effect
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
ShimmerReverb(
input: dry,
maxDelay: maxDelayTime,
size: $size,
decay: $decay,
shimmer: $shimmer,
damp: $damp,
sampleRate: sampleRate
)
}
}
@@ -49,6 +49,7 @@ public enum PedalRegistry {
"Harmonizer": { HarmonizerPedal() },
"Ping-Pong": { PingPongDelayPedal() },
"Reverse Delay": { ReverseDelayPedal() },
"Shimmer Reverb": { ShimmerReverbPedal() },
"Limiter": { LimiterPedal() },
"Noise Gate": { NoiseGatePedal() },
"Graphic EQ": { GraphicEQPedal() },
@@ -56,6 +56,7 @@ public struct PedalPaletteView: View {
"Auto-Wah", "Mutant", "Ring Modulator", "Diffuser", "Bitcrusher", "Bass Octaver",
"Octave Splitter", "Harmonizer",
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverse Delay", "Reverb",
"Shimmer Reverb",
]
/// Routing/branching topologies the user can insert into the board.
@@ -20,6 +20,7 @@ private func enclosureColor(for displayName: String) -> Color {
case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust
case "Delay": return Color(red: 0.10, green: 0.55, blue: 0.55) // teal
case "Reverb": return Color(red: 0.30, green: 0.18, blue: 0.65) // indigo
case "Shimmer Reverb": return Color(red: 0.46, green: 0.52, blue: 0.78) // icy periwinkle
case "Modulation": return Color(red: 0.12, green: 0.58, blue: 0.22) // green
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
@@ -0,0 +1,90 @@
// ShimmerReverbPedalTests.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("ShimmerReverbPedal")
struct ShimmerReverbPedalTests {
private func render(
configure: (ShimmerReverbPedal) -> Void
) throws -> [Float] {
let renderDuration: Double = 0.2
let numAudioBuses: Int = 64
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: renderDuration,
numAudioBuses: numAudioBuses
)
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: ShimmerReverbPedal = ShimmerReverbPedal(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)
}
private func totalSSD(_ a: [Float], _ b: [Float]) -> Double {
zip(a, b).reduce(0.0) { acc, pair in
let diff: Double = Double(pair.0 - pair.1)
return acc + diff * diff
}
}
@Test func buildsAndProducesNonSilentOutput() throws {
let samples: [Float] = try render { _ in }
#expect(!samples.isEmpty)
#expect(hasNonSilentOutput(samples), "shimmer reverb output was silent")
}
@Test func shimmerChangesOutput() throws {
let none: [Float] = try render { pedal in pedal.shimmer = 0.0; pedal.decay = 0.8; pedal.mix = 1.0 }
let glassy: [Float] = try render { pedal in pedal.shimmer = 0.8; pedal.decay = 0.8; pedal.mix = 1.0 }
#expect(hasNonSilentOutput(glassy), "shimmered reverb was silent")
#expect(totalSSD(none, glassy) > 0, "changing shimmer did not change the output")
}
@Test func exposesSizeDecayShimmerDampKnobs() throws {
let pedal: ShimmerReverbPedal = ShimmerReverbPedal()
let labels: [String] = pedal.effectKnobs.map { $0.label }
#expect(labels == ["Size", "Decay", "Shimmer", "Damp"])
}
@Test func presetRoundTripPreservesKnobs() throws {
let pedal: ShimmerReverbPedal = ShimmerReverbPedal()
pedal.decay = 0.5
pedal.shimmer = 0.7
let state: PedalState = pedal.captureState()
let restored: ShimmerReverbPedal = ShimmerReverbPedal()
restored.applyState(state)
#expect(restored.decay == 0.5)
#expect(restored.shimmer == 0.7)
}
@Test func registeredInBuiltInRegistry() throws {
let pedal: Pedal? = PedalRegistry.makePedal(type: "Shimmer Reverb")
#expect(pedal is ShimmerReverbPedal)
}
}
@@ -0,0 +1,92 @@
// ShimmerReverbTests.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("ShimmerReverb")
struct ShimmerReverbTests {
/// Minimal synth: an input source through a `ShimmerReverb`, written to a mono bus.
private final class ShimmerSynth: SynthesizerBase {
private let oscFreq: Double?
private let dc: Double
private let size: Double
private let decay: Double
private let shimmer: Double
private let outBus: Int
init(oscFreq: Double?, dc: Double, size: Double, decay: Double, shimmer: Double, outBus: Int) {
self.oscFreq = oscFreq
self.dc = dc
self.size = size
self.decay = decay
self.shimmer = shimmer
self.outBus = outBus
super.init()
}
override func build() {
let source: any ValidGeneratorInput = oscFreq.map { OscSin.Audio(freq: $0) } ?? dc
output(bus: outBus, source: ShimmerReverb(
input: source,
maxDelay: 0.12,
size: size,
decay: decay,
shimmer: shimmer,
damp: 0.4,
sampleRate: 44100.0
))
}
}
private func render(
oscFreq: Double?,
dc: Double,
size: Double = 0.05,
decay: Double,
shimmer: Double
) throws -> [Float] {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1, sampleRate: 44100.0)
defer { try? FileManager.default.removeItem(at: url) }
let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
defer { engine.busAllocator.releaseAudioBus(dstBus) }
let synth: ShimmerSynth = ShimmerSynth(
oscFreq: oscFreq, dc: dc, size: size, decay: decay, shimmer: shimmer, outBus: dstBus.index
)
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
try engine.add(synth)
try engine.add(master, position: NodePosition.after(synth))
try engine.start()
return readStereoCAF(url: url, sampleRate: 44100.0)
}
private func totalSSD(_ a: [Float], _ b: [Float]) -> Double {
zip(a, b).reduce(0.0) { acc, pair in
let diff: Double = Double(pair.0 - pair.1)
return acc + diff * diff
}
}
@Test func silentInputProducesSilence() throws {
// No input energy → the feedback loop has nothing to sustain → output stays at zero.
let samples: [Float] = try render(oscFreq: nil, dc: 0.0, decay: 0.9, shimmer: 0.8)
#expect(!hasNonSilentOutput(samples), "shimmer reverb rang with no input")
}
@Test func decayChangesTheTail() throws {
// Small tank so feedback round-trips compound within the reader's window; different decay
// must change the tail (direction-agnostic — a tuned comb is not monotonic in level).
let low: [Float] = try render(oscFreq: 440.0, dc: 0.0, size: 0.01, decay: 0.1, shimmer: 0.0)
let high: [Float] = try render(oscFreq: 440.0, dc: 0.0, size: 0.01, decay: 0.9, shimmer: 0.0)
#expect(hasNonSilentOutput(high), "decayed tail was silent")
#expect(totalSSD(low, high) > 0, "changing decay did not change the tail")
}
}
-2615
View File
File diff suppressed because it is too large Load Diff