AudioQueue启动失败
我按照以下步骤创建一个 AudioQueue。
- 使用
AudioQueueNewOutput
创建新输出 为 kAudioQueueProperty_IsRunning
属性添加属性监听器- 使用
AudioQueueAllocateBuffer
分配我的缓冲区 调用 AudioQueuePrime
- 调用
AudioQueueStart
问题是,当我调用 AudioQueuePrime
时,它在控制台上输出以下错误
AudioConverterNew returned -50
Prime failed (-50); will stop (11025/0 frames)
这里出了什么问题?
PS:
- 我在 iOS(设备和模拟器)上遇到此错误
- 调用
AudioQueueNewOutput
时安装的输出回调从未被调用! - 该文件有效,并且
AudioStreamBasicDescription
与格式 (AAC) 匹配 - 我使用 Mat 的 测试了该文件AudioStreamer 似乎可以在那里工作
示例初始化代码:
// Get the stream description from the first sample buffer
OSStatus err = noErr;
EDSampleBuffer *firstBuf = [sampleBufs objectAtIndex:0];
AudioStreamBasicDescription asbd = firstBuf.streamDescription;
// TODO: remove temporary format setup, just to ensure format for now
asbd.mSampleRate = 44100.00;
asbd.mFramesPerPacket = 1024; // AAC default
asbd.mChannelsPerFrame = 2;
pfcc(asbd.mFormatID);
// -----------------------------------
// Create a new output
err = AudioQueueNewOutput(&asbd, _audioQueueOutputCallback, self, NULL, NULL, 0, &audioQueue);
if (err) {
[self _reportError:kASAudioQueueInitializationError];
goto bail;
}
// Add property listener for queue state
err = AudioQueueAddPropertyListener(audioQueue, kAudioQueueProperty_IsRunning, _audioQueueIsRunningCallback, self);
if (err) {
[self _reportError:kASAudioQueuePropertyListenerError];
goto bail;
}
// Allocate a queue buffers
for (int i=0; i<kAQNumBufs; i++) {
err = AudioQueueAllocateBuffer(audioQueue, kAQDefaultBufSize, &queueBuffer[i]);
if (err) {
[self _reportError:kASAudioQueueBufferAllocationError];
goto bail;
}
}
// Prime and start
err = AudioQueuePrime(audioQueue, 0, NULL);
if (err) {
printf("failed to prime audio queue %ld\n", err);
goto bail;
}
err = AudioQueueStart(audioQueue, NULL);
if (err) {
printf("failed to start audio queue %ld\n", err);
goto bail;
}
这些是音频文件流中的格式标志
rate: 44100.000000
framesPerPacket: 1024
format: aac
bitsPerChannel: 0
reserved: 0
channelsPerFrame: 2
bytesPerFrame: 0
bytesPerPacket: 0
formatFlags: 0
cookieSize 39
I create an AudioQueue in the following steps.
- Create a new output with
AudioQueueNewOutput
- Add a property listener for the
kAudioQueueProperty_IsRunning
property - Allocate my buffers with
AudioQueueAllocateBuffer
- Call
AudioQueuePrime
- Call
AudioQueueStart
The problem is, when i call AudioQueuePrime
it outputs following error on the console
AudioConverterNew returned -50
Prime failed (-50); will stop (11025/0 frames)
What's wrong here?
PS:
- I got this error on iOS (Device & Simulator)
- The output callback installed when calling
AudioQueueNewOutput
is never called! - The file is valid and the
AudioStreamBasicDescription
does match the format (AAC) - I tested the file with Mat's AudioStreamer and it seems to work there
Sample Init Code:
// Get the stream description from the first sample buffer
OSStatus err = noErr;
EDSampleBuffer *firstBuf = [sampleBufs objectAtIndex:0];
AudioStreamBasicDescription asbd = firstBuf.streamDescription;
// TODO: remove temporary format setup, just to ensure format for now
asbd.mSampleRate = 44100.00;
asbd.mFramesPerPacket = 1024; // AAC default
asbd.mChannelsPerFrame = 2;
pfcc(asbd.mFormatID);
// -----------------------------------
// Create a new output
err = AudioQueueNewOutput(&asbd, _audioQueueOutputCallback, self, NULL, NULL, 0, &audioQueue);
if (err) {
[self _reportError:kASAudioQueueInitializationError];
goto bail;
}
// Add property listener for queue state
err = AudioQueueAddPropertyListener(audioQueue, kAudioQueueProperty_IsRunning, _audioQueueIsRunningCallback, self);
if (err) {
[self _reportError:kASAudioQueuePropertyListenerError];
goto bail;
}
// Allocate a queue buffers
for (int i=0; i<kAQNumBufs; i++) {
err = AudioQueueAllocateBuffer(audioQueue, kAQDefaultBufSize, &queueBuffer[i]);
if (err) {
[self _reportError:kASAudioQueueBufferAllocationError];
goto bail;
}
}
// Prime and start
err = AudioQueuePrime(audioQueue, 0, NULL);
if (err) {
printf("failed to prime audio queue %ld\n", err);
goto bail;
}
err = AudioQueueStart(audioQueue, NULL);
if (err) {
printf("failed to start audio queue %ld\n", err);
goto bail;
}
These are the format flags from the audio file stream
rate: 44100.000000
framesPerPacket: 1024
format: aac
bitsPerChannel: 0
reserved: 0
channelsPerFrame: 2
bytesPerFrame: 0
bytesPerPacket: 0
formatFlags: 0
cookieSize 39
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你做错了。
不,真的。这就是该错误的含义,这就是该错误的全部含义。
这就是为什么
paramErr
(-50) 是一个如此烦人的错误代码:它并没有说明你(或任何其他人)做错了什么。猜测其所抱怨的内容的第一步是找出哪个函数返回了该错误。更改您的
_reportError:
方法,使您能够记录返回错误的函数的名称。然后,记录您传递给该函数的参数,并找出为什么认为该函数的这些参数没有意义。我自己的大胆猜测是,这是因为您强制输入 ASBD 的值与示例缓冲区的特征不匹配。您问题中包含的日志输出显示“11025/0 帧”; 11025 是常见的采样率(但与 44100 不同)。我想你会知道 0 指的是什么。
You did it wrong.
No, really. That's what that error means, and that's ALL that error means.
That's why
paramErr
(-50) is such an annoying error code: It doesn't say a damn thing about what you (or anyone else) did wrong.The first step to formulating guesses as to what it's complaining about is to find out what function returned that error. Change your
_reportError:
method to enable you to log the name of the function that returned the error. Then, log the parameters you're passing to that function and figure out why it's of the opinion that those parameters to that function don't make sense.My own wild guess is that it's because the values you forced into the ASBD don't match the characteristics of the sample buffer. The log output you included in your question says “11025/0 frames”; 11025 is a common sample rate (but different from 44100). I assume you'd know what the 0 refers to.