From 39cc670cd23478621b44b783c141c2139ceb44f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C4=8Colja?= Date: Fri, 1 Mar 2024 13:00:58 +0100 Subject: [PATCH 1/2] write failing test --- .../AudioKitEXTests/CallbackInstrumentTests.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Tests/AudioKitEXTests/CallbackInstrumentTests.swift b/Tests/AudioKitEXTests/CallbackInstrumentTests.swift index 5bf1019..80741b1 100644 --- a/Tests/AudioKitEXTests/CallbackInstrumentTests.swift +++ b/Tests/AudioKitEXTests/CallbackInstrumentTests.swift @@ -66,5 +66,20 @@ class CallbackInstrumentTests: XCTestCase { /// If the callback does get called, this will fail our test, adding insult to injury XCTAssertEqual(data, expectedData) } + + func testClearsBuffer() { + let input = PlaygroundOscillator(waveform: Table([1, 1])) + let callback = CallbackInstrument() + + let engine = AudioEngine() + let mixer = Mixer(input, callback) + engine.output = mixer + + input.start() + let audio = engine.startTest(totalDuration: 1.0) + audio.append(engine.render(duration: 1.0)) + + XCTAssertTrue(audio.toFloatChannelData()!.flatMap { $0 }.allSatisfy { $0 == 1 }) + } } #endif From 729719cdda2e7100b813ca3cb1ab82a505eb07e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C4=8Colja?= Date: Fri, 1 Mar 2024 13:01:33 +0100 Subject: [PATCH 2/2] set output buffer values to zero --- Sources/CAudioKitEX/Nodes/CallbackInstrumentDSP.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/CAudioKitEX/Nodes/CallbackInstrumentDSP.mm b/Sources/CAudioKitEX/Nodes/CallbackInstrumentDSP.mm index 3054a84..98635ef 100644 --- a/Sources/CAudioKitEX/Nodes/CallbackInstrumentDSP.mm +++ b/Sources/CAudioKitEX/Nodes/CallbackInstrumentDSP.mm @@ -36,6 +36,8 @@ } void process(FrameRange range) override { + zeroOutput(range.count, range.start); + count += range.count; if (updateTime) { lastFrameCount = count;