AudioQueue启动失败

发布于 2024-10-01 00:35:46 字数 2485 浏览 2 评论 0原文

我按照以下步骤创建一个 AudioQueue。

  1. 使用 AudioQueueNewOutput 创建新输出 为
  2. kAudioQueueProperty_IsRunning 属性添加属性监听器
  3. 使用 AudioQueueAllocateBuffer 分配我的缓冲区 调用
  4. AudioQueuePrime
  5. 调用AudioQueueStart

问题是,当我调用 AudioQueuePrime 时,它在控制台上输出以下错误

AudioConverterNew returned -50
Prime failed (-50); will stop (11025/0 frames)

这里出了什么问题?

PS:

  1. 我在 iOS(设备和模拟器)上遇到此错误
  2. 调用 AudioQueueNewOutput 时安装的输出回调从未被调用!
  3. 该文件有效,并且 AudioStreamBasicDescription 与格式 (AAC) 匹配
  4. 我使用 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.

  1. Create a new output with AudioQueueNewOutput
  2. Add a property listener for the kAudioQueueProperty_IsRunning property
  3. Allocate my buffers with AudioQueueAllocateBuffer
  4. Call AudioQueuePrime
  5. 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:

  1. I got this error on iOS (Device & Simulator)
  2. The output callback installed when calling AudioQueueNewOutput is never called!
  3. The file is valid and the AudioStreamBasicDescription does match the format (AAC)
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巡山小妖精 2024-10-08 00:35:46
AudioConverterNew 返回 -50
Prime 失败 (-50);将停止(11025/0 帧)

这里出了什么问题?

你做错了。

不,真的。这就是该错误的含义,这就是该错误的全部含义。

这就是为什么 paramErr (-50) 是一个如此烦人的错误代码:它并没有说明你(或任何其他人)做错了什么

猜测其所抱怨的内容的第一步是找出哪个函数返回了该错误。更改您的 _reportError: 方法,使您能够记录返回错误的函数的名称。然后,记录您传递给该函数的参数,并找出为什么认为该函数的这些参数没有意义。

我自己的大胆猜测是,这是因为您强制输入 ASBD 的值与示例缓冲区的特征不匹配。您问题中包含的日志输出显示“11025/0 帧”; 11025 是常见的采样率(但与 44100 不同)。我想你会知道 0 指的是什么。

AudioConverterNew returned -50
Prime failed (-50); will stop (11025/0 frames)

What's wrong here?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文