PDA

View Full Version : Sound works in simulator but not in device?


kohjingyu
07-06-2009, 02:04 AM
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?

drunknbass
07-06-2009, 02:13 AM
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'.

kohjingyu
07-06-2009, 02:49 AM
Oh...Then how am I supposed to play sounds?

drunknbass
07-06-2009, 03:39 AM
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.

kohjingyu
07-06-2009, 05:38 AM
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.

kohjingyu
07-06-2009, 07:01 AM
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?

monteboyd
07-06-2009, 07:16 AM
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.

kohjingyu
07-06-2009, 07:28 AM
Yup I specified the right file. Hmm, anyone knows how to use the terminal conversion thing? I can't get it to work.

Stroffolino
07-06-2009, 08:36 AM
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.

kohjingyu
07-06-2009, 09:08 AM
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.

Stroffolino
07-06-2009, 02:50 PM
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.

It's possible to export sounds as aiffs within itunes. A .caf is simply an aiff with its suffix renamed. That being said, it's possible to play .wavs on both simulator and device.

kohjingyu
07-07-2009, 03:43 AM
Yup, so I got sounds files with a .caf extension. They worked perfectly. :)

Now...Anyone know of a good free audio editor besides Audacity?

Stroffolino
07-07-2009, 08:22 AM
Yup, so I got sounds files with a .caf extension. They worked perfectly. :)

Now...Anyone know of a good free audio editor besides Audacity?

Audacity is "ok" but I much prefer GoldWave (free, fully functional demo) on PC. With GoldWave it's super easy to export sounds with exactly the bits per sample and frequency you like.