2009-09-22 92 views
3

我試圖讓音頻隊列在iphone應用程序上工作,並且每當調用AudioQueueStart時它都會提供「fmt?」結果碼(kAudioFormatUnsupportedDataFormatError)。在下面的代碼中,我將格式設置爲kAudioFormatLinearPCM,該格式肯定受支持。我究竟做錯了什麼?AudioQueueStart報告不支持的格式

data.mDataFormat.mSampleRate = 44100; 
data.mDataFormat.mFormatID = kAudioFormatLinearPCM; 
data.mDataFormat.mFormatFlags = 0; 
data.mDataFormat.mBytesPerPacket = 4; 
data.mDataFormat.mFramesPerPacket = 1; 
data.mDataFormat.mBytesPerFrame = 4; 
data.mDataFormat.mChannelsPerFrame = 2; 
data.mDataFormat.mBitsPerChannel = 16; 

OSStatus status; 

status = AudioQueueNewOutput(&data.mDataFormat, audioCallback, &data, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &data.mQueue); 

for (int i = 0; i < NUMBUFFERS; ++i) 
{ 
    status = AudioQueueAllocateBuffer (data.mQueue, BUFFERSIZE, &data.mBuffers[i]); 
    audioCallback (&data, data.mQueue, data.mBuffers[i]); 
} 

Float32 gain = 1.0; 
status = AudioQueueSetParameter (data.mQueue, kAudioQueueParam_Volume, gain); 

status = AudioQueueStart(data.mQueue, NULL); 

數據是類型audioData其是這樣的:

typedef struct _audioData { 
AudioQueueRef mQueue; 
AudioQueueBufferRef mBuffers[NUMBUFFERS]; 
AudioStreamBasicDescription mDataFormat; 

} audioData;

謝謝

+0

嗨! 我有同樣的問題。更改不同的標誌對我無用。可能是iPad模擬器不支持錄音? – 2011-01-30 14:29:45

回答

0

事實證明,我需要設置一些標誌。它的工作原理與

data.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; 

編輯:實際上,不使用kLinearPCMFormatFlagIsBigEndian,似乎與這種格式應該是小端。