如何让AudioQueue播放而不冻结GUI?
我刚刚开始从 CoreAudio 书(粗剪)中学习 AudioQueues。 我做了AudioQueue播放示例教程,与苹果教程示例基本相同。一切正常。
当我尝试在具有 GUI 的应用程序中实现代码时,问题就开始了。我通过将代码粘贴到 NSObject 子类的“init”方法中来测试它。我可以让队列执行回调的唯一方法是在 init 末尾插入一个空的 DO...WHILE 循环,但这会使 GUI 冻结(显然...)!
显然,只要为 inCallbackRunLoop 和 CallbackRunLoopMode 参数将 AudioQueueNewOutput 传递为 NULL,AudioQueue 就应该自动在其自己的单独线程中运行。那只是没有发生。我只听到缓冲区启动后 1.5 秒的声音。
显然,有一些基本的东西我不明白事情是如何运作的......
卡斯帕
-(void) start
{
CheckError(
AudioQueueStart(queue, NULL),
"AudioQueueStart failed");
printf("Playing...\n");
do {
} while (0 == 0); //WHY IS THIS MAKING IT PLAY???
}
I just began learning about AudioQueues from the CoreAudio book (rough cuts).
I did the AudioQueue playback example tutorial, which is basically the same as the apple tutorial example. Everything is working fine.
The problems start when I try to implement the code in an app with a GUI. I tested it by pasting the code into the 'init' method of a NSObject subclass. The only way I can get the queue to do the callback is by inserting an empty DO...WHILE loop in the end of my init, but that makes the GUI freeze (obviously...)!!
Apparently the AudioQueue is supposed to be run in its own separate thread automatically as long as AudioQueueNewOutput is passed NULL for inCallbackRunLoop and CallbackRunLoopMode arguments. That's just not happening. I am only hearing the 1.5 seconds from the priming of the buffers.
Clearly, there is something fundamental that I don't understand about how things work...
Kasper
-(void) start
{
CheckError(
AudioQueueStart(queue, NULL),
"AudioQueueStart failed");
printf("Playing...\n");
do {
} while (0 == 0); //WHY IS THIS MAKING IT PLAY???
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我的 userData 结构没有在头文件中声明为 ivar 。菜鸟错误...
Turns out that my userData struct wasn't declared as a ivar in the header file. Rookie mistake...