13

I am developing one app in which I need to pass through audio capturing through output audio jack at the same time record and save video.

I have looked into aurio touch apple sample code and implemented audio passthrough.

I have also implemented the video recording through AVCaptureSession. Above both functionality individually done and works pefectly.

But when I merge functionality audio pass through not working because of audio session of the AVCapturesession.

I have also tried to pass through audio data which I am getting from AVCaptureSession delegate methods. Below is my code :

OSStatus err = noErr;


AudioBufferList audioBufferList;
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
CMItemCount numberOfFrames = CMSampleBufferGetNumSamples(sampleBuffer); // corresponds to the number of CoreAudio audio frames

currentSampleTime += (double)numberOfFrames;

AudioTimeStamp timeStamp;
memset(&timeStamp, 0, sizeof(AudioTimeStamp));
timeStamp.mSampleTime = currentSampleTime;
timeStamp.mFlags |= kAudioTimeStampSampleTimeValid;

AudioUnitRenderActionFlags flags = 0;
aurioTouchAppDelegate *THIS = (aurioTouchAppDelegate *)[[UIApplication sharedApplication]delegate];
 err = AudioUnitRender(self.rioUnit, &flags, &timeStamp, 1, numberOfFrames, &audioBufferList);

if (err) { printf("PerformThru: error %d\n", (int)err); }

But it is giving error. Please advise what can be done further as soon as possible. I have looked into so many docs and so many codes but couldn't find any solution. Please help..

4

1 回答 1

0

这是一些更好的错误处理代码。它返回什么错误?您可以通过在文档中搜索来查找错误描述。

static void CheckError (OSStatus error, const char *operation) {
    if (error == noErr) return;

    char str[20] = {};
    // see if it appears to be a 4 char code
    *(UInt32*)(str + 1) = CFSwapInt32HostToBig(error);
    if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
        str[0] = str[5] = '\'';
        str[6] = '\0';
    } else {
        sprintf(str, "%d", (int)error);
    }

    fprintf(stderr, "Error: %s(%s)\n", operation, str);
    exit(1);
}

- (void)yourFunction
{
    AudioBufferList audioBufferList;
    CMBlockBufferRef blockBuffer;
    CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &audioBufferList, sizeof(audioBufferList), NULL, NULL, 0, &blockBuffer);
    CMItemCount numberOfFrames = CMSampleBufferGetNumSamples(sampleBuffer); // corresponds to the number of CoreAudio audio frames

    currentSampleTime += (double)numberOfFrames;

    AudioTimeStamp timeStamp;
    memset(&timeStamp, 0, sizeof(AudioTimeStamp));
    timeStamp.mSampleTime = currentSampleTime;
    timeStamp.mFlags |= kAudioTimeStampSampleTimeValid;

    AudioUnitRenderActionFlags flags = 0;
    aurioTouchAppDelegate *THIS = (aurioTouchAppDelegate *)[[UIApplication sharedApplication]delegate];
    CheckError(AudioUnitRender(self.rioUnit, &flags, &timeStamp, 1, numberOfFrames, &audioBufferList),
               "Error with AudioUnitRender");
}
于 2014-01-14T22:56:17.257 回答