2013-04-01 42 views
1

我正在編寫一個Mac OS X應用程序,通過帶回聲消除的麥克風捕獲一些音頻。我正在創建一個類型爲VoiceProcessingIO的AudioUnit。我想輸出音頻作爲帶符號整數線性PCM。但是,當我指出我希望輸出採樣格式記錄爲SignedInteger時,我得到一個「不支持的格式」錯誤。配置Mac OS X AudioUnit以提供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

回答

0

我決定,我不能這樣做。我使用AudioConverter類將浮點格式轉換爲有符號整數。在光明方面,AudioConverter非常容易使用!