Showing results for 
Search instead for 
Did you mean: 

how to overwrite the header part of a wave file?????

I need to overwirte the header part of a wave file. Any one has ideas or similar experiences?
basically, I want to continousely save wave data from a sound card. At the end of my program, I need to write the data size of the final wave file to the header part of the wave file.
Is there a function to replace the content of a file? Thanks
0 Kudos
Message 1 of 8
I assume that what you want to do is add documentation into the header of the wav file such as the media type, location, equipment used .....
Some one may have written some routines to do this in Labview, unfortunately all the ones I have are written in Visual Basic, quite a long time ago.

Here are some pointers in the event that no one has any Labview stuff, we could even knock a few togther, if its not been done.

The WAV file falls into a cateory of Windows files known as RIFF format files, in fact you will see this written into the file header almost at the very front.

I quote here from the Microsoft Technet Article:-
See here for a nice picture and here for full details, although for the header structure I prefer here.
"The basic building block of a RIFF file is a chunk. A chunk is a logical unit of multimedia data, such as a single frame in a video clip. Each chunk contains the following fields:
  • A four-character code specifying the chunk identifier
  • A doubleword value specifying the size of the data member in the chunk
  • A data field
Don't be put off by the fact that it often says AVI rather than WAV in the examples, the RIFF format is an extensible file format supporting lots of various media types even custom types. It's just that at the moment people are interested in Video.

There are standard fourcc codes that exist to hold various specific types of information and if one of these is not suitable you can create your own, there is (well was) even a way to regiser your own special type with Microsoft!!

There are a couple of ways of doing the job (assuming some kind sole does not donate a VI library).

1) Handle all the file i/o yourself by reading in the file and then insert the appropriate headers and rewrite the file out again.
    Involved, but cross platform.
2) Muck about with Windows 'mmio' librarys (mmioCreateChunk).
    Platform specific but possibly more reliable???

If you select option 1, then what you have to do is read in the appropriate chunk sizes(lengths) contained in the header, insert your appropriate FOURCC code, size(length) and data then adjust the affected 'chunk' size indicators to put all the various size indicators in the correct place, simple ehhh Smiley Wink

If you select option 2, this requires linking to the appropriate DLL, it always my last resort to avoid DLL hell and portability issues.

As an example I wrote my own Turbo Pascal and later Visual Basic handlers which allowed attachment of lots of information from a form, and then created a special media format for the data to allow storing native measured data. These files are still recognised by WAV file readers today such as Media Player 10. Of course the data format is not understood because the encoding type was special, but that's the point.

One final point, there was a tool which read in a WAV file displaying all available headers, with C source (Windows 3.X) supplied in the MSDN toolkit. There are probalby other tools available by now, as a last resort If you decide to have a go I can send you my VB alpha version which reads all standard headers, it might write out a few as well (it was a very long time ago).

Good  luck.

Message Edité par Conseils le 12-10-2005 04:09 PM

Message 2 of 8
Hi Seanxu
Atached is a NI vi modificated to write only a wav file header. This header is a very simple one, so if you need a more elaborate one, will have to follow the Conseil's  post.
To use it:
1. Create file and write header ( just to make room)
2 append  data ( little endian if 16 bits) and keep count of bytes added
3 write again the header using the correct data ( speed, mode, bits and bytes).
 That creates a standard wav file readable for audio editors and so.

If you want to learn the structure of a wav file ( it is as easy as efficient)), I have a FileInforead vi thant reads label,position and size of all chunks in a wav file. Post back and i will post it.


"Qod natura non dat, Salmantica non praestat"
Message 3 of 8
Thanks guys!
I tried your method. but when i write the correct header information, I found the whole file was replaced. That means the data are gone. Only new header information is the new file. Thanks! Could you attach your VIs? Thanks a lot!
0 Kudos
Message 4 of 8


Attached are 3 files: wite header, read wav info and an example that generates a wav file.

See the example to write header, append data and write correct header.


Hope it helps.



"Qod natura non dat, Salmantica non praestat"
Message 5 of 8
thanks, but the Escribe Cabecera Wav.VI is not included in the zip file. Could you atttach it again? Thanks a lot!
0 Kudos
Message 6 of 8

Sorry about that

Escribe cabecera wav is in spanish. I included the vi as Write header wav for better understanding, so rename the vi or open the example and replace de missing vi for write header wav.

The file .wav must be created before using the vi to avoid erros.




"Qod natura non dat, Salmantica non praestat"
0 Kudos
Message 7 of 8

hi Alipio

I use your attached VI to overwrite the stored raw iq data wav file but i use this VI to the size of data samples in file is half 

i read this file it contains half of the data in the file after this vi, what's the issue in his vi.

kindly guide me 

thanks in advance.

0 Kudos
Message 8 of 8