-3

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
yilmaz
  • 1
  • 4
  • what error message do you get? – m.s. Jul 29 '15 at 09:36
  • Error using wavread (line 165) Invalid wave file. Reason : Sample limits out of range. – yilmaz Jul 29 '15 at 10:14
  • 1
    post a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – m.s. Jul 29 '15 at 10:19
  • can you specify your sampling rate and whether it is single or dual channel? Since there is a maximum limit on the length of a vector (length of your matrix), you must chop your file into smaller chunks where each chunk must produce the same vector length (which generally imply same time length) to be able to loop through and concatenate into a matrix. – GameOfThrows Jul 29 '15 at 10:25
  • The error Sample limits out of range might suggest that your file does not contain as many as 50,500,000 samples, meaning that it might have ended at 50,499,999, in which case you will either have to pre-allocate a zero matrix, or fill the 51st row where the length isn't enough with zeros – GameOfThrows Jul 29 '15 at 10:28
  • could you try wavread(file, [50000000 end]) and see the size of your result? – GameOfThrows Jul 29 '15 at 10:29
  • My data ends 80.000.000. I try to read 100 step with for loop. I could not read wavread(file, [50000000 end]). It gives error. Sampling rate and single/dual channel? What it is for? I create a variable with zeros big enough and try to fill it. But it gives error on 51. iteration. – yilmaz Jul 29 '15 at 10:42
  • %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 – yilmaz Jul 29 '15 at 11:01

1 Answers1

1

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

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Thanks. I wrote pseudo code. But my problem is I couldn't read 80 MB wav file in MATLAB anyways. – yilmaz Jul 29 '15 at 11:33
  • Please explain your problem in a way we can reproduce it. m.s. already gave you the guideline how to describe such problems. – Daniel Jul 29 '15 at 11:36
  • Suprisingly I can read data from "Import Data" section even if 80 MB size. I did not change anything. I tried auidoread/wavread(filename). It reads both. Thanks for your help. Maybe my pseudo code serves somebody help. – yilmaz Jul 29 '15 at 11:56