简体   繁体   English

什么是iPhone上音效的最佳格式

[英]What's the best format for sound effects on iPhone

What is the recommended audio format for storing and playing back short (2-3 sec) audio sound effects on the iPhone or iToouch? 在iPhone或iToouch上存储和播放短(2-3秒)音频音效的推荐音频格式是什么?

The iPhone audio SDK documentation indicates that the iPhone supports audio in several formats - however there are drawbacks to each: iPhone音频SDK文档表明iPhone支持多种格式的音频 - 但每种格式都有缺点:

  • MP3: This is a highly compressed, but also high-quality encoding format that preserves the richness of music and spoken voice. MP3:这是一种高度压缩,但也是高质量的编码格式,可以保留丰富的音乐和语音。 However, only a single mp3 stream can be played at a time on the iPhone because it requires use of the hardware decoder. 但是,在iPhone上一次只能播放一个mp3流,因为它需要使用硬件解码器。 This excludes mp3 as a format for sound effects, since they will interrupt background music and/or any user music being played. 这不包括mp3作为声音效果的格式,因为它们会中断背景音乐和/或正在播放的任何用户音乐。
  • WAV: The iPhone only supports WAV files if they are PCM - encoded and do not require any compression codecs. WAV: iPhone只支持WAV文件,如果它们是PCM编码的,并且不需要任何压缩编解码器。 While WAV supports many different sampling rates and bit-depths, it results in very large files (180k / sec for 16-bit/44.1kHz/stereo audio). 虽然WAV支持许多不同的采样率和位深度,但它会产生非常大的文件(16位/ 44.1kHz /立体声音频时为180k / sec)。 The large size becomes prohibitive when you have many effects to rapidly play. 当你有很多快速发挥的效果时,大尺寸会变得过高。
  • AIFF: Has similar problems to WAV files - it's unclear if any compression codecs are supported. AIFF:与WAV文件有类似的问题 - 目前还不清楚是否支持任何压缩编解码器。 Supposedly Apple Lossless compression is supported - but I can't find any tools that can generate AIFF in using this compression. 据说支持Apple Lossless压缩 - 但我找不到任何可以在使用此压缩时生成AIFF的工具。
  • Custom: You can use the iPhone low-level APIs to play your own audio from any source. 自定义:您可以使用iPhone低级API从任何来源播放自己的音频。 But this seems like overkill for playing a simple sound effect in a game. 但是在游戏中播放简单的声音效果似乎有些过分。 I certainly don't want to write my own audio layer and encoder/decoder just for this. 我当然不想为此编写自己的音频层和编码器/解码器。

Any recommendations would be appreciated... it would also be helpful if someone could recommend a reasonably priced tool for processing audio that can generate the recommended format. 任何建议都将受到赞赏...如果有人可以推荐一个价格合理的工具来处理可以生成推荐格式的音频,也会有所帮助。 Thanks. 谢谢。

You can use IMA4 compressed files, which provide a 1:4 compression from WAV files and are decompressed by hardware (you can load them with an AVAudioPlayer ). 您可以使用IMA4压缩文件,这些文件从WAV文件提供1:4压缩,并由硬件解压缩(您可以使用AVAudioPlayer加载它们)。

As for MP3, you can only play one file simultaneously in that format, that's why it's not recommended for sound effects where you could have more than one at the same time. 至于MP3,你只能以这种格式同时播放一个文件,这就是为什么不建议你同时拥有多个音效的音效。

I'm using IMA4 files with OpenAL, so I'm decompressing them manually with a code based on this post . 我正在使用OpenAL的IMA4文件,所以我用基于这篇文章的代码手动解压缩它们。

I've had pretty good luck with CAF format files although WAV comes close in size. 虽然WAV的尺寸接近,但我对CAF格式文件运气不错。

As for tools, Audacity is free and reasonably functional. 至于工具,Audacity是免费且功能相当的。 I mainly use Amadeus Pro (around US$40). 我主要使用Amadeus Pro(约40美元)。 Pretty decent and generates all the iPhone supported audio formats (including MP3, AIFF, WAVE, AAC, and CAF). 相当不错并生成所有iPhone支持的音频格式(包括MP3,AIFF,WAVE,AAC和CAF)。 A nice feature is that it supports AudioUnit and VST plug-ins so you can add SoundFX. 一个很好的功能是它支持AudioUnit和VST插件,因此您可以添加SoundFX。

I've also heard good things about Fission (by Rogue Amoeba) but haven't actually used it. 我也听过关于Fission的好消息(由Rogue Amoeba提供),但实际上并没有使用它。 Their other audio products are pretty solid. 他们的其他音频产品非常稳固。

The AVAudioPlayer framework is pretty good at playing short clips, but you may want to pre-load the sounds (call prepareToPlay ) and keep them around if you can spare the memory. AVAudioPlayer框架非常适合播放短片,但你可能想要预先加载声音(调用prepareToPlay )并保留它们,如果你可以节省内存。

Take a look at the afconvert command line utility on your Mac. 看一下Mac上的afconvert命令行实用程序。 It does many conversions between different audio formats, and if you have a lot of sounds, you can script the conversions... 它在不同的音频格式之间进行了很多转换,如果你有很多声音,你可以编写转换脚本......

I use SoundToolbox and AVAudioPlayer with sounds mostly in uncompressed linear PCM, created in GarageBand. 我使用SoundToolbox和AVAudioPlayer,声音主要是在GarageBand中创建的未压缩线性PCM。

SoundToolbox is great for playing a short little "Boing" or "click" or other sounds that you trigger to play and you don't care about stopping or messing with their volume etc. SoundToolbox非常适合播放短小的“Boing”或“click”或其他您触发的声音,而您不关心停止或搞乱音量等。

If you want to stop a playing sound or to know if the sound is done playing, AVAudioToolbox is nice. 如果你想停止播放声音或者知道声音是否播放完毕,AVAudioToolbox很不错。 If you want to play sounds with control over the left and right components of the sound, then look at OpenAL. 如果您想通过控制声音的左右分量来播放声音,请查看OpenAL。

If you haven't already, read Apple's iPhone Application Programming Guide on Sound support. 如果您还没有,请阅读Apple的iPhone应用程序编程指南中的声音支持。

If sound is important to your app, you may want to take advantage of some of features available to you for very little work. 如果声音对您的应用程序很重要,您可能希望利用一些可用的功能来完成很少的工作。

The only format I've been able to get to work is CAF. 我能够使用的唯一格式是CAF。 It is also the one in most the code examples from apple. 它也是苹果代码示例中最多的一个。 If you are using short sound effects the size won't be a problem. 如果您使用的是短音效,则尺寸不会有问题。

I've been using Microsoft ADPCM WAV format which compresses from 3.25:1 (high quality) to 3.98:1 (default quality). 我一直在使用Microsoft ADPCM WAV格式,它从3.25:1(高质量)压缩到3.98:1(默认质量)。 Also I reduce sample rate to 32000 or even 22050 depending on the sound. 此外,我根据声音将采样率降低到32000甚至22050。 There is no need to save some files in stereo - mono also reduces the size of file pretty well. 没有必要在立体声中保存一些文件 - mono也可以很好地减小文件的大小。

For background music mp3 is fine. 对于背景音乐mp3很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM