// FlowLevelStoreTests.swift // OSGKeyboardTests // // Regression cover for the waveform bar arithmetic. `calculateLevels` runs on // the AVAudioEngine realtime thread, where a reversed `start.. AVAudioPCMBuffer { let format = AVAudioFormat( commonFormat: .pcmFormatFloat32, sampleRate: 48_000, channels: 1, interleaved: false )! // frameCapacity must be > 0 even when we want a zero-length buffer. let buffer = AVAudioPCMBuffer( pcmFormat: format, frameCapacity: AVAudioFrameCount(max(frameLength, 1)) )! buffer.frameLength = AVAudioFrameCount(frameLength) if let channel = buffer.floatChannelData?[0] { for index in 0.. 0, "leading bars should carry the signal") for index in 10.. 0 }, "frameLength=\(frameLength) should light every bar" ) } } /// The instance path the audio tap actually calls. func testUpdateFromShortBufferKeepsSnapshotUsable() { let store = FlowLevelStore(barCount: barCount) store.update(from: makeBuffer(frameLength: 3), barCount: barCount) XCTAssertEqual(store.snapshot().count, barCount) } }