如何使用 OpenAL 或 Finch 多次重叠播放相同的声音?

发布于 2024-08-31 07:38:46 字数 171 浏览 8 评论 0原文

Finch 使用 OpenAL。但是,当我有一个 Sound 实例并说 -play 时,声音就会播放。当我以快节奏的方式连续多次调用 -play 时,每次 -play 都会使该声音的当前声音播放停止并重新启动。

那不是我想要的。我是否必须创建多个源或缓冲区才能使其正常工作?或者我会用同一个文件实例化多个声音吗?

Finch uses OpenAL. However, when I have an instance of Sound, and say -play, the sound plays. When I call -play multiple times one after another in a fast paced way, every -play makes the current sound playback of that sound stop and restart it.

That's not what I want. Would I have to create multiple sources or buffers to get that working? Or would I just instantiate multiple Sounds with the same file?

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

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

发布评论

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

评论(1

小草泠泠 2024-09-07 07:38:46

正好有一个 RevolverSound 类对于这个用例。很简单,它预先分配许多 Sound 实例,然后轮流播放它们:

- (void) play
{
    [[sounds objectAtIndex:current] play];
    current = (current + 1) % [sounds count];
}

这意味着可以同时播放的声音有一个硬性限制,并且内存使用量会随着该限制而增加。我没有发现这在实践中是一个大问题,因为当同时播放五个或更多声音时,已经存在声音混乱,您通常不会注意到第一个声音没有播放到最后在重新开始之前。

There’s a RevolverSound class exactly for this use case. It’s very simple, it allocates a number of Sound instances beforehand and then plays them in rotation:

- (void) play
{
    [[sounds objectAtIndex:current] play];
    current = (current + 1) % [sounds count];
}

This means that there is a hard limit of the sounds that can play simultaneously and the memory usage goes up with that limit. I didn’t find that to be a big problem in practice, because when there are five or more sounds playing at once, there’s already such a sonic chaos that you generally won’t notice that the first one did not play to the very end before starting again.

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