ofSoundPlayer large RAM usage


I’m working with ofSoundPlayer on a Beagle Bone Black(BBB), where I am dynamically loading, playing and unloading audio files. Due to memory contraints on the BBB I’m having to be very careful with memory usage.

I’ve noticed that when a .wav audio file is loaded into memory, it takes up 6x the filesize in the ram. i.e if I load a 20mb file, then it takes up 120mb of RAM. Or if I load a 5mb file in RAM then it takes up 30MB of RAM. When the ofSoundPlayer object is deleted then the memory is freed up again so I dont seem to be suffing from a memory leak.

Is this normal? 6Xfilesize seems an awful lot of RAM to use for each soundfile!



Don’t know this topic too intimately, but two things come to mind.

Does the .wav file contain a compressed audio? Usually it doesn’t, but it can, which could account for it.
Have you tried loading the sound as a streaming file? Might help.

 bool loadSound(string fileName, bool stream = false);

It’s probably something else, but worth a shot!


Cheers for the ideas!

RE: Does the .wav file contain a compressed audio?
No they are 16bit uncompressed… so its still a mystery.

RE: streaming
Thats my next port of call :wink: though it would be much better to use non streaming files…

maybe the audio files are getting resampled in terms of sample rate and / or having their bit rate changed on load, which would account for differences in RAM ?

the sound player in linux stores a copy of the whole file in float format to do the fft on the fly, it also uses 16bits no matter what the original file is, so if your file is 8bits that would explain the extra size. 2x from 8 -> 16bit + 4x more of the float buffer for the fft.

that class needs some serious refactoring but right now all you can do is load the files in stream mode which will use way less memory

Thanks for all the ideas everybody. The files are 16bit so that shouldn’t be the issue. I’d be interested to see if other people notice the same kind of memory usage.

In the mean time i can continue with a small bit of code that loads or streams depending on the available memory. Out of interest is there a recommended way to grab free available memory? At the moment i’m just grabbing the output of a system command:

ofSystem("free | grep Mem | awk '{print $4}'")

Which works, though I’m always ready to learn new ways!