从后台线程播放 OpenAL 声音

发布于 2024-11-14 06:42:01 字数 408 浏览 3 评论 0原文

在我的 iOS 应用程序中,我不想使用 OpenAL 播放声音。我有 AudioManager 类,负责声音管理(单例)。所有声源和缓冲区在创建时初始化(在第一个实例调用时)。

因此,要播放声音,我需要的就是停止以前的声音,清除旧缓冲区(必要的源),附加新缓冲区,设置音调和声音。增益,最后播放声音。所有这些操作都在 playSound:(AMSound)sound 方法中(AMSound 是一个简单的枚举)。

对于 UI 效果,我从主线程调用此方法。但我的应用程序有很多后台工作,有时还伴有声音效果。

我可以直接从后台线程调用 playSound: 还是只在主线程上调用? 那么同时发出的声音又如何呢:一个是从主线程创建的,另一个是从后台创建的?

In my iOS app I wan't to play sounds using OpenAL. I have AudioManager class, responsible for sound-management (singleton). All sound sources & buffers are initialized when it is created (on the first instance call).

So to play sound all I need - is to stop previous sound, clear the old buffer (of necessary source), attach new buffer, set pitch & gain and finally, play the sound. All these operations are in playSound:(AMSound)sound method (AMSound is a simple enum).

For UI effects I call this method from main thread. But my app has a lot of background work, which is sometimes also accompanied by sound effects.

Can I call playSound: directly from background threads or should Ido it on main thread only?
And what about simultaneous sounds: one created from main thread, another - from background?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

oО清风挽发oО 2024-11-21 06:42:01

无论您在哪个线程上调用 playsound,openAL 实际上都会在自己的线程上播放它。至于同时发出的声音,这取决于你想如何混合它们,无论如何,openAL总是会管理自己的播放线程,所以从线程的角度来看,你在哪里调用playsound并不重要。

Doesn't matter on which thread you call playsound, openAL will actually play it on its own thread anyway. As for simultaneous sounds, it depends on how you want to mix them, anyway, openAL will always manage its own play threads, so from threading perspective it doesn't really matter where you call playsound

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