Add Limiter, Noise Gate, and Graphic EQ pedals + vertical-fader UI control
Three new pedals: - LimiterPedal: linear boost gain stage into a LookAheadLimiter brick-wall ceiling. Reads engine sampleRate injected by PedalBoard.add at build time. - NoiseGatePedal: AmplitudeFollower -> hysteretic Schmidt gate -> LinLin floor map -> Lag smoothing. Tuneable residual floor when the gate is closed. - GraphicEQPedal: five cascaded RBJ filters (low/high shelf + three peaking mids) with per-band dB gains and a linear master output gain. New UI control: - PedalSlider descriptor and Pedal.effectSliders hook, alongside effectKnobs and effectSwitches. - VerticalParameterSlider: a vertical fader bound to a UIParamNode. - PedalView renders the fader bank and widens the enclosure to fit it. Persistence/registry: - PedalState.sliderValues (decodeIfPresent for backward compatibility); capture and apply in Pedal+Preset. - Registry entries and palette ordering for all three pedals. Tests: non-silent builds, limiter ceiling enforcement, gate open/closed/unity floor power ratios, EQ flat output, global-gain scaling, and 6-slider preset round-trip. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
// GraphicEQPedalTests.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("GraphicEQPedal")
|
||||
struct GraphicEQPedalTests {
|
||||
|
||||
/// Renders a `GraphicEQPedal` after applying `configure`, returning the interleaved output.
|
||||
private func render(configure: (GraphicEQPedal) -> Void) throws -> [Float] {
|
||||
let renderDuration: Double = 0.1
|
||||
let sampleRate: Double = 44100.0
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
sampleRate: sampleRate
|
||||
)
|
||||
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: GraphicEQPedal = GraphicEQPedal(
|
||||
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, sampleRate: sampleRate)
|
||||
}
|
||||
|
||||
@Test func flatEQProducesNonSilentOutput() throws {
|
||||
let samples: [Float] = try render { _ in } // all gains 0 dB, unity output
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "Flat EQ produced silence")
|
||||
}
|
||||
|
||||
@Test func publishesSixSliders() throws {
|
||||
let pedal: GraphicEQPedal = GraphicEQPedal()
|
||||
#expect(pedal.effectSliders.count == 6)
|
||||
#expect(pedal.effectSliders.last?.label == "Gain")
|
||||
}
|
||||
|
||||
@Test func globalGainScalesOutput() throws {
|
||||
// The master gain is in dB. +12 dB should be far louder than -12 dB
|
||||
// (24 dB apart ≈ 15.8× amplitude ≈ 250× power).
|
||||
let quiet: [Float] = try render { $0.globalGain = -12.0 }
|
||||
let loud: [Float] = try render { $0.globalGain = 12.0 }
|
||||
|
||||
func power(_ samples: [Float]) -> Double {
|
||||
samples.reduce(0.0) { acc, s in
|
||||
let v: Double = Double(s)
|
||||
return acc + v * v
|
||||
}
|
||||
}
|
||||
let quietPower: Double = power(quiet)
|
||||
let loudPower: Double = power(loud)
|
||||
|
||||
#expect(quietPower > 0, "-12 dB EQ was silent")
|
||||
// Expect well over an order of magnitude more power at +12 dB vs -12 dB.
|
||||
let minPowerRatio: Double = 50.0
|
||||
#expect(
|
||||
loudPower > quietPower * minPowerRatio,
|
||||
"Master dB gain did not scale output: loud=\(loudPower) quiet=\(quietPower)"
|
||||
)
|
||||
}
|
||||
|
||||
@Test func sliderValuesRoundTripThroughPresetState() throws {
|
||||
// Band/global gains live in effectSliders; they must survive captureState/applyState.
|
||||
let source: GraphicEQPedal = GraphicEQPedal()
|
||||
source.lowGain = 6.0
|
||||
source.lowMidGain = -3.0
|
||||
source.midGain = 4.5
|
||||
source.highMidGain = -7.0
|
||||
source.highGain = 2.0
|
||||
source.globalGain = 1.5
|
||||
|
||||
let state: PedalState = source.captureState()
|
||||
#expect(state.sliderValues.count == 6)
|
||||
|
||||
let restored: GraphicEQPedal = GraphicEQPedal()
|
||||
restored.applyState(state)
|
||||
|
||||
let tolerance: Double = 1e-6
|
||||
#expect(abs(restored.lowGain - 6.0) < tolerance)
|
||||
#expect(abs(restored.lowMidGain - (-3.0)) < tolerance)
|
||||
#expect(abs(restored.midGain - 4.5) < tolerance)
|
||||
#expect(abs(restored.highMidGain - (-7.0)) < tolerance)
|
||||
#expect(abs(restored.highGain - 2.0) < tolerance)
|
||||
#expect(abs(restored.globalGain - 1.5) < tolerance)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// LimiterPedalTests.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("LimiterPedal")
|
||||
struct LimiterPedalTests {
|
||||
|
||||
/// Renders a `LimiterPedal` through an offline engine and returns the interleaved output.
|
||||
private func render(
|
||||
boost: Double,
|
||||
ceiling: Double,
|
||||
sampleRate: Double = 44100.0
|
||||
) throws -> [Float] {
|
||||
let renderDuration: Double = 0.1
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
sampleRate: sampleRate
|
||||
)
|
||||
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: LimiterPedal = LimiterPedal(
|
||||
inputBus: srcBus.index,
|
||||
outputBus: dstBus.index
|
||||
)
|
||||
// Match the engine rate so the look-ahead limiter sizes its ring correctly.
|
||||
pedal.sampleRate = sampleRate
|
||||
pedal.boost = boost
|
||||
pedal.ceiling = ceiling
|
||||
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, sampleRate: sampleRate)
|
||||
}
|
||||
|
||||
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||
let samples: [Float] = try render(boost: 2.0, ceiling: 0.95)
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "LimiterPedal produced silence")
|
||||
}
|
||||
|
||||
@Test func outputNeverExceedsCeiling() throws {
|
||||
// Drive hard into the limiter with a low ceiling; the peak must stay at the ceiling.
|
||||
// Downstream Pan2/gain in the master only attenuates, so the recorded peak is a
|
||||
// conservative upper bound on the limiter output peak.
|
||||
let ceiling: Double = 0.5
|
||||
let samples: [Float] = try render(boost: 12.0, ceiling: ceiling)
|
||||
#expect(hasNonSilentOutput(samples), "Driven limiter produced silence")
|
||||
|
||||
// Skip the look-ahead fill window before measuring the peak. The limiter's 5 ms
|
||||
// look-ahead at 44.1 kHz is ~220 frames; 2048 interleaved samples is a comfortable
|
||||
// margin past the window-fill transient.
|
||||
let lookAheadFillSamples: Int = 2048
|
||||
guard samples.count > lookAheadFillSamples else { return }
|
||||
let window: ArraySlice<Float> = samples[lookAheadFillSamples...]
|
||||
let peak: Float = window.reduce(0) { Swift.max($0, abs($1)) }
|
||||
|
||||
let tolerance: Float = 0.05
|
||||
#expect(peak <= Float(ceiling) + tolerance, "Limiter overshot ceiling: peak=\(peak)")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// NoiseGatePedalTests.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("NoiseGatePedal")
|
||||
struct NoiseGatePedalTests {
|
||||
|
||||
/// Renders a `NoiseGatePedal` through an offline engine and returns the interleaved output.
|
||||
private func render(
|
||||
threshold: Double,
|
||||
floor: Double
|
||||
) throws -> [Float] {
|
||||
let renderDuration: Double = 0.1
|
||||
let sampleRate: Double = 44100.0
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: renderDuration,
|
||||
sampleRate: sampleRate
|
||||
)
|
||||
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: NoiseGatePedal = NoiseGatePedal(
|
||||
inputBus: srcBus.index,
|
||||
outputBus: dstBus.index
|
||||
)
|
||||
pedal.threshold = threshold
|
||||
pedal.floor = floor
|
||||
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, sampleRate: sampleRate)
|
||||
}
|
||||
|
||||
/// Sum of squared samples — a proxy for output power.
|
||||
private func power(_ samples: [Float]) -> Double {
|
||||
samples.reduce(0.0) { acc, s in
|
||||
let v: Double = Double(s)
|
||||
return acc + v * v
|
||||
}
|
||||
}
|
||||
|
||||
@Test func openGatePassesSignal() throws {
|
||||
// A threshold of 0 keeps the gate open — the loop signal should pass through.
|
||||
let samples: [Float] = try render(threshold: 0.0, floor: 0.0)
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "Open gate produced silence")
|
||||
}
|
||||
|
||||
@Test func closedGateWithZeroFloorStronglyAttenuates() throws {
|
||||
// An impossibly high threshold keeps the gate closed; with floor 0 the output
|
||||
// should be far quieter than the open-gate render.
|
||||
let openSamples: [Float] = try render(threshold: 0.0, floor: 0.0)
|
||||
let closedSamples: [Float] = try render(threshold: 0.95, floor: 0.0)
|
||||
|
||||
let openPower: Double = power(openSamples)
|
||||
let closedPower: Double = power(closedSamples)
|
||||
|
||||
#expect(openPower > 0, "Open gate render was silent")
|
||||
// Closed gate should suppress nearly all energy.
|
||||
let suppressionFactor: Double = 0.05
|
||||
#expect(
|
||||
closedPower < openPower * suppressionFactor,
|
||||
"Closed gate did not attenuate: open=\(openPower) closed=\(closedPower)"
|
||||
)
|
||||
}
|
||||
|
||||
@Test func unityFloorLeavesSignalUntouched() throws {
|
||||
// floor = 1 means no gating regardless of threshold — output stays present.
|
||||
let samples: [Float] = try render(threshold: 0.95, floor: 1.0)
|
||||
#expect(hasNonSilentOutput(samples), "Unity-floor gate muted the signal")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user