我正在编写一个 Mac OS X 应用程序来通过带有回声消除的麦克风捕获一些音频。我正在创建一个 VoiceProcessingIO 类型的 AudioUnit。我想将音频输出为有符号整数线性 PCM。但是,当我指出我希望输出样本格式记录为 SignedInteger 时,我收到“不支持的格式”错误。
如何配置 AudioUnit 以有符号整数格式输出数据?这是我现在如何配置它。如果我尝试用 kAudioFormatFlagIsSignedInteger 替换 kAudioFormatFlagIsFloat,那么我会收到一个错误:(
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
OSStatus status = AudioComponentInstanceNew(comp, &_audioUnit);
...
const int sampleSize = 2;
const int eight_bits_per_byte = 8;
AudioStreamBasicDescription streamFormat;
streamFormat.mSampleRate = 16000;
streamFormat.mFormatID = kAudioFormatLinearPCM;
streamFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
streamFormat.mBytesPerPacket = sampleSize;
streamFormat.mFramesPerPacket = 1;
streamFormat.mBytesPerFrame = sampleSize;
streamFormat.mChannelsPerFrame = 1;
streamFormat.mBitsPerChannel = sampleSize * eight_bits_per_byte;
status = AudioUnitSetProperty(_audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &streamFormat, sizeof(streamFormat));
// 状态 = UnsupportedFormatError