From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW corrupts WAV files?

I am using LabVIEW 8.0.1 and the included Sound File Read/Write Simple VIs.  When I generate a waveform, write it to disk then read it back out, I don't get back what I wrote.  WAV is suppose to be an uncompressed format.

Anyone have any ideas?  Example program attached.
Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
0 Kudos
Message 1 of 8
(2,939 Views)
Hi Joe,

you know WAV uses I16 values instead of DBL to store waveforms?
So there can be (or surely is) a difference between waveform before saving and after reading back as demonstrated in the attachment, especially when using fractional numbers...
(This can be called quantization error. Smiley Wink)

Message Edited by GerdW on 08-01-2007 03:43 PM

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(2,920 Views)
Well, yeah, but I would expect the quantitization error to be on the order of 1 part in 2^16 as it is a 16-bit format, and for a large chunk of the demo program I attached it is much larger.

Having twiddled with it for a few more hours, it appears to be related to the scale of the signals that are fed in.  There is no indication in the NI-supplied VIs what the maximum level is for the WAV file writer, and I may just be over driving it (though one would expect that the VI would throw an error if the inputs were invalid).

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
0 Kudos
Message 3 of 8
(2,915 Views)
Hi Joe,

my example shows a quantization error of ~6e-5 (for amplitude=1). This is 1/16384...
The signal ranges from -1 to 1, it is sampled with I16 datatype (which ranges from -32768 to +32767) resulting in an error of 4 quantization steps.
It's about 4 times of what it should be in an ideal case - but NI has hidden the code in the lvsound2.dll...

And one more note: when the amplitude gets bigger than 1 the example will NOT write a wav file... The Sound Write-vi is giving a warning in this case!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 8
(2,906 Views)
Thanks.  Your example uses a signal less than +- 1.00, while mine apparently was greater than +- 1.00.  When I look at the error out of the WAV Write VI, I do see the warning.  However, it is stripped by the WAV Read and hence was not reported later in my code.

FYI, I found that if you go into ...\vi.lib\sound\lvsound.llb

there are "Snd Read Wave File.vi" and "Snd Write Wave File.vi".  It looks like NI update the sound libraries at some point (as there is a ...\vi.lib\sound2, also, which are in the LV8 pallet), but has kept the older ones in vi.lib as well.  These VIs allow you to write the I16 data directly to the file so you can handle your own scaling.  As a bonus, all the subVIs are unlocked so you can see exactly what is going on.

Note that the "Stereo" inputs and outputs of these VIs need their array rotated to conform to "normal" LV array conventions.



Message Edited by Joe Gerhardstein on 08-01-2007 09:32 AM

Message Edited by Joe Gerhardstein on 08-01-2007 09:33 AM

Message Edited by Joe Gerhardstein on 08-01-2007 09:34 AM

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
Message 5 of 8
(2,901 Views)
I had some issues with the sound 2 llb where the old vi worked as expected.
here is the reply from Ni support.

"It took me some time to fully validate and submit this incorrect behavior
      to R&D. In case you are interested, the CAR ID was 49H68RXX

Once again, I hope that using the older VIs or Play sound file.vi is an
      acceptable solution for you."

0 Kudos
Message 6 of 8
(2,869 Views)
What version of LabVIEW did you have problems with the Sound2 library?

Joe Gerhardstein
Viasat
Certified LabVIEW Architect
Certified TestStand Developer
Certified Professional Instructor
http://www.viasat.com
0 Kudos
Message 7 of 8
(2,855 Views)
8.2.0
 
I did not try 8.2.1 yet.
0 Kudos
Message 8 of 8
(2,846 Views)