エコーキャンセレーションを使用してマイクからオーディオをキャプチャする Mac OS X アプリケーションを作成しています。タイプ VoiceProcessingIO の AudioUnit を作成しています。オーディオを Signed Integer Linear PCM として出力したいと考えています。ただし、出力サンプル形式を SignedInteger として記録することを示すと、「サポートされていない形式」エラーが発生します。
符号付き整数形式でデータを出力するように AudioUnit を設定するにはどうすればよいですか? これが私が今それをどのように構成しているかです。kAudioFormatFlagIsFloat を kAudioFormatFlagIsSignedInteger に置き換えようとすると、エラーが発生します :(
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