Simple Tutorial: Shrink Audio Footprint for use with AudioServicesPlaySystemSound
I'm posting this because I've spent 2 weeks fruitlessly scanning the web for a clear and straightforward explanation on how to use AudioServicesPlaySystemSound (soundID); and not have to use GARGANTUAN mothership WAV files. So hopefully posting this will save someone some time.
audio must be less than 30 sec
audio must be PCM or IMA4 formats
audio must be in .caf, .aif, or .wav
audio can’t play from memory
audio play from disk files
audio play immediately
audio play at existing sound level
audio can’t play loop
audio can’t manage stereo
So, NO mp3, aac, etc....
If you used AudioServicesPlaySystemSound heavily in your App like I did, and it worked PERFECTLY - and then found out that your audio folder was a BILLION mb too big for an iPhone app, here's what you do:
In Terminal, locate the folder containing only your audio files (I had 70 of em), using the command: "cd [insert folder directory here]" (ex. "cd documents/audio") You can hit "pwd" (print working directory) to see if you're in the right place.
Then, copy and paste the following into Terminal, assuming your beginning files are WAVs:
Code:
ext="wav"
for f in *.$ext
do time afconvert -v -f caff -d ima4 -c 1 $f
done
Hit enter.
(Sidenote for the newbs: afconvert is a MacOS Leopard built-in audio encoder - to see all it's options, type "afconvert -h" into terminal)
It will work away, converting all your audio into .caf files, at a most wonderful compression rate (I went from 33mb to 4mb) and the finished files will play flawlessly with AudioServicesPlaySystemSound.
THANK THE MAKER I got this one cased - it was keeping me up a night.
Post below if this helped you!
Some words for search: encoding compression shrink files down smaller audio codecs AudioServices SystemServices
Last edited by GRANDxADMIRAL; 05-14-2009 at 12:44 PM.
I'll test this out tonight and see how much smaller my audio files get. I'm hoping to see the same ratio that you achieved. Hopefully the sound quality is still good
1) You are in the directory with your audio files? (If you hit "pwd" it tells you?)
2) You are starting with WAV files? How many do you have? Are they the only thing in the directory? (Not sure if that matters, but being safe)
I produce the same error when I'm in the wrong DIR. If you can get it to pop an error as many times as you have files, you know you're in the right directory, with the wrong afconvert setttings.
Keep in mind that the .ipa is compressed (it is just .zip).
So, it may not matter much to pre-compress your assets. Of course, if your assets are compressed, it will take less space on the user's iPhone. However, the impact on the deliverable size is minor.
Keep in mind that the .ipa is compressed (it is just .zip).
So, it may not matter much to pre-compress your assets. Of course, if your assets are compressed, it will take less space on the user's iPhone. However, the impact on the deliverable size is minor.
I do believe the compression is different though, because ima4 compression actually rewrites the audio files using algorithms to "predict" 3/4 of the remaining data, leaving only 1/4 and the algorithm to take up space. If you ZIP a wav file, you only save about 1/10.
I think it's definitely worth compressing assets before final build.
well, there you go! i was using aif not wav files... extremely embarrassing!!! i didnt want to post this but maybe someone else will be as stupid as me :S
size reduction was excellent. i have 48 sounds that were about 18 mb now they are under 5 mb!! happy about that!!!
I'm posting this because I've spent 2 weeks fruitlessly scanning the web for a clear and straightforward explanation on how to use AudioServicesPlaySystemSound (soundID); and not have to use GARGANTUAN mothership WAV files. So hopefully posting this will save someone some time.
If you used AudioServicesPlaySystemSound heavily in your App like I did, and it worked PERFECTLY - and then found out that your audio folder was a BILLION mb too big for an iPhone app, here's what you do:
In Terminal, locate the folder containing only your audio files (I had 70 of em), using the command: "cd [insert folder directory here]" (ex. "cd documents/audio") You can hit "pwd" (print working directory) to see if you're in the right place.
Then, copy and paste the following into Terminal, assuming your beginning files are WAVs:
Code:
ext="wav"
for f in *.$ext
do time afconvert -v -f caff -d ima4 -c 1 $f
done
Hit enter.
(Sidenote for the newbs: afconvert is a MacOS Leopard built-in audio encoder - to see all it's options, type "afconvert -h" into terminal)
It will work away, converting all your audio into .caf files, at a most wonderful compression rate (I went from 33mb to 4mb) and the finished files will play flawlessly with AudioServicesPlaySystemSound.
THANK THE MAKER I got this one cased - it was keeping me up a night.
Post below if this helped you!
Some words for search: encoding compression shrink files down smaller audio codecs AudioServices SystemServices
I owe you big time! This is amazing!!!!
__________________
Haters gonna Hate
Likers gonna Like
Last edited by Bertrand21; 08-09-2010 at 12:16 AM.
Reason: Spelling!