Using audiowrite function for large array (out of memory)

조회 수: 1 (최근 30일)
Terence
Terence 2020년 3월 3일
댓글: Terence 2020년 6월 29일
Hi guys,
I am processing a WAV file that is over 20 hours in duration (Fs=8,000, 16 bits/sample). I read in each hour of audio separately (using [Y, FS]=audioread(FILENAME, [START END])) and I process the audio signal for each hour no problem. I then need to combine the processed audio data for each hour and write it to a 20+ hour WAV file at the end. However, I don't have enough RAM to do so. I am unable to create an array of such a size. Is there any way of writing these data to a WAV file without bringing this large array itself into memory? Or is there a way of partially writing to a single WAV file in iterations which may allow me to write each hour of data separately to the same WAV file?
I have tried allocating the memory using a .mat file and then dumpng the processed data that way. But I can't write the data in the mat file to a WAV file without bringing it all in to memory. Could a datastore approach work in this instance? Any advice would be appreicated.
Thanks a lot.

답변 (2개)

Nipun Katyal
Nipun Katyal 2020년 3월 6일
There are two work arounds for your scenario:
  1. Since the total memory available to an application comprises of the RAM,and a page file or a swap file, you can increase the swap space on your system, refer to the section "Increase System Swap Space" in the link below.
2. To store large variables matlab provides an implementation of tall arrays, a typical usage to store a huge wav file as mat files is shown below:
DirIn = '<Path to your audio files>';
eval(['filelist=dir(''' DirIn '/*.wav'')']);
% Store the first audio file and append the rest to it.
[yF,Fs] = audioread(filelist(1).name,'native');
yF = tall(yF);
for i = 2:length(filelist)
[y,Fs] = audioread(filelist(i).name);
yF = vertcat(yF,y);
end
write('result',yF,'FileType','mat');

jibrahim
jibrahim 2020년 3월 24일
Terence,
Consider using dsp.AudioFileWriter and dsp.AudioFileReader in DSP System Toolbox. This functionlaity is built to read and write audio files in a streaming, frame-by-frame fashion.
  댓글 수: 1
Terence
Terence 2020년 6월 29일
Thanks for your help. I ended up converting the float audio signals to int16 which and normalising using 2^15 which helped free up RAM.
I appreciate your suggestions. I will try that for sure also.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by