如何使用 OpenAL 或 Finch 多次重叠播放相同的声音?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正好有一个
RevolverSound
类对于这个用例。很简单,它预先分配许多Sound
实例,然后轮流播放它们:这意味着可以同时播放的声音有一个硬性限制,并且内存使用量会随着该限制而增加。我没有发现这在实践中是一个大问题,因为当同时播放五个或更多声音时,已经存在声音混乱,您通常不会注意到第一个声音没有播放到最后在重新开始之前。
There’s a
RevolverSound
class exactly for this use case. It’s very simple, it allocates a number ofSound
instances beforehand and then plays them in rotation: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.