1.2.1 release to support some ShoeGaze features

This commit is contained in:
2026-07-02 10:20:40 -07:00
parent 032b7c39d3
commit 676e8d3278
12 changed files with 673 additions and 10 deletions
@@ -450,6 +450,148 @@ struct RecordBufferTests {
#expect(rec.buffer.channelCount == 1)
}
// MARK: - recordedFrameCount
@Test func recordedFrameCountReflectsWritePosAfterStoppingMidBuffer() throws {
// Record 8 frames into a 32-frame buffer, then stop (run = 0), then verify
// recordedFrameCount reflects the frames actually written (8), not the full
// buffer allocation (32) — mirrors a looper pedal reading "how many frames
// were recorded" after calling run = 0.
let engine: SynthesisEngine = try makeEngine(blockSize: 8)
let buf: LyrebirdBuffer = LyrebirdBuffer(count: 32)
let rec: RecordBuffer.Audio = RecordBuffer.Audio(input: 1.0, buffer: buf, loop: false)
#expect(rec.recordedFrameCount == 0, "no frames recorded before first block")
// Block 1: writes 8 frames.
do {
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = rec.calculatedSamples(graph: graph, count: 8)
}
#expect(rec.recordedFrameCount == 8,
"recordedFrameCount should equal writePos after one block")
advanceBlock(engine)
// Stop recording.
rec.run = 0.0
// Block 2: run ramps toward 0 across the block, so a few more frames may be
// written before the gate fully closes; regardless recordedFrameCount must
// track writePos exactly and stay well short of the full 32-frame buffer.
do {
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = rec.calculatedSamples(graph: graph, count: 8)
}
#expect(rec.recordedFrameCount > 8, "some frames should be written while run ramps down")
#expect(rec.recordedFrameCount < buf.count, "recording stopped short of the full buffer")
engine.stop()
}
@Test func recordedFrameCountControlVariantTracksWritePos() throws {
let engine: SynthesisEngine = try makeEngine(blockSize: 8)
let buf: LyrebirdBuffer = LyrebirdBuffer(count: 16)
let rec: RecordBuffer.Control = RecordBuffer.Control(input: 1.0, buffer: buf, loop: false)
for blockIdx: Int in 0..<3 {
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = rec.calculatedSamples(graph: graph, count: 8)
#expect(rec.recordedFrameCount == blockIdx + 1,
"block \(blockIdx): expected recordedFrameCount \(blockIdx + 1)")
advanceBlock(engine)
}
engine.stop()
}
// MARK: - requestReset
@Test func requestResetRestartsWritePosAtNextBlock() throws {
// Simulate a looper "reset" action: record a few frames of one value, call
// requestReset(), then record a new value — the second take must overwrite
// starting at frame 0, not continue from the mid-buffer writePos.
let engine: SynthesisEngine = try makeEngine(blockSize: 8)
let buf: LyrebirdBuffer = LyrebirdBuffer(count: 32)
let rec: RecordBuffer.Audio = RecordBuffer.Audio(input: 1.0, buffer: buf, loop: false)
// First take: 8 frames of 1.0.
do {
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = rec.calculatedSamples(graph: graph, count: 8)
}
#expect(rec.recordedFrameCount == 8, "first take should write 8 frames")
advanceBlock(engine)
rec.requestReset()
// recLevel is a ParameterNode-backed @LiveParam: it ramps toward its new target
// over one block. Block A (frames 0–7, writePos restarted at 0 by the reset)
// ramps recLevel 1.0→2.0 with varying values; Block B (frames 8–15) records
// with recLevel flat at 2.0 — mirrors the recLevelScalesNewSignal pattern above.
rec.recLevel = 2.0
do {
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = rec.calculatedSamples(graph: graph, count: 8)
}
#expect(rec.recordedFrameCount == 8,
"reset should restart writePos at 0, so this block again reaches frame count 8")
advanceBlock(engine)
do {
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = rec.calculatedSamples(graph: graph, count: 8)
}
#expect(rec.recordedFrameCount == 16,
"writePos should continue advancing normally after the reset settles")
for i: Int in 8..<16 {
#expect(abs(buf[i, 0] - 2.0) < 1e-9,
"frame \(i): expected fresh take value 2.0 after reset, got \(buf[i, 0])")
}
for i: Int in 16..<32 {
#expect(buf[i, 0] == 0.0,
"frame \(i): region never reached by either take should remain unwritten")
}
engine.stop()
}
@Test func requestResetClearsDoneAndNeedsFree() throws {
// A prior .freeNode completion (isDone == true, needsFree == true) must be
// fully cleared by requestReset() so the same instance can record again.
let engine: SynthesisEngine = try makeEngine(blockSize: 8)
let buf: LyrebirdBuffer = LyrebirdBuffer(count: 8)
let rec: RecordBuffer.Audio = RecordBuffer.Audio(
input: 1.0,
buffer: buf,
loop: false,
doneAction: .freeNode
)
do {
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = rec.calculatedSamples(graph: graph, count: 8)
}
#expect(rec.needsFree, "doneAction .freeNode should set needsFree once buffer fills")
advanceBlock(engine)
rec.requestReset()
do {
let graph: SynthGraph = makeSynthGraph(engine: engine)
_ = rec.calculatedSamples(graph: graph, count: 8)
}
// handleEndOfBuffer pins writePos at buffer.count - 1 (matches
// doneActionFreeNodeSetsNeedsFree convention above) rather than buffer.count.
#expect(rec.recordedFrameCount == buf.count - 1,
"recording should resume and refill the buffer after reset")
#expect(rec.needsFree, "recording to the end again should re-trigger needsFree")
engine.stop()
}
// MARK: - Fast-path coverage
/// Default-mode hot path: `recLevel == 1`, `preLevel == 0`, `run == 1`, `loop == true`.