Questions regarding memory.

Hi,

1- How much memory is available to us and safe to assume we have on both Android 2.2+ and iOS?

2- My game was using memory around 4 Mb and I included a 2 second mono MP3 file but now the memory usage rocketed to 26 Mb ! Is it due to nature of MP3’s that get decoded into WAV upon execution and WAV’s are large? If music is that big, what about when I want to load a music which consists of at least one minute!

3- How I can minimize memory usage of audio files?

Thanks. [import]uid: 206803 topic_id: 35842 reply_id: 335842[/import]

Hi Aidin, the first one is tough to answer. No OS/Device combination is going to guarantee you any minimum free space. Most devices on the market today should be 512megabytes or more and assume you can get to a quarter of that, would be 64mb. But if you hit an older 256mb device, that’s like 32mb. That’s totally a guess. There are too many factors at play.

  1. I’m not sure why a 2 second audio clip would have sky rocketed your memory like that. Audio does eat up memory, bit one 2 second clip shouldn’t be that much. MP3 is a highly compressed format and it does have to uncompress it in memory (basically a WAV file). Sounds like something else is going on there.

  2. Audio memory is determined by 3 factors: length of clip, number of channels (mono = 1, stereo = 2) and the “bitrate” which is how accurate the sound is over a given time frame. Most best practices are to use mono tracks as most devices don’t have stereo speakers or the speakers are not of good enough quality to matter. The next thing can do is resample your clips to 11khz sounds instead of 44khz. Many bits of audio are at the higher bit rate and those will eat up memory pretty quickly. Use a program like Audacity to resample, to 11khz, make it mono, trim any dead air out.
    [import]uid: 199310 topic_id: 35842 reply_id: 142576[/import]

Just jumping onto this thread, regarding point 3 answer - i frequently read that for mobile games/apps, mono tracks are preferred. As mentioned, this cuts down file sizes and will still play fine on the smartphone speaker. The sounds i am currently using on my game are mono too but i was actually thinking of redoing them to stereo.

My question is does mono have an impact when using/playing the game/app with headphones on? ie. would you only hear the sound coming out from one earphone, and thus ruining the experience? I ask because i have yet to test my game on an actual device.

Cheers, [import]uid: 175094 topic_id: 35842 reply_id: 143178[/import]

Thanks Rob,

I tried your suggestions but I think there is a problem somewhere else because after I resampled it to 11khz, it went to 12Mb and then I replaced back the old 44khz file but the memory usage kept to be 12Mb !

How can I calculate how much memory (texture and audio) I’m supposed to use? I’m very interested to know what I’m consuming by this 12Mb. I’ve read some data that textures are loaded in smallest squares on iDevices, hence using atlases, but how much a 1024x1024 png would take? Is it’s quality whether being 32 or 16bit important? I’m asking because they may all get to be 32bit when it’s compiled on your servers.

Another question about audio, is it important how I save my audio on disk? Because I think and as you’ve said, it should be decoded and decompressed to WAV on the iDevice in order to get played back (I think same goes with other platforms such as PC as WAV is not compresed).

So if I save my file as variable bitrate vs. constant bitrate, does it change just how much disk space it needs?

Thanks. [import]uid: 206803 topic_id: 35842 reply_id: 143293[/import]

Hi Aidin, the first one is tough to answer. No OS/Device combination is going to guarantee you any minimum free space. Most devices on the market today should be 512megabytes or more and assume you can get to a quarter of that, would be 64mb. But if you hit an older 256mb device, that’s like 32mb. That’s totally a guess. There are too many factors at play.

  1. I’m not sure why a 2 second audio clip would have sky rocketed your memory like that. Audio does eat up memory, bit one 2 second clip shouldn’t be that much. MP3 is a highly compressed format and it does have to uncompress it in memory (basically a WAV file). Sounds like something else is going on there.

  2. Audio memory is determined by 3 factors: length of clip, number of channels (mono = 1, stereo = 2) and the “bitrate” which is how accurate the sound is over a given time frame. Most best practices are to use mono tracks as most devices don’t have stereo speakers or the speakers are not of good enough quality to matter. The next thing can do is resample your clips to 11khz sounds instead of 44khz. Many bits of audio are at the higher bit rate and those will eat up memory pretty quickly. Use a program like Audacity to resample, to 11khz, make it mono, trim any dead air out.
    [import]uid: 199310 topic_id: 35842 reply_id: 142576[/import]

I don’t believe audio shows up in Texture memory, that’s for images only. I also don’t think audio shows up in the Lua memory either.

8bit images or 24bit (well 32 with alpha channel) all unpack into 32bit images. They are rectangular arrays of pixels and and there are 4 arrays (in effect) per image (called color channels), one red, one green, one blue, and one alpha. Think of it as a 3D array. If your image is 480x640 then it will take up a 512x1024x4 block of memory. A 640x960 image will take up a 1024x1024x4 (or 4mb) of texture memory.

On the audio (and this impacts images too), the smaller it is on disc, the faster it is to read into the app. But once it’s unpacked a small MP3 or a larger WAV file occupy the same memory and it takes the same CPU to process it. With Audio though, bitrate and number of channels affects the overall memory size and CPU use too. Stereo, high bit-rate audio tracks don’t compress as well as mono, low bitrate tracks, so they will be bigger on disc, and by nature take up more memory.

[import]uid: 199310 topic_id: 35842 reply_id: 143402[/import]

Just jumping onto this thread, regarding point 3 answer - i frequently read that for mobile games/apps, mono tracks are preferred. As mentioned, this cuts down file sizes and will still play fine on the smartphone speaker. The sounds i am currently using on my game are mono too but i was actually thinking of redoing them to stereo.

My question is does mono have an impact when using/playing the game/app with headphones on? ie. would you only hear the sound coming out from one earphone, and thus ruining the experience? I ask because i have yet to test my game on an actual device.

Cheers, [import]uid: 175094 topic_id: 35842 reply_id: 143178[/import]

Thanks Rob,

I tried your suggestions but I think there is a problem somewhere else because after I resampled it to 11khz, it went to 12Mb and then I replaced back the old 44khz file but the memory usage kept to be 12Mb !

How can I calculate how much memory (texture and audio) I’m supposed to use? I’m very interested to know what I’m consuming by this 12Mb. I’ve read some data that textures are loaded in smallest squares on iDevices, hence using atlases, but how much a 1024x1024 png would take? Is it’s quality whether being 32 or 16bit important? I’m asking because they may all get to be 32bit when it’s compiled on your servers.

Another question about audio, is it important how I save my audio on disk? Because I think and as you’ve said, it should be decoded and decompressed to WAV on the iDevice in order to get played back (I think same goes with other platforms such as PC as WAV is not compresed).

So if I save my file as variable bitrate vs. constant bitrate, does it change just how much disk space it needs?

Thanks. [import]uid: 206803 topic_id: 35842 reply_id: 143293[/import]

I don’t believe audio shows up in Texture memory, that’s for images only. I also don’t think audio shows up in the Lua memory either.

8bit images or 24bit (well 32 with alpha channel) all unpack into 32bit images. They are rectangular arrays of pixels and and there are 4 arrays (in effect) per image (called color channels), one red, one green, one blue, and one alpha. Think of it as a 3D array. If your image is 480x640 then it will take up a 512x1024x4 block of memory. A 640x960 image will take up a 1024x1024x4 (or 4mb) of texture memory.

On the audio (and this impacts images too), the smaller it is on disc, the faster it is to read into the app. But once it’s unpacked a small MP3 or a larger WAV file occupy the same memory and it takes the same CPU to process it. With Audio though, bitrate and number of channels affects the overall memory size and CPU use too. Stereo, high bit-rate audio tracks don’t compress as well as mono, low bitrate tracks, so they will be bigger on disc, and by nature take up more memory.

[import]uid: 199310 topic_id: 35842 reply_id: 143402[/import]

Just jumping onto this thread, regarding point 3 answer - i frequently read that for mobile games/apps, mono tracks are preferred. As mentioned, this cuts down file sizes and will still play fine on the smartphone speaker. The sounds i am currently using on my game are mono too but i was actually thinking of redoing them to stereo.

My question is does mono have an impact when using/playing the game/app with headphones on? ie. would you only hear the sound coming out from one earphone, and thus ruining the experience? I ask because i have yet to test my game on an actual device.

Cheers, [import]uid: 175094 topic_id: 35842 reply_id: 143178[/import]

Thanks Rob,

I tried your suggestions but I think there is a problem somewhere else because after I resampled it to 11khz, it went to 12Mb and then I replaced back the old 44khz file but the memory usage kept to be 12Mb !

How can I calculate how much memory (texture and audio) I’m supposed to use? I’m very interested to know what I’m consuming by this 12Mb. I’ve read some data that textures are loaded in smallest squares on iDevices, hence using atlases, but how much a 1024x1024 png would take? Is it’s quality whether being 32 or 16bit important? I’m asking because they may all get to be 32bit when it’s compiled on your servers.

Another question about audio, is it important how I save my audio on disk? Because I think and as you’ve said, it should be decoded and decompressed to WAV on the iDevice in order to get played back (I think same goes with other platforms such as PC as WAV is not compresed).

So if I save my file as variable bitrate vs. constant bitrate, does it change just how much disk space it needs?

Thanks. [import]uid: 206803 topic_id: 35842 reply_id: 143293[/import]

I don’t believe audio shows up in Texture memory, that’s for images only. I also don’t think audio shows up in the Lua memory either.

8bit images or 24bit (well 32 with alpha channel) all unpack into 32bit images. They are rectangular arrays of pixels and and there are 4 arrays (in effect) per image (called color channels), one red, one green, one blue, and one alpha. Think of it as a 3D array. If your image is 480x640 then it will take up a 512x1024x4 block of memory. A 640x960 image will take up a 1024x1024x4 (or 4mb) of texture memory.

On the audio (and this impacts images too), the smaller it is on disc, the faster it is to read into the app. But once it’s unpacked a small MP3 or a larger WAV file occupy the same memory and it takes the same CPU to process it. With Audio though, bitrate and number of channels affects the overall memory size and CPU use too. Stereo, high bit-rate audio tracks don’t compress as well as mono, low bitrate tracks, so they will be bigger on disc, and by nature take up more memory.

[import]uid: 199310 topic_id: 35842 reply_id: 143402[/import]

Just jumping onto this thread, regarding point 3 answer - i frequently read that for mobile games/apps, mono tracks are preferred. As mentioned, this cuts down file sizes and will still play fine on the smartphone speaker. The sounds i am currently using on my game are mono too but i was actually thinking of redoing them to stereo.

My question is does mono have an impact when using/playing the game/app with headphones on? ie. would you only hear the sound coming out from one earphone, and thus ruining the experience? I ask because i have yet to test my game on an actual device.

Cheers, [import]uid: 175094 topic_id: 35842 reply_id: 143178[/import]

Thanks Rob,

I tried your suggestions but I think there is a problem somewhere else because after I resampled it to 11khz, it went to 12Mb and then I replaced back the old 44khz file but the memory usage kept to be 12Mb !

How can I calculate how much memory (texture and audio) I’m supposed to use? I’m very interested to know what I’m consuming by this 12Mb. I’ve read some data that textures are loaded in smallest squares on iDevices, hence using atlases, but how much a 1024x1024 png would take? Is it’s quality whether being 32 or 16bit important? I’m asking because they may all get to be 32bit when it’s compiled on your servers.

Another question about audio, is it important how I save my audio on disk? Because I think and as you’ve said, it should be decoded and decompressed to WAV on the iDevice in order to get played back (I think same goes with other platforms such as PC as WAV is not compresed).

So if I save my file as variable bitrate vs. constant bitrate, does it change just how much disk space it needs?

Thanks. [import]uid: 206803 topic_id: 35842 reply_id: 143293[/import]

I don’t believe audio shows up in Texture memory, that’s for images only. I also don’t think audio shows up in the Lua memory either.

8bit images or 24bit (well 32 with alpha channel) all unpack into 32bit images. They are rectangular arrays of pixels and and there are 4 arrays (in effect) per image (called color channels), one red, one green, one blue, and one alpha. Think of it as a 3D array. If your image is 480x640 then it will take up a 512x1024x4 block of memory. A 640x960 image will take up a 1024x1024x4 (or 4mb) of texture memory.

On the audio (and this impacts images too), the smaller it is on disc, the faster it is to read into the app. But once it’s unpacked a small MP3 or a larger WAV file occupy the same memory and it takes the same CPU to process it. With Audio though, bitrate and number of channels affects the overall memory size and CPU use too. Stereo, high bit-rate audio tracks don’t compress as well as mono, low bitrate tracks, so they will be bigger on disc, and by nature take up more memory.

[import]uid: 199310 topic_id: 35842 reply_id: 143402[/import]