在 iPhone 上完美连续地播放声音
我正在使用 cocos2d 为 iPhone 和 iPad 开发一款游戏,我需要能够在另一个游戏完成时准确地播放声音。 我的原声带被切成小块,在播放结束和开始播放之间没有任何间隙。
顺便提一句。我无法将声音粘合到一个文件中并直接播放,因为文件的顺序将在运行时重新排列。
我怎样才能实现这个目标?
I am developing a game for the iPhone and iPad using cocos2d, and I need to be able to play a sound exactly when another one completes.
I have a soundtrack that is chopped up in smaller pieces, and there are no room for the tinyest gap between playback when one finishes and one starts.
Btw. I cannot glue the sounds together into a single file and just play that since the order of the files will be rearranged runtime.
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 CocosDenshion,您可以使用
CDAudioManager 类参考
每当背景音乐结束时都会调用该委托。当然,这仅在您将声音文件作为背景音乐播放时才有效(使用 playBackgroundMusic 方法)。
如果这对您不起作用,请查看 ObjectAL。您将有更多的选择和更大的灵活性。例如,使用 ALSource 您可以对多个 ALBuffer 对象代表声音文件。这意味着每当源的缓冲区计数减少到 1 时,您只需将下一个缓冲区排队即可实现多个声音文件(任何格式)的不间断、顺序播放。
因为 ObjectAL 太棒了(嗯,我这么认为:))它已包含在 Kobold2D 中并可供使用。
With CocosDenshion you can register a delegate with
CDAudioManager class reference
This delegate will be called whenever the background music ends. This of course only works if you play your sound files as background music (with the playBackgroundMusic method).
If that doesn't work for you, have a look at ObjectAL. You'll have more options and greater flexibility. For example, with ALSource you can queue multiple ALBuffer objects which represent sound files. That means whenever the source's buffer count decreases to 1 you just queue the next buffer to achieve uninterrupted, sequential playback of multiple sound files (any format).
Because ObjectAL is so awesome (well, I think so :) ) it's included and ready to use in Kobold2D.
您可以使用单个音频队列或 RemoteIO 音频单元,只需使用任何文件中的原始/PCM 音频样本以任意顺序填充回调缓冲区即可。
You can use a single Audio Queue or the RemoteIO Audio Unit, and just fill the callback buffers with raw/PCM audio samples from any file in any order.