views:

51

answers:

2

Hi,

I am building a game with 20 levels and have around 15 music files. Currently I am preloading all the 15 sounds using cocos denshion at the start of the game. However the game crashes after a few levels. I get a 'Program received signal: “0”. Data Formatters temporarily unavailable' error. I assume this is because of lack of memory to run the game.

Is this happening due to the preloading of the sound files? What is a good practice? Is it better to pre-load a sound before each level where it is used?

Your advice is much appreciated.

Thanks AC

A: 

it depends on the size of the files (and how they are stored in memory), as well as any additional buffers. you'll probably only need a few on hand at any given time - could you just load a few you'll need for a given level, and then unload them at the end of the level?

even better: AudioToolbox.framework also has routines for incremental reading of files for playback. you could get by with realtime (buffered) reading from disk, if memory were very scarce. again, it depends on the amount of memory the sound files consume when loaded and how you use them (e.g. they may be short and looped -- the info is not in the description).

Justin
Hi Justin, the sound files are around 190kb each. It is a small file which is looped. Right now I am loading these sound files altogether at the start. I am using a buffer to store them. I just don't know if cocos uses a separate buffer for sound files and a separate buffer for textures. Sometimes when it crashes it gives me a Level2 memory warning and then deallocates all the textures. I am not sure if this may be caused due to the sound files too. Either way I just want to know the best practice in pre loading sounds.Just to clarify: I need only one sound at a time for each level.
abhinav
190k is not significant for audio. i am assuming that the file is lpcm. if it is compressed, then your audio engine could convert it to native lpcm on load (and consume several times the memory). if it is lpcm (and the memory consumed is about that of the file itself), then i wouldn't worry about streaming from disk - i would just load/unload at level changes. it's a good idea to figure out how much the implementation actually uses, especially if you continue to hit the memory ceiling. that should reduce your memory consumption by a few MB, and should be pretty fast - including faster launch
Justin
A: 

Run instruments to get an idea of how much memory is being used, you should be able to tell if this is the issue and then test out the load one or two at a time method in there. You can also unload sounds on receiving a memory warning.

Ben
Instruments is not helping much. I am looking for a good sound engine that gives me control to load an unload when I want. Any suggestions?
abhinav