Write a wav header, in C and python

I had this raw audio stream in a file, with no header, just the encoded data, but I knew the data properties from somewhere else than the file; in order to make any media player to recognize and play the audio data I decided to rebuild a WAV header for it, that worked fine, even for a compressed audio format.

The WAVE format is quite simple if you restrict yourself to a subset of its functionalities, all I needed was a RIFF chunk, a Format chunk and a Data chunk; for the Format chunk I had to use the WAVEFORMATEX Structure because the data I had was in a compressed format and some extra data was needed to be passed to the audio decoder; this kind of data is called Private Codec Data in some context, and AFAIU in the case of WMA codecs it specifies parameters for a descrambling mechanism used for error concealment (see the Stream-specific data for audio stream part in this ASF doc from avifile.sf.net).

You can find C and python snippets for writing a WAV header in the wav_header git repository; those are there mainly for illustration purposes, but you can do whatever you want with them.

CommentsSyndicate content

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the code without spaces.