Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-13-2009, 06:50 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 62
GRANDxADMIRAL is on a distinguished road
Default 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.

From Objective-C AudioServicesPlaySystemSound « Web Builders

Quote:
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.
GRANDxADMIRAL is offline   Reply With Quote
Old 05-13-2009, 07:19 PM   #2 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 249
gabacus is on a distinguished road
Default

i love this forum!

this is something i have been wanting to do but have put it off until i got a few other things sorted first...

and now, thanks to you, i do not have to spend hours researching how this has to be done!

THANK YOU SO MUCH!

i will be doing this a soon as i get home
gabacus is offline   Reply With Quote
Old 05-13-2009, 10:29 PM   #3 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
Join Date: Mar 2009
Posts: 292
odysseus31173 is on a distinguished road
Default

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
odysseus31173 is offline   Reply With Quote
Old 05-13-2009, 11:07 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 62
GRANDxADMIRAL is on a distinguished road
Default

Keep in mind the "-c 1" is setting the audio file to mono as well, so that in itself can cut the size in half. Remove this command if you want stereo.
GRANDxADMIRAL is offline   Reply With Quote
Old 05-14-2009, 05:29 AM   #5 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 249
gabacus is on a distinguished road
Default

damn! its not working for me

this is the error i am getting

Quote:
:$ ext="wav"
:$ for f in *.$ext
> do time afconvert -v -f caff -d ima4 -c 1 $f
> done
Error: ExtAudioFileOpenURL failed (-43)

real 0m0.092s
user 0m0.068s
sys 0m0.021s
192-168-1-5:Converted and Compressed eliopoul$
any ideas? its been a while since i did any scripting :S
gabacus is offline   Reply With Quote
Old 05-14-2009, 11:14 AM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 62
GRANDxADMIRAL is on a distinguished road
Default

OK so, asking the easy questions first,

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.
GRANDxADMIRAL is offline   Reply With Quote
Old 05-14-2009, 11:55 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 812
johnqh is on a distinguished road
Default

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.
johnqh is offline   Reply With Quote
Old 05-14-2009, 12:42 PM   #8 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 62
GRANDxADMIRAL is on a distinguished road
Default

Quote:
Originally Posted by johnqh View Post
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.
GRANDxADMIRAL is offline   Reply With Quote
Old 05-15-2009, 01:59 AM   #9 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 249
gabacus is on a distinguished road
Default

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!!!
gabacus is offline   Reply With Quote
Old 05-18-2009, 10:15 PM   #10 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
Join Date: Mar 2009
Posts: 292
odysseus31173 is on a distinguished road
Default

I did this to my group of sound files as well and it worked like a charm. went from 10mb to 3mb. Thanks for the tip
odysseus31173 is offline   Reply With Quote
Old 12-13-2009, 05:13 PM   #11 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 9
windrago is on a distinguished road
Default Awesome tip!

Quote:
Originally Posted by odysseus31173 View Post
I did this to my group of sound files as well and it worked like a charm. went from 10mb to 3mb. Thanks for the tip
Awesome tip man!
windrago is offline   Reply With Quote
Old 08-08-2010, 10:48 PM   #12 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by GRANDxADMIRAL View Post
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.

From Objective-C AudioServicesPlaySystemSound « Web Builders



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
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!
Bertrand21 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 336
7 members and 329 guests
givensur, guusleijsten, ipodphone, jbro, mer10, n00b, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,881
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:07 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0