由于AudioQueueNewInput失败了fmt,学习核心音频的第4章无法正常工作?

时间:2014-04-17 23:52:40

标签: ios macos core-audio

我正试图通过Adamson和Avila的第4章学习核心音频来完成录音计划。手动输入和从informit网站下载的未修改版本都以相同的方式失败。在队列创建时总是会失败。

Error: AudioQueueNewInput failed ('fmt?')

还有其他人在Mavericks和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 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。检查采样率。在你的情况下它将是巨大的(96000)。只需尝试将其手动设置为44100。

相关问题