Search code examples
matlabfilewavwave

Reading large size wav files in MATLAB


I want to read 80 MB wav file in MATLAB. I tried wavread and audioread functions but I could not read it. I splitted wav file when I was reading by wavread(file, [startpos endpos]). But in 50. iteration the program has broken. I could not read file completely. It works for wavread(file, [1 500000]), but doesn't work wavread(file, [50000000 50500000]);

In import menu I can import 30 MB wav file directly but when I try to read step by step with for loop, it has been broken.

I changed Java Heap Memory to 560 MB from preferences.

I am waiting for your recommandations. Thanks.

%%Mycodes

 path = 'asdf\asdf';

  ss = dir(path);
  L = ss.bytes; % Data length

  p = L/100; % I read %1 of data for each step

  data = zeros(L,1);

  for i = 1 : 100

    startpos = (i-1)*p+1;
    endpos = i*p;


    data(startpos:endpos) = wavread(path, [startpos endpos]);

  end

Solution

  • You are calculating L wrong. That's the number of bytes, but not the number of samples. A typical audio file has more than 8 bits/sample. Besides the file size includes the header information.

    Use audioinfo to get L