feat(pedals): limiter Release knob + compressor safety limiter; bump Lyrebird 1.6.4
Consume Lyrebird 1.6.4, which decouples LookAheadLimiter's release time from its look-ahead window. - LimiterPedal: add a Release knob (0.01–0.5 s) wired to the new LookAheadLimiter.releaseTime. A too-fast release modulated the gain within a low-frequency cycle and distorted sustained notes when driven hard. - CompressorPedal: add an opt-in Safety switch (off by default) that inserts a brick-wall LookAheadLimiter after the compressor to catch transient overshoot that could clip the output. Built as both branches with Select picking live; engaging it adds the limiter's short look-ahead delay. Tests cover the new knob/switch exposure, release-time effect, and that the safety limiter caps peaks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,82 @@ struct CompressorPedalTests {
|
||||
#expect(labels == ["Input", "Threshold", "Ratio"])
|
||||
}
|
||||
|
||||
@Test func exposesSafetySwitch() throws {
|
||||
let pedal: CompressorPedal = CompressorPedal()
|
||||
let switchLabels: [String] = pedal.effectSwitches.map { $0.label }
|
||||
#expect(switchLabels == ["Safety"])
|
||||
let optionTitles: [String] = pedal.effectSwitches.first?.options.map { $0.title } ?? []
|
||||
#expect(optionTitles == ["Off", "On"])
|
||||
}
|
||||
|
||||
@Test func safetyLimiterCapsPeaks() throws {
|
||||
// Drive the compressor hard (hot input + makeup gain) so its non-zero attack lets
|
||||
// transients overshoot. With the safety limiter engaged the output peak must stay
|
||||
// near full scale; the two switch states must also produce different output.
|
||||
let renderDuration: Double = 0.1
|
||||
let sampleRate: Double = 44100.0
|
||||
|
||||
func render(safety: Double) throws -> [Float] {
|
||||
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: CompressorPedal = CompressorPedal(
|
||||
inputBus: srcBus.index,
|
||||
outputBus: dstBus.index
|
||||
)
|
||||
pedal.sampleRate = sampleRate
|
||||
pedal.inputGain = 24.0
|
||||
pedal.threshold = -30.0
|
||||
pedal.ratio = 8.0
|
||||
pedal.safetyLimiter = safety
|
||||
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)
|
||||
}
|
||||
|
||||
let off: [Float] = try render(safety: 0.0)
|
||||
let on: [Float] = try render(safety: 1.0)
|
||||
|
||||
#expect(hasNonSilentOutput(off), "safety-off render was silent")
|
||||
#expect(hasNonSilentOutput(on), "safety-on render was silent")
|
||||
|
||||
// Skip the safety limiter's look-ahead fill window before measuring the peak.
|
||||
let lookAheadFillSamples: Int = 2048
|
||||
guard on.count > lookAheadFillSamples else { return }
|
||||
let onWindow: ArraySlice<Float> = on[lookAheadFillSamples...]
|
||||
let onPeak: Float = onWindow.reduce(0) { Swift.max($0, abs($1)) }
|
||||
|
||||
// Safety ceiling is just under full scale; downstream master only attenuates.
|
||||
let ceilingTolerance: Float = 0.05
|
||||
#expect(onPeak <= 1.0 + ceilingTolerance, "safety limiter failed to cap peak: \(onPeak)")
|
||||
|
||||
// The two switch positions must differ.
|
||||
let skip: Int = lookAheadFillSamples
|
||||
let window: Int = 2048
|
||||
guard off.count >= skip + window, on.count >= skip + window else { return }
|
||||
let offWindow: [Float] = Array(off[skip..<(skip + window)])
|
||||
let onWindow2: [Float] = Array(on[skip..<(skip + window)])
|
||||
let ssd: Double = zip(offWindow, onWindow2).reduce(0.0) { acc, pair in
|
||||
let diff: Double = Double(pair.0 - pair.1)
|
||||
return acc + diff * diff
|
||||
}
|
||||
#expect(ssd > 0, "safety switch had no effect on output")
|
||||
}
|
||||
|
||||
@Test func inputGainChangesOutput() throws {
|
||||
// The pre-compression input gain stage must alter the output: boosting the input
|
||||
// drives more of the signal past the threshold, changing the compressed result.
|
||||
|
||||
@@ -18,6 +18,7 @@ struct LimiterPedalTests {
|
||||
private func render(
|
||||
boost: Double,
|
||||
ceiling: Double,
|
||||
release: Double = 0.05,
|
||||
sampleRate: Double = 44100.0
|
||||
) throws -> [Float] {
|
||||
let renderDuration: Double = 0.1
|
||||
@@ -43,6 +44,7 @@ struct LimiterPedalTests {
|
||||
pedal.sampleRate = sampleRate
|
||||
pedal.boost = boost
|
||||
pedal.ceiling = ceiling
|
||||
pedal.release = release
|
||||
let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index)
|
||||
|
||||
try engine.add(source)
|
||||
@@ -78,4 +80,32 @@ struct LimiterPedalTests {
|
||||
let tolerance: Float = 0.05
|
||||
#expect(peak <= Float(ceiling) + tolerance, "Limiter overshot ceiling: peak=\(peak)")
|
||||
}
|
||||
|
||||
@Test func exposesBoostCeilingReleaseKnobs() throws {
|
||||
let pedal: LimiterPedal = LimiterPedal()
|
||||
let labels: [String] = pedal.effectKnobs.map { $0.label }
|
||||
#expect(labels == ["Boost", "Ceiling", "Release"])
|
||||
}
|
||||
|
||||
@Test func releaseChangesOutput() throws {
|
||||
// Same drive and ceiling, different release times: the gain recovers between peaks
|
||||
// at different rates, so the limited output differs. Ceiling still holds for both.
|
||||
let ceiling: Double = 0.4
|
||||
let fast: [Float] = try render(boost: 12.0, ceiling: ceiling, release: 0.01)
|
||||
let slow: [Float] = try render(boost: 12.0, ceiling: ceiling, release: 0.5)
|
||||
|
||||
#expect(hasNonSilentOutput(fast), "fast-release render was silent")
|
||||
#expect(hasNonSilentOutput(slow), "slow-release render was silent")
|
||||
|
||||
let skip: Int = 2048
|
||||
let window: Int = 2048
|
||||
guard fast.count >= skip + window, slow.count >= skip + window else { return }
|
||||
let fastWindow: [Float] = Array(fast[skip..<(skip + window)])
|
||||
let slowWindow: [Float] = Array(slow[skip..<(skip + window)])
|
||||
let ssd: Double = zip(fastWindow, slowWindow).reduce(0.0) { acc, pair in
|
||||
let diff: Double = Double(pair.0 - pair.1)
|
||||
return acc + diff * diff
|
||||
}
|
||||
#expect(ssd > 0, "release time had no effect on limiter output")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user