What are the best audio formats you use for soundtracks and for sound effects? MP3? WAV?
What audio formats do you use?
(26 posts) (12 voices)-
Posted 10 months ago #
-
MP3 for soundtracks and CAF for sound effects
Posted 10 months ago # -
I work with WAV on audio editors (I save the WAV sound effect and music files in 22050Hz, 16 bits, mono), then convert them to CAF (for sound effects) and AIFC (for music), to obtain smaller file sizes. As far as I know, MP3 can't be looped because there is a little pause between loops, so I avoid MP3 if I need to loop the BG Music.
Some command lines to convert WAV files to CAF and AIFC:
afconvert -f caff -d ima4 sfx.wav afconvert -f AIFC -d ima4 bgm.wavHope this helps.
Posted 10 months ago # -
+1 for caff and aifc too. And "-c 1" on the afconvert will create mono files, in case you want to reduce even more the size and you don't need stereo (unless you use headphones there will be not massive difference)
Posted 10 months ago # -
mp3 on my golf game due to binary size (the mp3's are mega small)
however i try to use as high quality as possible... because if you've got the space (by that mean, under 50 MB) why not?
Posted 10 months ago # -
Apple's recommendation is below. CAF files are Core Audio's wrapper format, they can be wrapped around lots of different types of encoding such as little endian linear PCM, IMA4, mp3 and aac. For example, Dani is actually using IMA4 which is a lossy compression format that is about 1/4 the size of the equivalent little endian encoding.
In the past lots of people have had issues looping mp3 files that were fixed when they switched to AAC.
If you are playing sounds using OpenAL (e.g. you use CocosDenshion playEffect or ObjectAL) then all your sounds are converted to little endian linear PCM format in memory when they are loaded so the format you use is only really relevant to how much space they take in the download.
For uncompressed (highest quality) audio, use 16-bit, little endian, linear PCM audio data packaged in a CAF file. You can convert an audio file to this format in Mac OS X using the afconvert command-line tool, as shown here:
/usr/bin/afconvert -f caff -d LEI16 {INPUT} {OUTPUT}
The afconvert tool lets you convert to a wide range of audio data formats and file types. See the afconvert man page, and enter afconvert -h at a shell prompt, for more information.For compressed audio when playing one sound at a time, and when you don’t need to play audio simultaneously with the iPod application, use the AAC format packaged in a CAF or m4a file.
For less memory usage when you need to play multiple sounds simultaneously, use IMA4 (IMA/ADPCM) compression. This reduces file size but entails minimal CPU impact during decompression. As with linear PCM data, package IMA4 data in a CAF file.
Posted 10 months ago # -
I found a useful post here: http://gamua.com/blog/2010/06/sound-on-ios-best-practices/
Posted 10 months ago # -
@Dani - do you use the sound engine from Sparrow? If not then that article is not really good advice/best practices.
Posted 10 months ago # -
@Steve Olmeadow: Then I'm very confused now. What format do you recommend me to use for CocosDenshion and this scenario (an aviation shooter)?:
- Lots of different sounds playing almost at the same time.
- Background music loop.I'm looking for this features (in that order):
1. Little CPU and performance impact.
2. Little file size.As I said, I use this for sound effects:
afconvert -f caff -d ima4 sfx.wavAnd this for music:
afconvert -f AIFC -d ima4 bgm.wavThanks in advance!
Posted 10 months ago # -
I did A LOT of test on the audio formats for Wawa Land, and this are the 2 formats that I use to get the best compromise between size and quality:
BGM - AIFC - IMA4 - MONO - 32k
SFX - AIFC - IMA4 - MONO - 24kI also have one or two MP3s for good quality long SFX.
Posted 10 months ago # -
@Dani - for background music use AAC packaged in a CAF or M4A file. e.g
afconvert -d aac -f 'caff' -b 131072 background-music-lei.caf test_128.cafFor sound effects use 16 bit little endian linear PCM in a CAF file. If you have a looping sound and there is a glitch then switch to using .WAV as CocosDenshion will use a different loading method that may improve looping at the cost of slightly longer load times e.g
afconvert -f caff -d LEI16 sound.wavNote that is Apple's recommendation. However, what you are currently doing isn't too bad. If you switch to following Apple's recommendation you will find your background music should be better quality and a smaller file. Your effects will be larger files but better quality, memory use at run time will be exactly the same.
Here is a good article: http://www.raywenderlich.com/233/audio-101-for-iphone-developers-converting-and-recording
Posted 10 months ago # -
Thanks @Steve Olmeadow, I have tried AAC-CAF for background music files and they loop OK, so I think this is the best solution (smaller file size, better quality, loopable). For sound effects I will use LEI16-CAF and mono, but I don't know if I should use them in 44100Hz or 22050Hz. I will make some other tests.
Other questions: I'm not sure about how CocosDenshion manages sound effects. Does it make any difference playing sound effects in LEI16-CAF or IMA4-CAF from a performance point of view? I suppose IMA4 sounds need uncompression, but are they uncompressed each time I play it, or are they uncompressed once and stored in memory? If I preload all sound effects, will they remain in memory till I quit the app? Will they need any uncompression later?
What I do in my project is preloading all sound effects once at startup.
Thanks!
Posted 10 months ago # -
I believe that preloaded sound effects will remain in memory until they are removed or the app is shut down. I have also preloaded all sound effects at startup like you are doing.
Posted 10 months ago # -
@Dani - 44100 or 22050 really comes down to the sounds and what you think sounds acceptable. Are you familiar with the Nyquist theorem? Basically it states that you require a sample rate twice the maximum frequency to accurately represent a sound. So, for a bassy sound with no frequencies above 11025 then 22050Hz will be fine. Of course 22050 uses half the memory of 44100 so if you are pushed for memory that may sway you. Apple also used to recommend having all the sounds at the same frequency for playback via OpenAL but I don't think that is such an issue on current devices.
As for the internals of CocosDenshion, you are correct all sounds are uncompressed when they are loaded. They are stored in memory in little endian linear PCM format which is like the native internal audio format (often called canonical format). The memory use is slightly smaller than the file size of a LEI16 CAF file or a .WAV file as the files have header information that is discarded.
If you preload sounds they will remain in memory until they are unloaded or the app is terminated. The decompression only occurs when the sound is loaded.
Personally I like having sounds in LEI16 as it is very easy to see what your audio memory use will be by simply adding up the file sizes. Also, don't forget that the audio files will be compressed in the IPA file so when comparing file size savings you should look at the change to the final IPA size rather than comparing the raw file sizes.
Posted 10 months ago # -
Ok, thanks @Steve Olmeadow, now I undertand this quite better.
One more question, when I setup the audio engine, I do this:
[CDSoundEngine setMixerSampleRate:CD_SAMPLE_RATE_MID];That it's supposed to setup the mixer to 22050Hz. Can I still play some sounds with different frequencies? What happens if I play a 44100Hz sound?
Thanks is advance.
Posted 10 months ago # -
@Dani - yeah, that just relates to the recommendation Apple used to make in their best practices. They recommended setting the mixer rate and all samples to the same rate in a couple of their WWDC talks (probably 2009/2010). I don't think it is relevant any more unless you are supporting 1st gen devices.
When you set the mixer rate as you have done then you can still play sounds with different samples rates. However, if the mixer rate is set to 22050 then 44100 sounds will be mixed down to that rate so a good rule of thumb would be to set the mixer rate to the same rate as your highest sample rate.
Posted 10 months ago # -
@Steve Olmeadow: Ah, ok, thank you very much, man. I see all this audio issue clearer now, and I was making some mistakes, so I have to update my projects!
Posted 10 months ago # -
hi @Steve Oldmeadow,
thank you for the information. this is very helpful.
just a quick question, I have a background music that I'd like to convert to CAF using your below command:
- afconvert -d aac -f 'caff' -b 131072 background-music-lei.caf test_128.caf
However, my background music is in mp3 format. Do I need to use wav to convert to caf and then use the above command or i can use the below command to convert from mp3 direct to caf ?
- afconvert -d aac -f 'caff' -b 131072 game_theme.mp3 game_theme.caf
Thank you in advance for your help
Posted 9 months ago # -
@jcljk - afconvert can convert any format it supports to any other format so there is no need to convert your mp3 to wav. Your command looks okay to me but I'm not an expert on afconvert syntax. You may need to play around with it a bit. afconvert has help. Just use afconvert --help.
Posted 9 months ago # -
Hi @Steve Oldmeadow,
Thank you for your reply.
So, you are saying that there is no difference between converting from wav to caf or mp3 to caf (in quality or performance)
To my understanding, wav is raw format whereas mp3 is encoded.
Wont we lose quality if we convert from mp3 instead of wav?Posted 9 months ago # -
Yes, you will get better quality converting wav to a compressed format than converting a compressed format to another compressed format. All the compressed formats are lossy which means quality is lost. I thought you only had the file as an mp3.
Having said that, I doubt the average person would hear any difference between a high quality mp3 and a wav. Especially through the speaker or headphones of a mobile device.
Posted 9 months ago # -
Thank you Steve. You are very helpful. I will try to get the wav file and convert it to caf.
Posted 9 months ago # -
@Steve
'As for the internals of CocosDenshion, you are correct all sounds are uncompressed when they are loaded. They are stored in memory in little endian linear PCM format which is like the native internal audio format (often called canonical format).'.
Do you think it might be worthwhile to look into keeping IMA4 files in memory and playing directly from there? On Ray Wenderlich's page that you suggested, it says IMA4 files can be played "quite quickly and simultaneously" (which I assume means playing them without first converting into linear PCM in memory while loading).We have a game with run-time memory limitations even after optimising the graphics quite a bit, so every little bit helps.
(Sorry to bring back this thread, but it was one of the best search results for iOS audio formats, so thanks!)
Posted 4 months ago # -
LPCM 16bit 22kHz mono for sound fx, .caf.
IMA4:1 16bit 22kHz mono for music, .caf.Posted 4 months ago # -
There's a nice utility app (free) in the Mac OS X App Store called Hoot that will batch convert files to .caf. It's probably just wrapping afconvert, but you can drag files from the finder.
Posted 4 months ago #
Reply
You must log in to post.