如何在 OpenAL 中计量/平均峰值功率电平?

发布于 2024-08-27 08:09:44 字数 119 浏览 8 评论 0原文

我正在使用 Finch 声音引擎从 AVAudioPlayer 切换到 OpenAL。我需要进行计量,即获得平均峰值电平。 Finch 声音引擎不提供此功能,而且我对 OpenAL 完全陌生。我该怎么做?任何例子将非常感激。

I'm in the process of switching from AVAudioPlayer to OpenAL using the Finch sound engine. I need to do metering, i.e. get the average peak levels. Finch sound engine does not provide this, and I'm completely new to OpenAL. How can I do this? Any examples would be really appreciated.

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

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

发布评论

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

评论(1

鲜肉鲜肉永远不皱 2024-09-03 08:09:44

我假设您正在寻找 AVAudioPlayer 的 peakPowerForChannel: 方法的直接替代品。不幸的是,没有。你必须自己动手。

OpenAL“声音”是“缓冲区”(加载到内存中的示例数据)和“源”的组合,“源”表示您想要应用于示例数据的属性之类的内容。

OpenAL 播放的简单方法是将整个文件加载到内存中,然后在一次调用中播放整个文件。但是,您可以使用 NSInputStream 将文件中的 PCM 样本数据块读入 OpenAL 缓冲区,使用 alBufferData() 使用您自己的函数计算峰值功率,使用您的源播放该块,然后重复直到 EOF 。

我知道您打算使用 Finch,但您应该对 AudioQueues 进行真正的仔细检查(如果计量对您来说是一个关键功能)。它针对此类应用程序进行了更好的设计。特别是,kAudioQueueProperty_CurrentLevelMeterDB 属性将为您提供峰值 RMS (mPeakPower) 或平均 RMS 电平 (mAveragePower),您可以根据需要随时读取。

祝你好运,编码愉快!

一些可能有用的资源:

I'm assuming you're looking for a drop-in replacement of AVAudioPlayer's peakPowerForChannel: method. Unfortunately, there is none. You'll have to roll your own.

OpenAL "sounds" are a combination of a "buffer" (your sample data, loaded in memory) and a "source," which represents something like properties you want applied to your sample data.

The easy approach to OpenAL playback is to load the entire file into memory and just play the whole thing in one call. However, you can use an NSInputStream to read in a chunk of PCM sample data from a file into an OpenAL buffer, use alBufferData() to compute your peak power using your own function, play the chunk using your source, and then repeat until EOF.

I know you are intending to use Finch, but you should give AudioQueues a real close lookover (if metering is a critical feature for you). It is much better designed for this type of application. In particular, the kAudioQueueProperty_CurrentLevelMeterDB property will provide you with either peak RMS (mPeakPower) or average RMS levels (mAveragePower), which you can read as often as you like.

Good luck and happy coding!

Some resources that might be helpful:

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