2014-04-17 33 views
2

我試圖從Adamson和Avila學習Core Audio的第4章中獲得錄音程序。無論是手動輸入還是從informit網站下載的未修改版本都以相同的方式失敗。它在創建隊列時總是失敗。學習的第4章Core Audio由於AudioQueueNewInput失敗而無法使用fmt?

Error: AudioQueueNewInput failed ('fmt?') 

有沒有其他人在小牛隊和XCode5上試過這個示例程序?以下是從下載站點直至故障點的內容。當我嘗試使用一些硬編碼參數的LPCM時,則沒關係,但我無法使MPEG4AAC正常工作。看起來像AppleLossless雖然工作。

// Code from download 
int main(int argc, const char *argv[]) 
{ 
MyRecorder recorder = {0}; 
AudioStreamBasicDescription recordFormat = {0}; 
memset(&recordFormat, 0, sizeof(recordFormat)); 

// Configure the output data format to be AAC 
recordFormat.mFormatID = kAudioFormatMPEG4AAC; 
recordFormat.mChannelsPerFrame = 2; 

// get the sample rate of the default input device 
// we use this to adapt the output data format to match hardware capabilities 
MyGetDefaultInputDeviceSampleRate(&recordFormat.mSampleRate); 

// ProTip: Use the AudioFormat API to trivialize ASBD creation. 
//   input: at least the mFormatID, however, at this point we already have 
//    mSampleRate, mFormatID, and mChannelsPerFrame 
//   output: the remainder of the ASBD will be filled out as much as possible 
//     given the information known about the format 
UInt32 propSize = sizeof(recordFormat); 
CheckError(AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, 
            &propSize, &recordFormat), "AudioFormatGetProperty failed"); 

// create a input (recording) queue 
AudioQueueRef queue = {0}; 
CheckError(AudioQueueNewInput(&recordFormat, // ASBD 
           MyAQInputCallback, // Callback 
           &recorder, // user data 
           NULL, // run loop 
           NULL, // run loop mode 
           0, // flags (always 0) 
           // &recorder.queue), // output: reference to AudioQueue object 
           &queue), 
      "AudioQueueNewInput failed"); 

回答

1

我面臨同樣的問題。檢查採樣率。在你的情況下,它將是巨大的(96000)。只需嘗試將其手動設置爲44100.

相關問題