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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 11-05-2009, 07:27 AM   #1 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default Audio slows down my app...

Hi there!

After successfully implement audio in my app I've found a problem. In the simulator everything goes right, but in the device the app slows down when a sound is going to be played (pausing a moment just before it is played), wich is a problem... I think it's not caused by file size because sounds are really small (33 KB, 53 KB, 12 KB...), but I don't know what's happening. I just call the play method:

...
[soBtnClick play];
...

And soBtnClick is an instance of a class called Audio wich inherits from AVAudioPlayer and wich play method is simply:

- (void)play
{
[player play];
}

Where player is an instance of AVAudioPlayer.

What can be causing my app to slow down? Any idea?

Thanks in advance!
Johanovski is offline   Reply With Quote
Old 11-05-2009, 03:21 PM   #2 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Does it happen every time or just the first time? I have this issue the first time - I assume the phone just doesn't load the audio player code until it needs it. You could probably fake it out by instantiating AVAudioPlayer at the beginning of your app.
jsd is offline   Reply With Quote
Old 11-05-2009, 03:47 PM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

This is a common problem with avAudioPlayer, though you can use prepareToPlay to "prime" them before playing. What's your file type? An mp3 takes more cpu, and the system can only play (or prepare) one mp3 on the audio hardware at a time (the second one must be play through software - slower). So you could try wav.

You may have to switch to OpenAL if wavs aren't better. IMA4 them to get them small as possible.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 11-09-2009, 05:16 AM   #4 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default Found it!

I've found it, thanks!
My audio files were compressed format and playing it required a small CPU time to prepare it, wich causes my app to slows down. I've converted sound to uncompressed format (.wav) and the problem solved!

Thanks for all! ^_^
Johanovski is offline   Reply With Quote
Old 03-16-2010, 12:42 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: Northern Ireland
Posts: 54
Default

Im having the same problem but don't know how to prepare the sound i'm using AvAudioToolbox as well and the wav files are tiny but i still get a lag the first time they are run sample code would be really handy.
johnblack45 is offline   Reply With Quote
Old 03-19-2010, 03:18 AM   #6 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default

Hi John!

Well, have to say that since this my sound engine structure changed a lot. I realized that playing sound with AVAudioPlayer isn't the best way so now I'm using AVAudioPlayer to play music (in .mp3 format) and OpenAL to play sounds (which I convert to .caf files). There are some great OpenAL tutorials in the Apple page and also some examples on how to use it. For the sound files I recommend you to convert them to .caf, which I think it's iPhone best format for sounds. To convert them you can use the terminal and type:

Code:
afconvert -f caff -d LEI16@22050 -c 1 yourSound.wav yourSound.caf
Note function's parameters:
- LEI16: This refers to sound Khz, so if you want your sound to have 32 Khz you must type 32 instead of 16.
- @22050: This refers to bit rate, so in this example sounds are converted to 22050 bits, but you may want to convert them to 44100...
- -c 1: This refers to the number of channels. Here I'm converting sounds to mono (because instead the user uses headphones a stereo sound is not appreciable with the iPhone and it just mean more file size so you may want to optimize it to prevent memory troubles...

And that's all I can say about this... AVAudioPlayer for music files in .mp3 format and OpenAL for sounds in .caf format!

Hope it helped!
Johanovski is offline   Reply With Quote
Reply

Bookmarks

Tags
audio, avaudioplayer, play, slowdown

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: 260
20 members and 240 guests
2WeeksToGo, ADY, BrianSlick, dacapo, Dani77, Dattee, Duncan C, headkaze, IphoneSdk, jemicha, kapps11, mer10, mgon987, Punkjumper, sneaky, timle8n1
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,743
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

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