user2133807
user2133807

Reputation: 53

Web Audio API on iOS Memory crash

We are using Web Audio API to play and manipulate audio in a web app. When trying to decode large mp3 files (around 5MB) the memory usage spikes upwards in Safari on iPad, and if we load another similar size file it will simply crash.

It seems like Web Audio API is not really usable when running on the iPad unless we use small files.

Note that the same code works well on Chrome Desktop version - Safari version does complain on high memory usage.

Does anybody knows how to get around this issue? or what's the memory limit for playing audio files using Web Audio on an iPad?

Thanks!

Upvotes: 1

Views: 786

Answers (1)

HankMoody
HankMoody

Reputation: 3174

Decoded audio files weight a lot more in RAM than on disk. A single sample uses 4 bytes (32-bit float). This translates to 230 MB of RAM for 10 minutes of audio at 48 000 Hz sample rate and in stereo. One hour of audio at the same sample rate and with stereo will take ~1,3 GB of RAM!

So, if you decode a lot of files, you can consume big amounts of RAM. My suggestion is to "undecode" files that you don't need (just "forget" unneeded audio buffers, so garbage collector can free memory).

You can also use mono audio files instead of stereo, that should reduce memory usage by half.

Note, that decoded audio files are always resampled to device's sample rate. This means that using audio with low sample rates won't help with memory usage.

Upvotes: 3

Related Questions