我正在编写一个Mac OS X应用程序,通过回声消除功能通过麦克风捕获一些音频。我正在创建一个VoiceProcessingIO类型的AudioUnit。我想将音频输出为Signed Integer Linear 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));
// status = UnsupportedFormatError
答案 0 :(得分:0)
我决定不能这样做。我使用AudioConverter类将浮点格式转换为有符号整数。从好的方面来说,AudioConverter非常容易使用!