Jump to content

How do you control memory to use mp3 with IOS


GBear
 Share

Recommended Posts

hI. 

my game is playing BGM by mp3

and using sound.js by createjs (http://www.createjs.com/soundjs) (same when i tested by howler.js )

when i play BGM my game's memory is up 100mb more.. 

my game has 200-300mb memory  when every resource loaded except BGM.

if BGM loaded,  my game is 300-400MB memory 

 

my BGM has '128kb 4:12 playtime'

size is 3.85MB

 

how can i reduce memory with mp3  T-T

Android platform has big memory more than 2mb  if galaxy note3 or later...

but IOS platform has 1GB until Iphone6   

 

T-T..

do you have idea for this.. 

 

 

 

Link to comment
Share on other sites

5 hours ago, GBear said:

how can i reduce memory with mp3 

You can't. You can only reduce file size. When the audio is loaded into memory it is uncompressed, so whatever compression was applied to the data on disk makes no difference whatsoever to the memory it takes up.

Link to comment
Share on other sites

It depends on the specific situation but normally you could try to aim for CD quality but mono, then with as little compression as you can get away with (which normally actually means a LOT of compression!). So that works out as 44.1kHz sample rate, 16bit sound, mono, and then whatever kbps compression you want, maybe around 60ish? Vocals and sound effects can normally be compressed more than music without sounding quite so bad. The more sound you want to use, the more you'll have to compress it to keep your download size acceptable.

Link to comment
Share on other sites

GBear are you able to run some tests over different sound rates - various sample rates, bitrates, stereo vs mono - and measure the ram consumption for each at runtime?  Probably use AAC-MP4 for all (all the benefits of MP3, plus some more, and none of the drawbacks).

The hypothesis being, does it actually make a difference to the decompressed raw data memory consumption, or is the decompressed data a consistent predetermined rate (e.g. 44khz stereo linear PCM)?

Link to comment
Share on other sites

GBear, my understanding is that by providing MP4 (AAC) and OGG (Vorbis) all major targets are covered.  I forget the exact correlation, but typically proprietary browsers tend to MP4 and open source browsers tend to OGG.

To date we have used the MP4+OGG combo (via CreateJS / SoundJS) without complaint (note that "Stock" Android browser results can vary).

For the iOS memory tests I think only using MP4 will suffice - do you think source rates will make a difference?

Link to comment
Share on other sites

I also use the OGG / MP4 combo as described by b10b on SoundJS with no issues. Encoding to AAC gives you better compression and better sound looping than using MP3s

In terms of compression, I went for 64kbits stereo when targetting devices with plenty of memory, such as desktops, and 48kbits mono for most mobile devices. I don't value high quality sound on mobiles; the speakers on devices are usually poor, lots of people turn off sound when playing games on their phone, and most importantly, it's hard enough just getting sound working on mobiles in the first place!

Link to comment
Share on other sites

GBear, I mean do you think source rates will make a difference to memory (RAM at runtime)?

The assumption is yes, but I've never seen a test to validate it - so if the assumption is wrong, there is little benefit (other than bandwidth) in deciding between 48kbps vs 192kbps, or 22khz vs 44khz, or stereo vs mono etc.

Edit: I am asking you because I do not have access to memory profiling tools for iOS

Link to comment
Share on other sites

Doing a little memory profiling on the game I'm working on using Chrome Task Manager. 

I load a single audio sprite, which is 6 minutes 40 seconds long. I tested with both a similarly encoded ogg and m4a, and there was no difference to the results

  • No audio loaded: 94 mb
  • 48kbits 44100hz mono: 171 mb
  • 64kbits 44100hz stereo: 247 mb

So you can see, decreasing the bitrate WILL decrease memory usage. It's up to you to judge at what quality is acceptable. As I mentioned, I personally feel that 48kbits is fine for mobiles, and 64kbits is fine for desktops, but that's my opinion for the type of games that I make.

The other option is of course to decrease the number of sounds that you load for lower end devices. Do not be scared to do this. An iPhone 4s has 512mb of RAM, an iPhone 6s has 2gb; you can't expect the older device to cope with all of the sounds and animations that newer devices can handle. If you trim well enough, for example, the user of an iPhone 4s would never know that there are actually 4 different background tunes to the game; make them happy with the 2 they get! 

Link to comment
Share on other sites

  • 2 weeks later...

I agree, that different devices suit different bitrates and formats .  If I had a lot of audio I would consider writing a small php proxy script that detects user agent and routes to a different audio file automatically at runtime.

 

Interesting results Moonrat, thank you.  However these numbers challenge some of our assumptions as there doesn't appear to be a linear correlation?

Subtracting the 94mb baseline, we have:

48kbits mono at 77 mb for 400 seconds (.004096 mb per kbit per second per channel)

64kbits stereo at 153 mb for 400 seconds (.002988 mb per kbit per second per channel)

Plus these test are on Chrome (desktop?) - not iOS (where sound decompression may be handled differently due to software limits, or proprietary hardware audio playback).

I think we need more tests to arrive at a definitive conclusion (e.g. stereo vs mono comparison at the same bitrate), and on multiple devices.  We also probably need a test where two totally different musical tracks occupy the left and right channels of the stereo test.

Apologies that I am asking rather than providing the results - I am unable to run these tests on iOS because I currently don't have access to a Mac Safari 6 (for a dev console for iOS).

 

Link to comment
Share on other sites

Thanks.  I created some files, but when I compared I noticed that "48kbps" were the same filesize as "96kbps".  So my audio software was unhelpfully ignoring the bitrate settings in favour of a "quality" setting (0-500).  I'm happy to generate files using this arbitrary scale, but it may be less precise than if someone else has a method to properly generate kbps mp4s?

I had groupings for 44khz vs 22khz, stereo vs mono, and 48 kbps per 96kbps.  And one extra with the left hand track reversed for good measure.

 

 

Link to comment
Share on other sites

hi @b10b  @themoonrat

how do you think about wav?

 

bgm will be  used  by mp3. but other sounds like effect, click, skills are don't know  which format used....

if i use mp3, i control by soundsprite but   my games have a lot of sounds  becuase there are many many monsters or skills or etc...

in this case hmm  .

 

 

Link to comment
Share on other sites

Soundsprite may work best if you have dozens of short sounds.  I found that very short mp3s (<1s) caused some problems, often crashing out Safari on iOS - so I needed to add silence on the end.  Also adding some code to ensure that the same sound doesn't play too quickly after last playing is usually a good plan too.

Link to comment
Share on other sites

@b10b oh.. thx..

Quote

 I found that very short mp3s (<1s) caused some problems, often crashing out Safari on iOS 

 

   --b

 

Quote

I needed to add silence on the end.

what's this meaning?      you force sounds to silence on the end ?

Link to comment
Share on other sites

Some browsers, Internet Explorer in particular, struggles to play small sounds. On individual sound files, a sound that's 400ms long might not get played at all, or might get cut off when played. Use audacity to 'pad' the file to 1s second by adding silence onto the end. Internet Explorer then finds it much easier to play these short effects.

It's very similar when in audio sprites. Internet Explorer does not have the Web Audio API, so its 'seeking' to the correct part of the file is of a lower accuracy

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...