zero-alloc audio pipeline: pointer-based IO from ring buffer to stdout
Replace Data/AudioPacket allocations with raw pointer callbacks through the entire audio pipeline. Ring buffer hands out direct pointers (or linearizes into a pre-allocated scratch buffer on wrap-around), converter accepts/emits pointers via its cached buffers, and output handler writes to stdout via write(2) with EINTR handling. Remove AudioPacket (dead code), --flush flag (no-op with raw write(2)). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -132,10 +132,17 @@ public class AudioRecorder {
|
||||
}
|
||||
|
||||
private func processAudioBuffer() {
|
||||
// Process and send complete chunks, applying conversion if needed
|
||||
audioBuffer?.processChunks().forEach { packet in
|
||||
let processedPacket = converter?.transform(packet) ?? packet
|
||||
outputHandler.handleAudioPacket(processedPacket)
|
||||
audioBuffer?.processChunks { pointer, count in
|
||||
if let converter = self.converter {
|
||||
if !converter.transform(from: pointer, count: count, handler: { outPtr, outCount in
|
||||
self.outputHandler.handleAudioData(outPtr, count: outCount)
|
||||
}) {
|
||||
// Conversion failed — pass through unconverted audio
|
||||
self.outputHandler.handleAudioData(pointer, count: count)
|
||||
}
|
||||
} else {
|
||||
self.outputHandler.handleAudioData(pointer, count: count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user