Skip to Main Content Skip to Search
Accelerating the pace of engineering and science

Why do I receive an error about "incorrect chunk size" when using WAVREAD in MATLAB?


Date Last Modified: Tuesday, January 10, 2012
Solution ID:   1-1BZMF
Product:   MATLAB
Reported in Release:   R13sp1
Platform:   All Platforms
Operating System:   All OS
 

Subject:

Why do I receive an error about "incorrect chunk size" when using WAVREAD in MATLAB?

Problem Description:

Using the following code:

wavread('myfile.wav')
I receive the following error:

??? Error using ==> wavread
Error using ==> wavread
Incorrect chunk size information in WAV file.

Solution:

The WAV-file that you are trying to read is most likely constructed improperly. There are two numbers written into WAV-files that are related to the size of the file itself. If these numbers are incorrect, you will receive this error.

The following function can fix your WAV-file. However, you should create a backup copy of your file before running the following function since it modifies the file.

function wavchunksizefix( filename )

d = dir(filename);
fileSize = d.bytes;
fid=fopen(filename,'r+','l');
fseek(fid,4,-1);
fwrite(fid,fileSize-8,'uint32');
fseek(fid,40,-1);
fwrite(fid,fileSize-44,'uint32');
fclose(fid);
The function is run this way:

wavchunksizefix('filename.wav')

Please provide feedback to help us improve this Solution
Contact support