Matlab shuts down during loop using audiowrite
4 次查看(过去 30 天)
显示 更早的评论
I'm running a loop going through a series of wave files in a folder. The loop calls my audiochange function (a very basic version, still causing the issue, is shown below).
When it gets somewhere between 450-500 files in (depending on the folder I am running this on) - Matlab shuts down with no error messages/logs showing up anywhere. I'm assuming this means I'm swamping the memory.
However, I have monitored task manager, and I also embedded some lines that gave me a 'log' file of the outputs from the function 'memory' - there are no increasing memory use or spikes in either place. I have 16 GB of system memory, with 9 GB available; approximately 3GB are being used by Matlab when it is running this code using R2023a.
My input files are 96kHz, 10 minutes long, 16 bit. It crashes when I try to write out 10 minute files; however when I read/write out 1 minute files - Matlab still shuts down at the exact same input file. When I restart Matlab and start at the input file that crashed - it runs fine for another 450-500 files. There is still around 1TB of space on the drive that I am writing to.
When I comment out the audiowrite line it runs through the whole folder without crashing. Seems like if the issue is loading the variable newWave multiple times with audioread, it should crash, but it doesn't.
I will put in a request with my IT department to update to the latest version of Matlab tomorrow; but curious if there is any other solution if that gives the same result.
recordLength = 10; % this is original wave file duration
fileLength = 10; % this is my output file duration, I have also tried fileLength = 1.
for n = 1:num_files_in_folder % varies per folder
for m = 1:recordLength/fileLength
ssamp = 1+filelength*(m-1);
esamp = min(filelength*m,recordlength);
filename_read = ['<myreadpath\myreadfilename>'];
filename_write = ['<mywritepath\mywritefilename>'];
audiochange(filename_read,filename_write,ssamp, esamp)
end
end
function audiochange(filename_read,filename_write,ssamp, esamp)
[newWave,fs] = audioread(filename_read,[ssamp esamp]);
audiowrite(filename_write,newWave,fs);
end
0 个评论
回答(1 个)
Walter Roberson
2024-2-26
I suspect that you are running into a limit on open files -- I suspect that audiowrite() is not closing files.
You could experiment with using
fclose('all')
every 100 files or so. Might work, might not
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!