From Thursday, May 23rd (05:00 PM CDT) through Friday, April 24th (1:30 AM CDT), 2024, will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.


Showing results for 
Search instead for 
Did you mean: 

Why can't MathLab read NI wav files? Compression type errors from wav header.

Go to solution
I am writing, 1-n channel, 24 bit wav files using the standard NI Sound File Open/Close/Write(DBL) vi's found in LabVIEW 8.6\vi.lib\sound2\lvsound2.llb. Data for this application is being acquired from an NI-9234 via USB-9162 or NI-cDAQ-9172. My wav files are readable by many wav file readers, including media player (1-2 channels), SoundForge and my own LabVIEW wav file readers. However, MathLab fails to read these files claiming that they can not deal with compressed wav format. As we read in the NI documentation, these files are uncompressed. I found a wav header reader via the discussion forums and read my wav file in. The compression code that was printed was -2 instead of 1 for uncompressed. Has anyone had similar problems reading into MathLab? Does anyone know anything about the significance of a -2 for compression? My guess is that there is a word size problem here that MathLab can not deal with, or that NI is not treating correctly.
0 Kudos
Message 1 of 12

If 24 bit is used a -2 is used. If 16 bit is  used the expected 1 is to be found. Could it be that matlab do not handle 24 bit?


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 2 of 12
Thanks for the quick reply. My understading was that the compression should be set to 1 (for uncompressed) whether it was 16 bit or 24 bit. We've used SoundForge to strip off one channel and re-write it to a new wav file as 24 bit data. These re-written files are readable by MathLab and their compression is denoted by a 1 instead of a -2. Another difference between the 2 wav files is that the original has a format length of 40 and the new file has a format length of 16 bits. This does not seem to be due to the difference in number of channels.
0 Kudos
Message 3 of 12
I did a quick search on the net and found out that FEFF means two thing. More than 2 channels or 24 bit. The wav file is just a binary file so just replace 0xFEFF with 0x0100. This should work. Just write in the bytes 0x0100 at index 20. You may use labview or a hex editor

Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Message 4 of 12
Thanks, I'll give this a shot and let you know how it goes. I've tried writing a single channel of data to the wav file but the compression indicator is still set at -2. With everything I've read, "1" stands for an uncompressed PCM data file. None of the formats point to negative values for compression. What is the sorce of your wav format documentation?
0 Kudos
Message 5 of 12

cb3 wrote: 
What is the sorce of your wav format documentation?

Sad to say not good. I quick and dirty Goggled it. I did not get any smarter. But I did not put so much effort into it. 😉  But it is a reason for that the FEFF is put in. At the same time I came to the same conclusion as you. And so do Matlab. Take a look here


Message Edited by Coq rouge on 06-12-2009 10:49 PM

Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 6 of 12
Accepted by cb3

Well, I've learned quite a bit more since last we communicated. The standard MatLab wav reader is wavread.m. This script should be able to read multi channel 24 bit files; but it doesn't read the files from LabVIEW. We've located a modification to this script called wavexread.m which was developed to read wav files that use WAVE_FORMAT_EXTENSIBLE. This format was developed by MS as an extended format to write multi channel 24+ bit files with other included information. The LabVIEW wav files are readable by MatLab via use of this script. Essentially the script ignores the formatting as though the compression setting for the PCM format was set to 1 (instead of -2 or as we know it, "FEFF"). I did try re-writing the binary wav file and replaced the "FEFF" with "0100". This file was readable by the stock wavread.m but not the extended wavexread.m; further hiliting the fact that MatLab really shouldn't care.

However, I will throw this back to NI to ask whether it is really necessary to use the extended format to write these files when the standard format would sufice. It sure would have made life much simpler if my customer hadn't needed to worry about this.

Thanks for you help.

0 Kudos
Message 7 of 12



I am facing the same problem. but I didn't understand how to fix it.


Should I use the wavexread.m in the Matlab ? and if yes, where can i find this script or function (as I searched for it but I couldn't locate it)

or Should I make these transformation from 0xFEFF to 0x0100 ? and also if yes, how can i make it?


Many thanks,


0 Kudos
Message 8 of 12

I've attached the MATLAB scrit, wavexread.m. Just remove the suffix, .txt.

You can also find it at


Good luck.

0 Kudos
Message 9 of 12

Many thanks for your reply and sending me the .m file

But unfortunately, it does not work, it says:"incorrect chunk size information in wave file".

Do you know what should I do ?!

0 Kudos
Message 10 of 12