AudioQueue无法启动(AudioQueue fails to start)

编程入门 行业动态 更新时间:2024-10-27 23:18:21
AudioQueue无法启动(AudioQueue fails to start)

我按以下步骤创建了一个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

最满意答案

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

这有什么不对?

你做错了。

不完全是。 那就是那个错误意味着什么,这就是错误意味着的全部

这就是为什么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.

更多推荐

本文发布于:2023-08-02 15:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法启动   AudioQueue   start   fails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!