Replace test tone with an E-minor Karplus-Strong arpeggio
TestLoopSource now plays a repeating pluck arpeggio over the open lower four guitar strings (E2, A2, D3, G3) in E minor: one Impulse drives both the KarplusStrong excitation and a Demand/DemandSequence that steps the pitch per pluck. Fixed-seed WhiteNoise exciter keeps the tone deterministic (so two source renders match, e.g. the overdrive bypass-equals-dry test). Adds a sampleRate init param (default 48k) sizing the KS delay line; ShoeGaze.addBoard passes the engine's actual rate. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -9,20 +9,23 @@ import LyrebirdUI
|
||||
|
||||
/// A synthesized test signal source that writes to a target audio bus.
|
||||
///
|
||||
/// Produces two detuned sine oscillators at 110 Hz and 165 Hz — an approximation
|
||||
/// of a guitar's A2 and E3 strings — with a slow amplitude envelope driven by a
|
||||
/// low-frequency sine LFO. This makes the board audible immediately without any
|
||||
/// hardware connection.
|
||||
/// Plays a repeating E-minor arpeggio on a Karplus-Strong plucked string, cycling the open
|
||||
/// pitches of a guitar's lower four strings — E2, A2, D3, G3 — so the board has a musical,
|
||||
/// guitar-like signal to process without any hardware connected. A single ``Impulse`` drives
|
||||
/// both the pluck excitation and a ``Demand``/``DemandSequence`` that advances the pitch one step
|
||||
/// per pluck, keeping note changes locked to the plucks.
|
||||
///
|
||||
/// The output is written to `targetBus` so downstream pedals read it from that bus.
|
||||
/// `TestLoopSource` should be added to the engine **before** the first pedal in the
|
||||
/// chain to ensure signal-order correctness (source evaluates first).
|
||||
/// `TestLoopSource` should be added to the engine **before** the first pedal in the chain to
|
||||
/// ensure signal-order correctness (source evaluates first).
|
||||
///
|
||||
/// ## Parameters
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - targetBus: Audio bus index to write the test signal to. Typically the
|
||||
/// pedalboard's head bus index.
|
||||
/// - targetBus: Audio bus index to write the test signal to. Typically the pedalboard's
|
||||
/// head bus index.
|
||||
/// - sampleRate: Engine sample rate, used to size the Karplus-Strong delay line. Defaults to
|
||||
/// `48000`; the pedalboard passes the engine's actual rate so the pitch is accurate.
|
||||
/// - amplitude: Output amplitude in [0, 1]. Defaults to `0.25`.
|
||||
public final class TestLoopSource: SynthesizerBase {
|
||||
|
||||
@@ -33,44 +36,68 @@ public final class TestLoopSource: SynthesizerBase {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Frequency of the first oscillator in Hz (approximates guitar A2 string).
|
||||
private let freqA: Double = 110.0
|
||||
/// Open pitches of the guitar's lower four strings, in Hz: E2, A2, D3, G3. Arpeggiated in
|
||||
/// order and repeated — an E-minor flavored figure (all four are in E natural minor).
|
||||
private let arpeggioPitches: [Double] = [82.41, 110.00, 146.83, 196.00]
|
||||
|
||||
/// Frequency of the second oscillator in Hz (approximates guitar E3 string, slightly detuned).
|
||||
private let freqB: Double = 165.75
|
||||
/// Plucks per second (the arpeggio step rate).
|
||||
private let pluckRate: Double = 3.0
|
||||
|
||||
/// LFO frequency in Hz for amplitude modulation (slow tremolo).
|
||||
private let lfoFreq: Double = 0.5
|
||||
/// Karplus-Strong feedback gain in [0, 1]; higher = longer sustain (strings ring into the
|
||||
/// next pluck like a real arpeggio).
|
||||
private let feedback: Double = 0.99
|
||||
|
||||
/// LFO depth as a fraction of base amplitude [0, 1].
|
||||
private let lfoDepth: Double = 0.3
|
||||
/// Karplus-Strong one-pole damping coefficient (`0.5` = classic natural damping).
|
||||
private let damping: Double = 0.5
|
||||
|
||||
/// Gain for each individual oscillator before summing. Two oscillators × 0.5 = unity.
|
||||
private let oscGain: Double = 0.5
|
||||
/// Maximum delay time in seconds, sizing the delay line. `0.05 s` covers fundamentals down to
|
||||
/// 20 Hz — well below the lowest arpeggio pitch (E2, ~82 Hz).
|
||||
private let maxDelayTime: Double = 0.05
|
||||
|
||||
/// Fixed seed for the pluck-excitation noise, so the test tone is deterministic and identical
|
||||
/// across instances (two renders of the source produce the same output).
|
||||
private let exciterSeed: UInt64 = 0x5E1E_C7ED_5017_C35A
|
||||
|
||||
// MARK: - Routing
|
||||
|
||||
/// The bus this source writes its output to.
|
||||
private let targetBus: Int
|
||||
|
||||
/// Engine sample rate used to size the Karplus-Strong delay line.
|
||||
private let sampleRate: Double
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a test loop source that writes to `targetBus`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - targetBus: Audio bus index to write the synthesized test signal to.
|
||||
public init(targetBus: Int) {
|
||||
/// - sampleRate: Engine sample rate (sizes the Karplus-Strong delay line). Defaults to `48000`.
|
||||
public init(targetBus: Int, sampleRate: Double = 48_000.0) {
|
||||
self.targetBus = targetBus
|
||||
self.sampleRate = sampleRate
|
||||
super.init()
|
||||
}
|
||||
|
||||
// MARK: - Build
|
||||
|
||||
public override func build() {
|
||||
let oscA: OscSin.Audio = OscSin.Audio(freq: freqA, mul: oscGain)
|
||||
let oscB: OscSin.Audio = OscSin.Audio(freq: freqB, phase: 0.25, mul: oscGain)
|
||||
let lfo: OscSin.Audio = OscSin.Audio(freq: lfoFreq, mul: lfoDepth, add: 1.0 - lfoDepth)
|
||||
let signal: any ValidGeneratorInput = (oscA + oscB) * lfo * $amplitude
|
||||
output(bus: targetBus, source: signal)
|
||||
// One impulse drives both the pluck excitation and the pitch-stepping demand, so each
|
||||
// pluck lands on the next arpeggio note.
|
||||
let pluck: Impulse.Audio = Impulse.Audio(freq: pluckRate)
|
||||
let pitch: Demand.Audio = Demand.Audio(
|
||||
trig: pluck,
|
||||
demand: DemandSequence(values: arpeggioPitches, repeats: -1)
|
||||
)
|
||||
let string: KarplusStrong.Audio = KarplusStrong.Audio(
|
||||
exciter: WhiteNoise.Audio(seed: exciterSeed),
|
||||
trigger: pluck,
|
||||
freq: pitch,
|
||||
feedback: feedback,
|
||||
coef: damping,
|
||||
sampleRate: sampleRate,
|
||||
maxDelayTime: maxDelayTime
|
||||
)
|
||||
output(bus: targetBus, source: string * $amplitude)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,10 @@ public final class ShoeGaze {
|
||||
// Route the input source to the board head bus.
|
||||
switch inputSource {
|
||||
case .testLoop:
|
||||
let source: TestLoopSource = TestLoopSource(targetBus: board.headBus.index)
|
||||
let source: TestLoopSource = TestLoopSource(
|
||||
targetBus: board.headBus.index,
|
||||
sampleRate: engine.sampleRate
|
||||
)
|
||||
// Plain add → head of mainGroup (evaluates before any pedal).
|
||||
try engine.add(source)
|
||||
testLoopSources.append(source)
|
||||
|
||||
Reference in New Issue
Block a user