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:
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user