★ TouchArcade needs your help. Click here to support us on Patreon.

Sound works in simulator but not in device?

07-06-2009, 02:04 AM
#1
Joined: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
Sound works in simulator but not in device?

Hey guys,
So I play a sound when I press a button, and when I run it in the simulator, it works, but when I put it in my device, it doesn't work. The volume was at full, and the silent switch wasn't off. Anyone know what to do?
07-06-2009, 02:13 AM
#2
Joined: Nov 2008
Posts: 128
if you are using a method to play sounds that depends on it being pre allocated before you play it, sometimes the speed on your computer will make it seem as if its working in simulator when really the code isnt meant to work that way and youre getting 'lucky'.

07-06-2009, 02:49 AM
#3
Joined: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
Oh...Then how am I supposed to play sounds?
07-06-2009, 03:39 AM
#4
Joined: Nov 2008
Posts: 128
Quote:
Originally Posted by froggy1233 View Post
Oh...Then how am I supposed to play sounds?
dont allocates these sound fx right when you play them.. usually you pre allocate them and keep them in mem till you know youll never need it again.. aka beginning of level, etc.
07-06-2009, 05:38 AM
#5
Joined: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
Quote:
Originally Posted by drunknbass View Post
dont allocates these sound fx right when you play them.. usually you pre allocate them and keep them in mem till you know youll never need it again.. aka beginning of level, etc.
Oh ok thanks. No wonder it worked in my other app.
07-06-2009, 07:01 AM
#6
Joined: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
Okay, so I preloaded my sounds in viewDidLoad. They play in the simulator but not in the real device. I don't understand, it works for my other app...Does the file extension .m4a work?
07-06-2009, 07:16 AM
#7
Joined: Jan 2009
Location: Sydney, Australia
Posts: 111
Maybe a long shot but check you are loading the exact right case for your sound files, e.g. you are loading "Sound.m4a" and not "sound.m4a" if your file is saved as "Sound.m4a".
The device has a case-sensitive file system whereas the simulator does not.

Having said that I can't tell you if m4a works or not.
07-06-2009, 07:28 AM
#8
Joined: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
Yup I specified the right file. Hmm, anyone knows how to use the terminal conversion thing? I can't get it to work.
07-06-2009, 08:36 AM
#9
Joined: Apr 2009
Location: Pennsylvania
Posts: 1,006
Quote:
Originally Posted by froggy1233 View Post
Yup I specified the right file. Hmm, anyone knows how to use the terminal conversion thing? I can't get it to work.
Which APIs are you using to play back the sounds? I've ran into plenty of .wav files that played fine in the simulator, but not on a real device. Reducing their size (by reducing frequency or bytes per sample) was almost always to get them working.
07-06-2009, 09:08 AM
#10
Joined: Mar 2009
Location: Singapore
Posts: 1,770
Send a message via AIM to kohjingyu
Quote:
Originally Posted by Stroffolino View Post
Which APIs are you using to play back the sounds? I've ran into plenty of .wav files that played fine in the simulator, but not on a real device. Reducing their size (by reducing frequency or bytes per sample) was almost always to get them working.
I'm using <AudioToolbox/AudioServices.h> It's a short sound, about 1 second or so only. I'm pretty sure it's the file type, since I used the same method in another app and it worked. Does anybody know how to convert it to a .caf file? I heard of using terminal, but somehow I can't get it to work.