Music XML updates and optimizations
This commit is contained in:
@@ -458,3 +458,163 @@ benchEngine(label: " PitchShift.Audio ×16",
|
||||
warmupIter: psWarmup, benchIter: psIter)
|
||||
|
||||
print("\nblockSize=\(blockSize) sampleRate=44100 graph=16×(OscSin→EnvGen→Pan2→Out) warmup=\(crWarmup) iterations=\(crIter)")
|
||||
|
||||
// ============================================================
|
||||
// MARK: - Generator consolidation + RT performance baseline (GP group)
|
||||
//
|
||||
// Reference numbers for the GP perf phases. Each synth drives a target
|
||||
// generator hard (chained instances) so the target dominates the constant
|
||||
// engine/Pan2/Out overhead; the before/after delta on the identical graph
|
||||
// isolates the generator change. Driven via benchEngine so the engine advances
|
||||
// its segment serial every block (no fan-out cache artifact). Swept at
|
||||
// cbs=512 (one control tick/callback) and cbs=64 (8 sub-blocks/callback) to
|
||||
// show the win-curve across control block sizes.
|
||||
// ============================================================
|
||||
|
||||
print("\n--- GP performance baseline (8-voice target graphs) ---\n")
|
||||
|
||||
let gpVoiceCount: Int = 8
|
||||
let gpWarmup: Int = 500
|
||||
let gpIter: Int = 10_000
|
||||
|
||||
/// `gen × gen` and `gen + gen` arithmetic tree — exercises BinaryOpGenerator's
|
||||
/// generator-vs-generator path (vDSP_vmulD / vDSP_vaddD targets in GP-5).
|
||||
final class BinaryOpVectorSynth: SynthesizerBase {
|
||||
let freq: Double
|
||||
let bus: Int
|
||||
init(freq: Double, bus: Int) {
|
||||
self.freq = freq
|
||||
self.bus = bus
|
||||
super.init()
|
||||
}
|
||||
override func build() {
|
||||
let f: Double = freq
|
||||
let o1: OscSin.Audio = OscSin.Audio(freq: f)
|
||||
let o2: OscSin.Audio = OscSin.Audio(freq: f * 1.5)
|
||||
let o3: OscSin.Audio = OscSin.Audio(freq: f * 2.0)
|
||||
let o4: OscSin.Audio = OscSin.Audio(freq: f * 0.5)
|
||||
let mix: any Generator = (o1 * o2) + (o3 * o4)
|
||||
let mix2: any Generator = (mix * o3) + (o2 * o4)
|
||||
Out.Audio(bus: bus, source: Pan2(input: mix2 * 0.2, pan: 0.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// Alternating `gen × scalar` / `gen + scalar` chain — exercises
|
||||
/// BinaryOpGenerator's generator-vs-scalar path (vDSP_vsmulD / vsaddD in GP-5).
|
||||
final class BinaryOpScalarSynth: SynthesizerBase {
|
||||
let freq: Double
|
||||
let bus: Int
|
||||
init(freq: Double, bus: Int) {
|
||||
self.freq = freq
|
||||
self.bus = bus
|
||||
super.init()
|
||||
}
|
||||
override func build() {
|
||||
let o: OscSin.Audio = OscSin.Audio(freq: freq)
|
||||
let chain: any Generator = ((((o * 0.8) + 0.1) * 0.7) + 0.05) * 0.6
|
||||
Out.Audio(bus: bus, source: Pan2(input: chain, pan: 0.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// Chained unary transcendental math — `Exp(Sqrt(Abs(Sin(x))))`. GP-4 vForce
|
||||
/// targets (vvsin / vvsqrt / vvexp; Abs → vDSP_vabsD). Abs keeps Sqrt input
|
||||
/// non-negative.
|
||||
final class UnaryMathSynth: SynthesizerBase {
|
||||
let freq: Double
|
||||
let bus: Int
|
||||
init(freq: Double, bus: Int) {
|
||||
self.freq = freq
|
||||
self.bus = bus
|
||||
super.init()
|
||||
}
|
||||
override func build() {
|
||||
let o: OscSin.Audio = OscSin.Audio(freq: freq)
|
||||
let s: Sin.Audio = Sin.Audio(o)
|
||||
let a: Abs.Audio = Abs.Audio(s)
|
||||
let r: Sqrt.Audio = Sqrt.Audio(a)
|
||||
let e: Exp.Audio = Exp.Audio(r, mul: 0.1)
|
||||
Out.Audio(bus: bus, source: Pan2(input: e, pan: 0.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// `LinLin.Audio` linear remap — GP-6 `vDSP_vsmsaD` target.
|
||||
final class LinLinSynth: SynthesizerBase {
|
||||
let freq: Double
|
||||
let bus: Int
|
||||
init(freq: Double, bus: Int) {
|
||||
self.freq = freq
|
||||
self.bus = bus
|
||||
super.init()
|
||||
}
|
||||
override func build() {
|
||||
let o: OscSin.Audio = OscSin.Audio(freq: freq)
|
||||
let m: LinLin.Audio = LinLin.Audio(o, inLo: -1.0, inHi: 1.0, outLo: 0.0, outHi: 0.2)
|
||||
Out.Audio(bus: bus, source: Pan2(input: m, pan: 0.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// `SVF.Audio` with a generator-driven cutoff (OscSin LFO sweeping 500–2500 Hz)
|
||||
/// — forces the per-sample `sin()` coefficient path that GP-2/P4 replaces with
|
||||
/// block-boundary interpolation.
|
||||
final class SVFGenFreqSynth: SynthesizerBase {
|
||||
let freq: Double
|
||||
let bus: Int
|
||||
init(freq: Double, bus: Int) {
|
||||
self.freq = freq
|
||||
self.bus = bus
|
||||
super.init()
|
||||
}
|
||||
override func build() {
|
||||
let o: OscSin.Audio = OscSin.Audio(freq: freq)
|
||||
let lfo: OscSin.Audio = OscSin.Audio(freq: 2.0, mul: 1000.0, add: 1500.0)
|
||||
let svf: SVF.Audio = SVF.Audio(input: o, freq: lfo, q: 2.0)
|
||||
Out.Audio(bus: bus, source: Pan2(input: svf.lowpass, pan: 0.0))
|
||||
}
|
||||
}
|
||||
|
||||
/// `Chorus.Audio` on a single oscillator — GP-7 power-of-two delay-line target.
|
||||
final class ChorusBenchSynth: SynthesizerBase {
|
||||
let freq: Double
|
||||
let bus: Int
|
||||
init(freq: Double, bus: Int) {
|
||||
self.freq = freq
|
||||
self.bus = bus
|
||||
super.init()
|
||||
}
|
||||
override func build() {
|
||||
let o: OscSin.Audio = OscSin.Audio(freq: freq)
|
||||
let ch: Chorus.Audio = Chorus.Audio(input: o)
|
||||
Out.Audio(bus: bus, source: Pan2(input: ch, pan: 0.0))
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor func gpPopulate(_ engine: SynthesisEngine, _ make: (Double, Int) -> SynthesizerBase) {
|
||||
for i: Int in 0..<gpVoiceCount {
|
||||
let f: Double = 220.0 * pow(2.0, Double(i) / 12.0)
|
||||
do {
|
||||
try engine.add(make(f, 0))
|
||||
} catch {
|
||||
fatalError("engine.add failed in gpPopulate: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let gpTargets: [(label: String, make: (Double, Int) -> SynthesizerBase)] = [
|
||||
("BinaryOp gen×gen / gen+gen", { BinaryOpVectorSynth(freq: $0, bus: $1) }),
|
||||
("BinaryOp gen×scalar / +scalar", { BinaryOpScalarSynth(freq: $0, bus: $1) }),
|
||||
("Unary math Exp(Sqrt(Abs(Sin)))", { UnaryMathSynth(freq: $0, bus: $1) }),
|
||||
("LinLin.Audio", { LinLinSynth(freq: $0, bus: $1) }),
|
||||
("SVF.Audio gen-driven freq", { SVFGenFreqSynth(freq: $0, bus: $1) }),
|
||||
("Chorus.Audio", { ChorusBenchSynth(freq: $0, bus: $1) }),
|
||||
]
|
||||
|
||||
for target: (label: String, make: (Double, Int) -> SynthesizerBase) in gpTargets {
|
||||
for cbs: Int in [512, 64] {
|
||||
benchEngine(label: " \(target.label) cbs=\(cbs)",
|
||||
controlBlockSize: cbs,
|
||||
populate: { gpPopulate($0, target.make) },
|
||||
warmupIter: gpWarmup, benchIter: gpIter)
|
||||
}
|
||||
}
|
||||
|
||||
print("\nblockSize=\(blockSize) voices=\(gpVoiceCount) warmup=\(gpWarmup) iterations=\(gpIter)")
|
||||
|
||||
Reference in New Issue
Block a user