Я пытаюсь захватить звук с микрофона, используя AVCaptureSession
с настройкой ниже,
AVCaptureSession* captureSession = [AVCaptureSession new];
AVCaptureDevice* audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
NSError* error;
AVCaptureDeviceInput* audioInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioCaptureDevice error:&error];
if (error) {
NSLog(@"AVCaptureDeviceInput Error: %@", error.localizedDescription);
}
if ([captureSession canAddInput:audioInput]) {
[captureSession addInput:audioInput];
} else {
NSLog(@"Unable to add Audio Input to Capture Session");
}
AVCaptureAudioDataOutput* audioOutput = [AVCaptureAudioDataOutput new];
NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt: kAudioFormatLinearPCM], AVFormatIDKey, [NSNumber numberWithFloat: 44100.0], AVSampleRateKey, nil];
audioOutput.audioSettings = settings;
dispatch_queue_t audioQueue = dispatch_queue_create("AudioSessionQueue", nil);
[audioOutput setSampleBufferDelegate:self queue:audioQueue];
if ([captureSession canAddOutput:audioOutput]) {
[captureSession addOutput:audioOutput];
} else {
NSLog(@"Unable to add Audio Output to Capture Session");
}
[captureSession commitConfiguration];
[captureSession startRunning];
currentSession = captureSession;
Я получаю некоторые данные в методе делегата -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
и преобразую их в NSData, как показано ниже,
AudioBufferList audioBufferList;
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
CMItemCount numSamples = CMSampleBufferGetNumSamples(sampleBuffer);
NSUInteger size = sizeof(audioBufferList);
char buffer[size];
((int*)buffer)[0] = (int)numSamples;
memcpy(buffer, &audioBufferList, size);
//This is the Audio data.
NSData *bufferData = [NSData dataWithBytes:buffer length:size];
Теперь мой вопрос: как проверить, что данные являются действительными аудио?