0

Say we have an AVCaptureAudioDataOutput object that has been set up with an AVCaptureSession to get data samples from the device's microphone.

captureOutput(_:didOutput:from:) in AVCaptureAudioDataOutputSampleBufferDelegate always gets called with 2048 bytes of samples. Is it possible to set a preferred sample buffer size?

A basic example:

let output = AVCaptureAudioDataOutput()
output.setSampleBufferDelegate(delegate, queue)
// Add output to AVCaptureSession and start the capture session once everything is set up
...

// In the delegate
public func captureOutput(_ output: AVCaptureOutput, 
                          didOutput sampleBuffer: CMSampleBuffer, 
                          from connection: AVCaptureConnection) {
    // sampleBuffer is 2048 bytes, but I want less
    let blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer)
    print(CMBlockBufferGetDataLength(blockBuffer!)) // 2048
    ...
}
Victor Durojaiye
  • 162
  • 1
  • 10
  • Have a look at `AVAudioSession`'s `setPreferredIOBufferDuration` method - it _might_ influence the capture session buffer size. – Rhythmic Fistman May 06 '22 at 14:37
  • I tried that. It did set `ioBufferDuration` close to what I wanted, but it made no difference to the sample buffer size. – Victor Durojaiye May 06 '22 at 14:47
  • When `setPreferredIOBufferDuration` succeeds it does influence the AudioUnit buffer size. What are you trying to do? Do you need lower latency capture? If so, switch to remote io audio units. – Rhythmic Fistman May 06 '22 at 14:49
  • 1
    Yes I need lower latency capture. I'll take a look at remote IO audio units as I've never heard of it before. – Victor Durojaiye May 06 '22 at 15:01

0 Answers0