勾选要保存在内存中的声音。 AVA音频播放器?系统声音?核心音频?

发布于 2024-09-19 16:25:50 字数 460 浏览 4 评论 0原文

我正在尝试播放一个非常小的音频文件 - 它的长度大约为 0.05 秒,并且是一个未压缩的 .wav 文件。

现在,我正在使用 AVAudioPlayer 来播放声音。

我打算在旋转器旁边高速播放声音,就像《The Price Is Right》或《Wheel of Fortune》一样。如果我实例化循环计数为 100 的 AVAudioPlayer,它确实会按照我的预期非常快地播放声音。

然而,如果我在旋转器的每个“滴答声”上执行 [audioPlayer play] ,音频就会严重落后。我的猜测是,与设置高循环计数不同,[audioPlayer play] 需要在每次播放时完成音频剪辑​​内存的设置和拆卸。

有没有什么方法可以强制剪辑在内存中保留更长的时间?这是一种非常频繁的声音,因此在整个应用程序运行期间保持这种声音也可以。

I'm trying to play a very small audio file - it's roughly 0.05s in length, and it's an uncompressed .wav file.

Rgiht now, I'm using AVAudioPlayer to play the sound.

I intend to play the sound with high rapidity alongside a spinner, a la The Price Is Right or Wheel of Fortune. If I instantiate the AVAudioPlayer with a loop count of 100, it does indeed play the sound very rapidly as I'd expect.

If I execute [audioPlayer play] on each 'tick' of the spinner, however, the audio falls terribly behind. My guess is that, unlike setting a high loop count, [audioPlayer play] requires complete setup and teardown of the audio clip's memory for each playback.

Is there any way to force the clip to remain set up in memory for a longer duration? It's a very frequent sound, and as such would also be okay with keeping it up during the entire app run.

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

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

发布评论

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

评论(1

勿忘心安 2024-09-26 16:25:50

如果您依赖于更精确的计时,您可能需要尝试使用其他声音 API 之一。 Audio Unit RemoteIO 很复杂,但可以最精确地定时播放未压缩的声音。 OpenAL 和音频队列是另外两个选项。

If you depend on more precise timing, you might want to try using one of the other sound APIs. Audio Unit RemoteIO is complicated, but allows the most precise timing of playing uncompressed sounds. OpenAL and Audio Queues are two other options.

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