Add Chorus, Sustainer, Ring Modulator pedals + pedal-info UI
Pedals (each registered, with PedalType static, enclosure color, palette order, summary, and tests): - Chorus: true-stereo widener (two anti-phase modulated delay lines), distinct from the mono-summed Modulation chorus. - Sustainer: one-knob compressor (sustain drives threshold/ratio/makeup via LinLin) + tone low-pass. - Ring Modulator: dry × tunable sine carrier. Pedal-info UI: - Pedal.summary (open var, overridden by all 21 pedals; mandatory going forward). - PedalRegistry.summary(for:) for the picker. - PedalPaletteView rows show the summary as a subtitle. - PedalView gains an ⓘ button → PedalInfoView sheet showing the description and the effect controls (knobs/sliders/switches) with ranges/options — excludes the common Mix/Level/bypass. Tests: per-pedal build/param-change/knob-list; every built-in pedal has a non-empty summary; info excludes common controls. 183 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
// ChorusPedalTests.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("ChorusPedal")
|
||||
struct ChorusPedalTests {
|
||||
|
||||
private func render(configure: (ChorusPedal) -> Void = { _ in }) throws -> [Float] {
|
||||
let renderDuration: Double = 0.1
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64)
|
||||
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: ChorusPedal = ChorusPedal(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 ssd(_ a: [Float], _ b: [Float]) -> Double {
|
||||
let skip: Int = 2048, window: Int = 2048
|
||||
guard a.count >= skip + window, b.count >= skip + window else { return 0 }
|
||||
return zip(a[skip..<(skip + window)], b[skip..<(skip + window)]).reduce(0.0) { acc, pair in
|
||||
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||
}
|
||||
}
|
||||
|
||||
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||
let samples: [Float] = try render()
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "ChorusPedal produced silence")
|
||||
}
|
||||
|
||||
@Test func rateChangesOutput() throws {
|
||||
let slow: [Float] = try render { $0.rate = 0.1 }
|
||||
let fast: [Float] = try render { $0.rate = 5.0 }
|
||||
#expect(hasNonSilentOutput(slow) && hasNonSilentOutput(fast))
|
||||
#expect(ssd(slow, fast) > 0, "rate had no effect on output")
|
||||
}
|
||||
|
||||
@Test func depthChangesOutput() throws {
|
||||
let shallow: [Float] = try render { $0.depth = 0.0005 }
|
||||
let deep: [Float] = try render { $0.depth = 0.008 }
|
||||
#expect(ssd(shallow, deep) > 0, "depth had no effect on output")
|
||||
}
|
||||
|
||||
@Test func leftAndRightVoicesDiffer() throws {
|
||||
// The point of the widener: anti-phase LFOs make the two voices distinct. Activate the
|
||||
// right channel (which a stereo board region does via PedalBoard.add) by setting
|
||||
// `outputBusRight`, route each board bus to a separate hardware channel, and compare.
|
||||
let renderDuration: Double = 0.1
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let dstL: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let dstR: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
defer {
|
||||
engine.busAllocator.releaseAudioBus(srcBus)
|
||||
engine.busAllocator.releaseAudioBus(dstL)
|
||||
engine.busAllocator.releaseAudioBus(dstR)
|
||||
}
|
||||
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index)
|
||||
let pedal: ChorusPedal = ChorusPedal(inputBus: srcBus.index, outputBus: dstL.index)
|
||||
pedal.outputBusRight = dstR.index // emulate the stereo region a board would create
|
||||
let master: StereoSplitTestMaster = StereoSplitTestMaster(left: dstL.index, right: dstR.index)
|
||||
try engine.add(source)
|
||||
try engine.add(pedal, position: NodePosition.after(source))
|
||||
try engine.add(master, position: NodePosition.after(pedal))
|
||||
try engine.start()
|
||||
|
||||
// readStereoCAF returns interleaved [L, R, L, R, …]; even = left voice, odd = right voice.
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
let skipFrames: Int = 2048
|
||||
let windowFrames: Int = 2048
|
||||
guard samples.count >= 2 * (skipFrames + windowFrames) else { return }
|
||||
|
||||
var lefts: [Float] = []
|
||||
var rights: [Float] = []
|
||||
for frame: Int in skipFrames ..< (skipFrames + windowFrames) {
|
||||
lefts.append(samples[2 * frame])
|
||||
rights.append(samples[2 * frame + 1])
|
||||
}
|
||||
#expect(hasNonSilentOutput(lefts) && hasNonSilentOutput(rights), "a chorus voice was silent")
|
||||
|
||||
let ssdLR: Double = zip(lefts, rights).reduce(0.0) { acc, pair in
|
||||
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||
}
|
||||
#expect(ssdLR > 0, "left and right chorus voices are identical — no stereo width")
|
||||
}
|
||||
}
|
||||
|
||||
/// Routes two mono board buses to hardware left (bus 0) and right (bus 1) so a stereo widener's
|
||||
/// channels can be captured separately by `readStereoCAF`.
|
||||
@MainActor
|
||||
private final class StereoSplitTestMaster: SynthesizerBase {
|
||||
private let left: Int
|
||||
private let right: Int
|
||||
|
||||
init(left: Int, right: Int) {
|
||||
self.left = left
|
||||
self.right = right
|
||||
super.init()
|
||||
}
|
||||
|
||||
override func build() {
|
||||
output(bus: 0, source: input(bus: left))
|
||||
output(bus: 1, source: input(bus: right))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// PedalInfoTests.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("Pedal info")
|
||||
struct PedalInfoTests {
|
||||
|
||||
@Test func everyBuiltInPedalHasASummary() throws {
|
||||
for type: String in PedalRegistry.builtIn.keys {
|
||||
let pedal: Pedal? = PedalRegistry.makePedal(type: type)
|
||||
#expect(pedal != nil, "registry could not build \(type)")
|
||||
let summary: String = pedal?.summary ?? ""
|
||||
#expect(!summary.isEmpty, "\(type) has an empty summary — every pedal must set one")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func registrySummaryHelperMatchesInstance() throws {
|
||||
#expect(PedalRegistry.summary(for: "Overdrive") == OverdrivePedal().summary)
|
||||
#expect(PedalRegistry.summary(for: "Ring Modulator") == RingModulatorPedal().summary)
|
||||
#expect(PedalRegistry.summary(for: "Nope") == "")
|
||||
}
|
||||
|
||||
@Test func effectControlsExcludeCommonControls() throws {
|
||||
// The info panel lists effect controls only; the common Mix / Level / bypass live in the
|
||||
// base `Pedal` and must never appear in effectKnobs/effectSliders/effectSwitches.
|
||||
let pedal: GraphicEQPedal = GraphicEQPedal()
|
||||
let effectLabels: [String] =
|
||||
pedal.effectKnobs.map { $0.label }
|
||||
+ pedal.effectSliders.map { $0.label }
|
||||
+ pedal.effectSwitches.map { $0.label }
|
||||
#expect(!effectLabels.contains("Mix"))
|
||||
#expect(!effectLabels.contains("Level"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// RingModulatorPedalTests.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("RingModulatorPedal")
|
||||
struct RingModulatorPedalTests {
|
||||
|
||||
private func render(frequency: Double) throws -> [Float] {
|
||||
let renderDuration: Double = 0.1
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64)
|
||||
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: RingModulatorPedal = RingModulatorPedal(inputBus: srcBus.index, outputBus: dstBus.index)
|
||||
pedal.frequency = frequency
|
||||
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)
|
||||
}
|
||||
|
||||
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||
let samples: [Float] = try render(frequency: 220.0)
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "RingModulatorPedal produced silence")
|
||||
}
|
||||
|
||||
@Test func frequencyChangesOutput() throws {
|
||||
let low: [Float] = try render(frequency: 100.0)
|
||||
let high: [Float] = try render(frequency: 800.0)
|
||||
#expect(hasNonSilentOutput(low) && hasNonSilentOutput(high))
|
||||
|
||||
let skip: Int = 1024, window: Int = 2048
|
||||
guard low.count >= skip + window, high.count >= skip + window else { return }
|
||||
let ssd: Double = zip(low[skip..<(skip + window)], high[skip..<(skip + window)]).reduce(0.0) { acc, pair in
|
||||
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||
}
|
||||
#expect(ssd > 0, "carrier frequency had no effect on output")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// SustainerPedalTests.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("SustainerPedal")
|
||||
struct SustainerPedalTests {
|
||||
|
||||
private func render(configure: (SustainerPedal) -> Void = { _ in }) throws -> [Float] {
|
||||
let renderDuration: Double = 0.1
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64)
|
||||
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: SustainerPedal = SustainerPedal(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)
|
||||
}
|
||||
|
||||
@Test func buildsAndProducesNonSilentOutput() throws {
|
||||
let samples: [Float] = try render()
|
||||
#expect(!samples.isEmpty)
|
||||
#expect(hasNonSilentOutput(samples), "SustainerPedal produced silence")
|
||||
}
|
||||
|
||||
@Test func exposesSustainAndToneKnobs() throws {
|
||||
let pedal: SustainerPedal = SustainerPedal()
|
||||
#expect(pedal.effectKnobs.map { $0.label } == ["Sustain", "Tone"])
|
||||
}
|
||||
|
||||
@Test func sustainAmountChangesOutput() throws {
|
||||
// Min vs max sustain drive the compressor very differently → measurably different output.
|
||||
let gentle: [Float] = try render { $0.sustain = 0.0 }
|
||||
let squashed: [Float] = try render { $0.sustain = 10.0 }
|
||||
#expect(hasNonSilentOutput(gentle) && hasNonSilentOutput(squashed))
|
||||
|
||||
let skip: Int = 1024, window: Int = 2048
|
||||
guard gentle.count >= skip + window, squashed.count >= skip + window else { return }
|
||||
let ssd: Double = zip(gentle[skip..<(skip + window)], squashed[skip..<(skip + window)]).reduce(0.0) { acc, pair in
|
||||
let d: Double = Double(pair.0 - pair.1); return acc + d * d
|
||||
}
|
||||
#expect(ssd > 0, "sustain knob had no effect on output")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user