LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add data in the header of a .wav file

Solved!
Go to solution

Hello guys,

i am requesting your help for a little problem that I can't get through during my internship.

Here is what I want to do: I acquire signals that I write to a .wav file. What I would like to do next is to reopen this .wav file and add some data in the header such as the microphone sensitivity for instance. The reason I am doing this is because this is how one of our program works, it can get back the Pressure vs. time signal by using these information. I already have the hexadecimal code I need to add but I haven't been able to figure out if doing such a thing is possible or not after one day of researches so any ideas would be greatly appreciated. I am wondering if Matlab could do the trick but I'd rather stay with the "normal VIs"...

Thank you very much for your help.

0 Kudos
Message 1 of 6
(4,834 Views)

You can find a detailed map of what a WAV file header looks like here.  It is a good overview and contains links to far more information.  Using the LabVIEW binary write functions (file I/O palette), once you find out where to put the data, placing it there should be no problem.  The real issue is finding where to put it without damaging the rest of the file.  Good luck.

0 Kudos
Message 2 of 6
(4,828 Views)

First of all I would like to thank you for your answer. I've already actually studied the wav format (and this page in particular 🙂 ) so I already know exactly what I need to write and where to write it. It's a chuck that contains all the information and my other program already know how to ready it. The problem is that I don't know how to insert it into the wav file. I have tried with "format into file" which seems to be exactly what I need and I have the set the position with "Set file Position" but it overwrites my previous data. What I would need would be something that would insert my chuck into the .wav without erasing what's just after it. Is this possible?

0 Kudos
Message 3 of 6
(4,820 Views)

As far as I know, there is no way to prepend data to a file.

 

What I've done in the past is to write a dummy header to my file before writing the data, then replace the dummy header with the actual header when all of the header information was available.  The trick here is to make sure that your dummy header is the same size as your actual header.

 

Gerd gives another solution here: http://forums.ni.com/t5/LabVIEW/Is-it-possible-to-prepend-text-to-a-text-file/m-p/939631#M421647.  This is likely to be the way you want to go if you're talking about existing files.

 

Hope that helps.

 

0 Kudos
Message 4 of 6
(4,802 Views)
Solution
Accepted by topic author guilhemch

To insert data into the middle of a file, you will need to rewrite the entire file after that point, as Gerd said in the linked post.  I would do the following:

 

  1. Seek to the position you want to put your new chunk
  2. Read 65,000 bytes from that point forward and store it in a local cache (shift registers work well for this, or just a wire at this point).
  3. Write your new chunk, taking note of how long it is
  4. Write your buffered data minus the length of your new chunk
  5. Read another 65,000 bytes and put it in a new buffer
  6. Write the end of the old buffer and part of the new buffer until you get to 65,000 bytes
  7. Repeat 4-6 until you get to the end of the file
  8. Update offsets in the header to correspond to new chunk locations, since you moved things

You can probably do this with two data buffers in a pair of shift registers in a loop.  The 65,000 bytes is chosen for best performance.  You can use other sizes, but your speed may suffer.  Let us know if you run into issues.

0 Kudos
Message 5 of 6
(4,775 Views)

Thank you very much guys this si exactly what I was looking for. I finally got through my problem and I'm very glad, everything works pretty much fine now. Thanks again

0 Kudos
Message 6 of 6
(4,765 Views)