iPhone音频单元录制在后台,如何

时间:2011-12-05 20:21:56

标签: iphone core-audio audio-recording audiounit

我正在查看用于录制的音频单元功能。一切都很好,除了录制回调在应用程序在后台时停止,不像AVCapture在背景中使用RED BAR进行录制。有没有办法让它在后台继续录制,就像AVCapture一样?

#import "AudioUnit/AudioComponent.h"
#import "AudioUnit/AudioUnit.h"

desc.componentType          = kAudioUnitType_Output;
desc.componentSubType       = kAudioUnitSubType_RemoteIO;
desc.componentFlags         = 0;
desc.componentFlagsMask     = 0;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;

AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc);
status = AudioComponentInstanceNew(inputComponent, &audioUnit);
checkStatus(status);

UInt32 flag = 1;

status = AudioUnitSetProperty(audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, kInputBus, &flag, sizeof(flag));
checkStatus(status);

//status = AudioUnitSetProperty(audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(flag));
checkStatus(status);

AudioStreamBasicDescription     audioFormat;
audioFormat.mSampleRate         = 8000.00; //44100.00;
audioFormat.mFormatID           = kAudioFormatLinearPCM;
audioFormat.mFormatFlags        = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
audioFormat.mFramesPerPacket    = 1;
audioFormat.mChannelsPerFrame   = 1;
audioFormat.mBitsPerChannel     = 16;
audioFormat.mBytesPerPacket     = 2;
audioFormat.mBytesPerFrame      = 2;

status = AudioUnitSetProperty(audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kInputBus, &audioFormat, sizeof(audioFormat));
checkStatus(status);

status = AudioUnitSetProperty(audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &audioFormat, sizeof(audioFormat));
checkStatus(status);

AURenderCallbackStruct callbackStruct;

callbackStruct.inputProc = recordingCallback;
callbackStruct.inputProcRefCon = self;

status = AudioUnitSetProperty(audioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, kInputBus, &callbackStruct, sizeof(callbackStruct));
checkStatus(status);

1 个答案:

答案 0 :(得分:3)

Doh,忘了设置

目标/信息/所需背景模式/应用播放音频

到测试应用程序。