From 097c38283efe2a4e9d08fc4a354d5e53a8a663ea Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Tue, 24 Nov 2026 14:59:16 -0800 Subject: [PATCH] feat(karplus): extend Free-tune range up to E5 The Free-mode Tune knob now reaches 660 Hz (E5, the top of the treble staff), up from 400 Hz, so the resonator root can be dialled across the full guitar range by ear. Note mode already covered this via the octave selector. Test: Free Tune at E5 rings near 659 Hz. Full suite 795 green. Co-Authored-By: Claude Opus 4.8 --- .../Pedals/KarplusResonatorPedal.swift | 9 ++++++--- .../KarplusResonatorPedalTests.swift | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Sources/LyrebirdShoeGaze/Pedals/KarplusResonatorPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/KarplusResonatorPedal.swift index e76442a..7e9f532 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/KarplusResonatorPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/KarplusResonatorPedal.swift @@ -30,7 +30,8 @@ import LyrebirdUI /// selectors in equal temperament (A4 = 440 Hz, so A3 = 220 Hz). /// /// ## Knobs -/// - `tune`: Root frequency of the string bank in Hz (used in **Free** tuning). Range `[40, 400]`. +/// - `tune`: Root frequency of the string bank in Hz (used in **Free** tuning). Range `[40, 660]` +/// (up to E5, the top of the treble staff). /// - `sustain`: Ring length — the string feedback. Range `[0, 1]` → feedback `[0.9, 0.999]`. /// - `tone`: Brightness of the strings. Range `[0, 1]`: `0` = dark/woody, `1` = bright/metallic. /// - `sensitivity`: How readily playing plucks the strings. Range `[0, 1]`: higher = lower trigger @@ -50,7 +51,7 @@ public final class KarplusResonatorPedal: Pedal { // MARK: - Parameters - /// Root frequency of the string bank in Hz. Range `[40, 400]`. + /// Root frequency of the string bank in Hz (Free tuning). Range `[40, 660]` — up to E5. @UIParam public var tune: Double = 82.41 /// Ring length — the string feedback. Range `[0, 1]` → feedback `[0.9, 0.999]`. @@ -180,7 +181,9 @@ public final class KarplusResonatorPedal: Pedal { // MARK: - Ranges - private let tuneRange: ClosedRange = 40.0 ... 400.0 + /// Free-mode root range in Hz. Upper bound reaches E5 (≈ 659 Hz, the top of the treble staff); + /// lower bound sits around a low bass E. + private let tuneRange: ClosedRange = 40.0 ... 660.0 private let unitRange: ClosedRange = 0.0 ... 1.0 // MARK: - Knobs diff --git a/Tests/LyrebirdShoeGazeTests/KarplusResonatorPedalTests.swift b/Tests/LyrebirdShoeGazeTests/KarplusResonatorPedalTests.swift index 9fce7a4..be35e73 100644 --- a/Tests/LyrebirdShoeGazeTests/KarplusResonatorPedalTests.swift +++ b/Tests/LyrebirdShoeGazeTests/KarplusResonatorPedalTests.swift @@ -259,6 +259,18 @@ struct KarplusResonatorPedalTests { "two voicings should ring differently: tail diff \(diff) vs drone tail \(droneTail)") } + @Test func freeModeReachesTrebleStaffTop() throws { + // Free-mode Tune now reaches E5 (≈ 659 Hz, top of the treble staff). Drone voicing shares the + // root period, so the ring's fundamental sits at the set root. + let e5: Double = 659.25 + let out: [Float] = try renderPluck { pedal in + pedal.mix = 1.0; pedal.sustain = 0.9; pedal.sensitivity = 0.6 + pedal.tuning = 0.0; pedal.tune = e5; pedal.voicing = 0.0 + } + let f: Double = fundamentalHz(out, skip: tailSkipFrames, window: tailWindowFrames, minHz: 300.0, maxHz: 900.0) + #expect(abs(f - e5) / e5 < 0.1, "Free Tune at E5 should ring near \(e5) Hz, got \(f)") + } + @Test func renderIsDeterministic() throws { // Every node in the bank is deterministic (no RNG), so two identical renders are bit-identical. let a: [Float] = try renderPluck { pedal in pedal.sustain = 0.8; pedal.voicing = 2.0 }