Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing and manipulating microphone audio with AVCaptureSession?

While there are plenty of tutorials for how to use AVCaptureSession to grab camera data, I can find no information (even on apple's dev network itself) on how to properly handle microphone data.

I have implemented AVCaptureAudioDataOutputSampleBufferDelegate, and I'm getting calls to my delegate, but I have no idea how the contents of the CMSampleBufferRef I get are formatted. Are the contents of the buffer one discrete sample? What are its properties? Where can these properties be set?

Video properties can be set using [AVCaptureVideoDataOutput setVideoSettings:], but there is no corresponding call for AVCaptureAudioDataOutput (no setAudioSettings or anything similar).

like image 511
akaii Avatar asked Nov 15 '22 02:11

akaii


1 Answers

They are formatted as LPCM! You can verify this by getting the AudioStreamBasicDescription like so:

CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
const AudioStreamBasicDescription *streamDescription = CMAudioFormatDescriptionGetStreamBasicDescription(formatDescription);

and then checking the stream description’s mFormatId.

like image 175
David Cairns Avatar answered Dec 28 '22 08:12

David Cairns