Add Granulator and Auto Granulator pedals; color-code + filter pedal picker
- StereoGranulator generator: records mono input into a circular buffer and replays overlapping Hann-windowed grains, each randomly panned by `spread` (0 = centred, 1 = full field). Voice pool + control-rate grain size / overlap / spread, all pre-allocated; inlined xorshift64 for grain pans. - GranulatorPedal (.widener): Grain / Overlap / Spread. - AutoGranulatorPedal (.widener): grain size tracks input level via AmplitudeFollower → LinLin, with a Response switch (Loud→Short / Loud→Long) selected by a CrossFade. Min/Max Grain / Overlap / Spread. - Pedal picker (PedalPaletteView): cards colour-coded by a new PedalCategory (Gain/Dynamics/EQ&Filter/Modulation/Pitch/Delay/Reverb/Texture) plus a "filter by type" menu defaulting to All. Tests: generator (seeded determinism + stereo-spread L/R separation) and both pedals (build/non-silent, param/response changes, knobs, registry, preset round-trip). Suite 271. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
// AutoGranulatorPedalTests.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("AutoGranulatorPedal")
|
||||
struct AutoGranulatorPedalTests {
|
||||
|
||||
private func render(
|
||||
configure: (AutoGranulatorPedal) -> 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: 2)
|
||||
defer {
|
||||
engine.busAllocator.releaseAudioBus(srcBus)
|
||||
engine.busAllocator.releaseAudioBus(dstBus)
|
||||
}
|
||||
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let pedal: AutoGranulatorPedal = AutoGranulatorPedal(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
|
||||
}
|
||||
}
|
||||
|
||||
// Small min/max grains so audible output (which trails the write head by one grain) fills the
|
||||
// reader's 4096-frame window.
|
||||
|
||||
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||
let samples: [Float] = try render { pedal in pedal.minGrain = 0.01; pedal.maxGrain = 0.03 }
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "auto granulator output was silent")
|
||||
}
|
||||
|
||||
@Test func responseSwitchChangesOutput() throws {
|
||||
let loudShort: [Float] = try render { pedal in pedal.minGrain = 0.008; pedal.maxGrain = 0.02; pedal.response = 0.0; pedal.mix = 1.0 }
|
||||
let loudLong: [Float] = try render { pedal in pedal.minGrain = 0.008; pedal.maxGrain = 0.02; pedal.response = 1.0; pedal.mix = 1.0 }
|
||||
#expect(hasNonSilentOutput(loudLong), "flipped-response granulator was silent")
|
||||
#expect(totalSSD(loudShort, loudLong) > 0, "flipping the response did not change the output")
|
||||
}
|
||||
|
||||
@Test func exposesKnobsAndResponseSwitch() throws {
|
||||
let pedal: AutoGranulatorPedal = AutoGranulatorPedal()
|
||||
#expect(pedal.effectKnobs.map { $0.label } == ["Min Grain", "Max Grain", "Overlap", "Spread"])
|
||||
#expect(pedal.effectSwitches.map { $0.label } == ["Response"])
|
||||
#expect(pedal.effectSwitches.first?.options.map { $0.title } == ["Loud→Short", "Loud→Long"])
|
||||
}
|
||||
|
||||
@Test func presetRoundTripPreservesResponse() throws {
|
||||
let pedal: AutoGranulatorPedal = AutoGranulatorPedal()
|
||||
pedal.response = 1.0
|
||||
pedal.minGrain = 0.03
|
||||
let state: PedalState = pedal.captureState()
|
||||
|
||||
let restored: AutoGranulatorPedal = AutoGranulatorPedal()
|
||||
restored.applyState(state)
|
||||
#expect(restored.response == 1.0)
|
||||
#expect(restored.minGrain == 0.03)
|
||||
}
|
||||
|
||||
@Test func registeredInBuiltInRegistry() throws {
|
||||
let pedal: Pedal? = PedalRegistry.makePedal(type: "Auto Granulator")
|
||||
#expect(pedal is AutoGranulatorPedal)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// GranulatorPedalTests.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("GranulatorPedal")
|
||||
struct GranulatorPedalTests {
|
||||
|
||||
private func render(
|
||||
configure: (GranulatorPedal) -> 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: 2)
|
||||
defer {
|
||||
engine.busAllocator.releaseAudioBus(srcBus)
|
||||
engine.busAllocator.releaseAudioBus(dstBus)
|
||||
}
|
||||
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let pedal: GranulatorPedal = GranulatorPedal(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
|
||||
}
|
||||
}
|
||||
|
||||
// Small grains so audible output (which trails the write head by one grain) fills the reader's
|
||||
// 4096-frame window rather than starting after a long grain's worth of silence.
|
||||
|
||||
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||
let samples: [Float] = try render { pedal in pedal.grain = 0.02 }
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "granulator output was silent")
|
||||
}
|
||||
|
||||
@Test func spreadChangesOutput() throws {
|
||||
let mono: [Float] = try render { pedal in pedal.grain = 0.01; pedal.spread = 0.0; pedal.mix = 1.0 }
|
||||
let wide: [Float] = try render { pedal in pedal.grain = 0.01; pedal.spread = 1.0; pedal.mix = 1.0 }
|
||||
#expect(hasNonSilentOutput(wide), "spread granulator was silent")
|
||||
#expect(totalSSD(mono, wide) > 0, "changing spread did not change the channel output")
|
||||
}
|
||||
|
||||
@Test func grainSizeChangesOutput() throws {
|
||||
let small: [Float] = try render { pedal in pedal.grain = 0.01; pedal.mix = 1.0 }
|
||||
let large: [Float] = try render { pedal in pedal.grain = 0.04; pedal.mix = 1.0 }
|
||||
#expect(totalSSD(small, large) > 0, "changing grain size did not change the output")
|
||||
}
|
||||
|
||||
@Test func exposesGrainOverlapSpreadKnobs() throws {
|
||||
let pedal: GranulatorPedal = GranulatorPedal()
|
||||
#expect(pedal.effectKnobs.map { $0.label } == ["Grain", "Overlap", "Spread"])
|
||||
}
|
||||
|
||||
@Test func registeredInBuiltInRegistry() throws {
|
||||
let pedal: Pedal? = PedalRegistry.makePedal(type: "Granulator")
|
||||
#expect(pedal is GranulatorPedal)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// StereoGranulatorTests.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("StereoGranulator")
|
||||
struct StereoGranulatorTests {
|
||||
|
||||
/// Minimal synth: a sine through a seeded `StereoGranulator`, routing one of its two channels
|
||||
/// to a mono bus so the offline render captures that channel's content.
|
||||
private final class GranSynth: SynthesizerBase {
|
||||
private let channel: Int
|
||||
private let spread: Double
|
||||
private let seed: UInt64
|
||||
private let outBus: Int
|
||||
|
||||
init(channel: Int, spread: Double, seed: UInt64, outBus: Int) {
|
||||
self.channel = channel
|
||||
self.spread = spread
|
||||
self.seed = seed
|
||||
self.outBus = outBus
|
||||
super.init()
|
||||
}
|
||||
|
||||
override func build() {
|
||||
let osc: OscSin.Audio = OscSin.Audio(freq: 220.0)
|
||||
let gran: StereoGranulator = StereoGranulator(
|
||||
input: osc,
|
||||
maxGrainSize: 0.2,
|
||||
grainSize: 0.05,
|
||||
overlap: 4.0,
|
||||
spread: spread,
|
||||
sampleRate: 44100.0,
|
||||
seed: seed
|
||||
)
|
||||
output(bus: outBus, source: channel == 0 ? gran.left : gran.right)
|
||||
}
|
||||
}
|
||||
|
||||
private func renderChannel(_ channel: Int, spread: Double, seed: UInt64) 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: GranSynth = GranSynth(channel: channel, spread: spread, seed: seed, 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 producesNonSilentOutput() throws {
|
||||
let samples: [Float] = try renderChannel(0, spread: 0.7, seed: 7)
|
||||
#expect(hasNonSilentOutput(samples), "granulator output was silent")
|
||||
}
|
||||
|
||||
@Test func deterministicForAFixedSeed() throws {
|
||||
let a: [Float] = try renderChannel(0, spread: 1.0, seed: 7)
|
||||
let b: [Float] = try renderChannel(0, spread: 1.0, seed: 7)
|
||||
#expect(totalSSD(a, b) == 0.0, "same seed must produce identical output")
|
||||
}
|
||||
|
||||
@Test func zeroSpreadCentersBothChannels() throws {
|
||||
// spread 0 → every grain pans to centre → left and right channels are identical.
|
||||
let left: [Float] = try renderChannel(0, spread: 0.0, seed: 7)
|
||||
let right: [Float] = try renderChannel(1, spread: 0.0, seed: 7)
|
||||
#expect(totalSSD(left, right) == 0.0, "zero spread should center grains (L == R)")
|
||||
}
|
||||
|
||||
@Test func fullSpreadSeparatesChannels() throws {
|
||||
// spread 1 → grains scatter → left and right differ.
|
||||
let left: [Float] = try renderChannel(0, spread: 1.0, seed: 7)
|
||||
let right: [Float] = try renderChannel(1, spread: 1.0, seed: 7)
|
||||
#expect(hasNonSilentOutput(left) && hasNonSilentOutput(right), "spread channels were silent")
|
||||
#expect(totalSSD(left, right) > 0.0, "full spread should separate L and R")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user