iPhone游戏音频和背景音乐
有一些与向游戏添加声音有关的问题,特别是介绍音乐(用于启动)、背景音乐(循环)和按钮事件声音。希望您能分享您这方面的知识。
1) 我应该使用压缩声音还是未压缩声音?或者也许是两者的结合?我应该注意 iPhone 硬件是否有任何限制——例如,播放多个压缩声音的能力?
2)最适合我的音频格式是什么?
3)对于背景音乐,我正在考虑使用AVAudioPlayer。对于按钮事件声音,我正在考虑使用 AudioServicesPlaySystemSound,你觉得怎么样?
4)还有其他我应该注意的问题吗?
谢谢你!
Have a few questions related to adding sounds to my game, specifically intro music (for splash), background music (loop) and button event sounds. Hope you can share your knowledge on this.
1) Should I use compressed sounds or uncompressed sounds? Or perhaps a combination of the two? Are there any limitations on the iPhone hardware that I should be aware of -- for example, the ability to play multiple compressed sounds?
2) What's the best audio format for my purpose?
3) For background music, I am thinking of using AVAudioPlayer. For button event sounds, I am thinking of using AudioServicesPlaySystemSound, what do you think?
4) Any other issues I should be aware of?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 根据 iPhone 应用程序编程指南:“从 iPhone OS 3.0 开始,几乎所有支持的音频格式都可以用于同时播放,即所有可以使用软件解码播放的音频格式,如表 7-1 所示。处理器效率最高的多重播放,请使用线性 PCM(未压缩)或 IMA4(压缩)音频。”
但如果您要同时播放大量声音,则应该使用未压缩或 IMA4。
2) 您应该使用 CAF 文件格式,因为它为您提供了使用数据格式的最大灵活性。您可以将 MP3、AAC、PCM、IMA4 以及几乎任何压缩或未压缩的数据放入 CAF 文件 (.caf)。我通常使用 IMA4 压缩的 CAF 文件,单声道、16 位、44.1kHz。
3) 这就是我在应用程序中的做法:AVAudioPlayer 用于导致音乐音量降低的语音提示,AudioServicesPlaySystemSound 用于按钮和其他 UI 声音效果。
4) 如果使用未压缩的 PCM 数据,文件大小可能会很大,但 IMA4 是一种相当嘈杂的压缩方案。您可以使用 AAC,但可能会受到一次可以播放的 AAC 声音数量的限制。在 iPhone OS 3.0 之前,您一次只能播放一种 AAC 或 MP3 声音。
1) According to the iPhone Application Programming Guide: "Starting in iPhone OS 3.0, nearly all supported audio formats can be used for simultaneous playback—namely, all those that can be played using software decoding, as described in Table 7-1. For the most processor-efficient multiple playback, use linear PCM (uncompressed) or IMA4 (compressed) audio."
But if you're going to be playing a lot of sounds at the same time, you should use either uncompressed or IMA4.
2) You should use the CAF file format because it gives you the most flexibility in what data format to use. You can put MP3, AAC, PCM, IMA4, and pretty much any compressed or uncompressed data in a CAF file (.caf). I typically use CAF files with IMA4 compression at mono, 16-bit, 44.1kHz.
3) That's how I do it in my apps: AVAudioPlayer for voice cues that cause the music levels to duck, and AudioServicesPlaySystemSound for buttons and other UI sound effects.
4) If you use uncompressed PCM data, the file sizes can be huge, but IMA4 is a fairly noisy compression scheme. You can use AAC but then you might be limited by how many AAC sounds you can play at once. Before iPhone OS 3.0, you could only play one AAC or MP3 sound at a time.