sound file - out of memory

2 views (last 30 days)
Alon on 15 Apr 2014
Commented: Walter Roberson on 15 Apr 2014
Hello, I wrote a code loading several sound files and viewing their frequency/time domains. The code works well with a sound files less than 15/20 seconds. A problem occures when I try to load a sound file that is (for example) 3 minutes. Only loading the samples to a vector makes my 4GB memory to catch up 3.9GB. What can I do to optimize the problem? Thanks

Answers (1)

Walter Roberson
Walter Roberson on 15 Apr 2014
Increase your RAM (and use a 64 bit operating system).
Or read portions of the data instead of the whole file. For example if you do not care about frequencies below 10 Hz (because they are not audible to humans) then you only need to handle 1/5 of a second of data at a time. 15 seconds of 44 kHz audio is sufficient to resolve down to 3 microhertz.
Walter Roberson
Walter Roberson on 15 Apr 2014
Yes, you can read using a loop. Have a look at and see the parameters it has. Notice the default overlap is half of a window. This suggests that for a window of even width N, you can:
curpos = 1;
start loop
thiswindow = read samples curpos : curpos + N - 1;
process the data in thiswindow
curpos = curpos + N/2;
end loop
as an outline. You can make it more efficient than that, though.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!