06bdcbbe92
- New Demos/LyrebirdGUIDemo: one shared source (synths + node-based views) that bootstraps SwiftUI on macOS and GTK4/SwiftOpenUI on Linux; LYREBIRD_DEMO=vector|sine. - The four CLI demos (Quickstart/Demo/NRT/Score) now build and run on Linux. - README + Linux getting-started refreshed; LyrebirdATK row removed from the Extensions section pending collaborator sign-off. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
76 lines
2.3 KiB
Swift
76 lines
2.3 KiB
Swift
// VectorOscillatorUI.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
|
||
/// A stereo vector oscillator whose XY position, frequency, and amplitude are
|
||
/// live-controllable from the UI.
|
||
///
|
||
/// Four corner wavetables are crossfaded on a 2D XY plane:
|
||
///
|
||
/// C (triangle) ── D (Hanning) (y = 1)
|
||
/// │ │
|
||
/// A (sine) ──── B (saw-ish) (y = 0)
|
||
/// x=0 x=1
|
||
///
|
||
/// Moving X blends A↔B (and C↔D); moving Y blends the AB mix into the CD mix.
|
||
public final class VectorOscillatorUI: SynthesizerBase {
|
||
|
||
/// X-axis blend position. 0 = corner A/C, 1 = corner B/D. Normalized [0, 1].
|
||
@UIParam public var x: Double = 0.5
|
||
|
||
/// Y-axis blend position. 0 = bottom (A, B), 1 = top (C, D). Normalized [0, 1].
|
||
@UIParam public var y: Double = 0.5
|
||
|
||
/// Oscillator frequency in Hz. Slider range: 40–2000 Hz.
|
||
@UIParam public var frequency: Double = 220.0
|
||
|
||
/// Output amplitude (linear gain). Knob range: 0–1.
|
||
@UIParam public var amplitude: Double = 0.25
|
||
|
||
private let bufferA: LyrebirdBuffer // corner A: sine
|
||
private let bufferB: LyrebirdBuffer // corner B: 16-partial saw-ish
|
||
private let bufferC: LyrebirdBuffer // corner C: triangle
|
||
private let bufferD: LyrebirdBuffer // corner D: Hanning window shape
|
||
|
||
public override init() {
|
||
let tableSize: Int = lyrebirdDefaultTableSize
|
||
|
||
let a: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
|
||
a.fillSine()
|
||
|
||
let b: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
|
||
b.fill(partials: 16)
|
||
|
||
let c: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
|
||
c.fillTriangle()
|
||
|
||
let d: LyrebirdBuffer = LyrebirdBuffer(count: tableSize)
|
||
d.fillHanning()
|
||
|
||
self.bufferA = a
|
||
self.bufferB = b
|
||
self.bufferC = c
|
||
self.bufferD = d
|
||
|
||
super.init()
|
||
}
|
||
|
||
public override func build() {
|
||
let osc: VectorOscillator.Audio = VectorOscillator.Audio(
|
||
bufferA: bufferA,
|
||
bufferB: bufferB,
|
||
bufferC: bufferC,
|
||
bufferD: bufferD,
|
||
freq: $frequency,
|
||
x: $x,
|
||
y: $y,
|
||
mul: $amplitude
|
||
)
|
||
output(bus: 0, source: Pan2(input: osc, pan: 0.0))
|
||
}
|
||
}
|