Csound Csound-dev Csound-tekno Search About

wav file format (header files)

Date2016-04-08 21:36
FromPeter Burgess
Subjectwav file format (header files)
Hi there, I have been messing around today making some code that
generates wav files in binary format. Let's not worry about why on
earth I'd want to do that while I have csound at my fingertips, but
you know, sometimes things come up!

Anyways, I thought I'd nailed the format of the header, but my .wav
files I'm exporting don't show any properties, let along play. Anyone
here know much about the wav headers?

So far I have taken the notes attached, and I have been referencing
the following website:

http://www.topherlee.com/software/pcm-tut-wavformat.html

it's taken a while to translate what each bit of the header means, and
there's a few areas I'm still not totally sure of:

bytes 37-41 = "data" chunk header. Marks the beginning of the data section.

what does this do? Is it nessacary to mark the beggining of the data
section, when the header is a particular size already? Also, some of
the files I've examined have had this section blank, whle others have
had:

  0x 6461 7461

then there is the length of format data

bytes 17-20 = Length of format data as listed above

My guess is that this specifies how long the formatting before it
lasts, but it seems strange to have this come after the data? Needless
to say, most of my wav files have this set to 16, so I'm guessing that
means 16 bytes of format data.... but then one of them has it set to
20, which is more format data than can fit before it....  this makes
no sense to me

I would be delighted if anyone has any insight into this :D

Pete

Date2016-04-08 22:22
FromRichard
SubjectRe: wav file format (header files)
WAVE is a container format, supporting a very wide range of sample 
formats. It is a "chunked" format, in which each chunk has a 
four-character name followed by a four-byte size field. It is a mistake 
to think of it as having a fixed size header. The document you reference 
only describes the most basic form possible, and is out of date in many 
ways. In particular, while it is mandated that the "data" chunk must 
come after the "fmt " chunk, other (arbitrary) chunks can precede it. 
The fmt chunk itself can have many different sizes.

The original reference for handling the WAVE format is Microsoft's own 
document, which as it happens I have a local copy of here:

http://people.bath.ac.uk/masrwd/riffmcidoc.zip

This does not cover more recent extensions such as WAVEFORMATEXTENSIBLE, 
which is the format one must expect these days:

https://msdn.microsoft.com/en-us/library/windows/hardware/dn653308%28v=vs.85%29.aspx

I have a chapter in the Audio Programming Book which discusses file 
formats, and presents a small C library "portsf" for reading and writing 
PCM wav files. The industrial-strength library of course is libsndfile.

Richard Dobson



On 08/04/2016 21:36, Peter Burgess wrote:
> Hi there, I have been messing around today making some code that
> generates wav files in binary format. Let's not worry about why on
> earth I'd want to do that while I have csound at my fingertips, but
> you know, sometimes things come up!
>
> Anyways, I thought I'd nailed the format of the header, but my .wav
> files I'm exporting don't show any properties, let along play. Anyone
> here know much about the wav headers?
>
> So far I have taken the notes attached, and I have been referencing
> the following website:
>
> http://www.topherlee.com/software/pcm-tut-wavformat.html
>
> it's taken a while to translate what each bit of the header means, and
> there's a few areas I'm still not totally sure of:
>
> bytes 37-41 = "data" chunk header. Marks the beginning of the data section.
>
> what does this do? Is it nessacary to mark the beggining of the data
> section, when the header is a particular size already? Also, some of
> the files I've examined have had this section blank, whle others have
> had:
>
>    0x 6461 7461
>
> then there is the length of format data
>
> bytes 17-20 = Length of format data as listed above
>
> My guess is that this specifies how long the formatting before it
> lasts, but it seems strange to have this come after the data? Needless
> to say, most of my wav files have this set to 16, so I'm guessing that
> means 16 bytes of format data.... but then one of them has it set to
> 20, which is more format data than can fit before it....  this makes
> no sense to me
>
> I would be delighted if anyone has any insight into this :D
>
> Pete
>

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-04-08 22:52
FromRory Walsh
SubjectRe: wav file format (header files)
Can you not libsndfile. Why reinvent the wheel? Unless this is a purely academic exercise, in which case, check out the Audio Programming Book ;) 

On 8 April 2016 at 22:22, Richard <richard@rwdobson.com> wrote:
WAVE is a container format, supporting a very wide range of sample formats. It is a "chunked" format, in which each chunk has a four-character name followed by a four-byte size field. It is a mistake to think of it as having a fixed size header. The document you reference only describes the most basic form possible, and is out of date in many ways. In particular, while it is mandated that the "data" chunk must come after the "fmt " chunk, other (arbitrary) chunks can precede it. The fmt chunk itself can have many different sizes.

The original reference for handling the WAVE format is Microsoft's own document, which as it happens I have a local copy of here:

http://people.bath.ac.uk/masrwd/riffmcidoc.zip

This does not cover more recent extensions such as WAVEFORMATEXTENSIBLE, which is the format one must expect these days:

https://msdn.microsoft.com/en-us/library/windows/hardware/dn653308%28v=vs.85%29.aspx

I have a chapter in the Audio Programming Book which discusses file formats, and presents a small C library "portsf" for reading and writing PCM wav files. The industrial-strength library of course is libsndfile.

Richard Dobson




On 08/04/2016 21:36, Peter Burgess wrote:
Hi there, I have been messing around today making some code that
generates wav files in binary format. Let's not worry about why on
earth I'd want to do that while I have csound at my fingertips, but
you know, sometimes things come up!

Anyways, I thought I'd nailed the format of the header, but my .wav
files I'm exporting don't show any properties, let along play. Anyone
here know much about the wav headers?

So far I have taken the notes attached, and I have been referencing
the following website:

http://www.topherlee.com/software/pcm-tut-wavformat.html

it's taken a while to translate what each bit of the header means, and
there's a few areas I'm still not totally sure of:

bytes 37-41 = "data" chunk header. Marks the beginning of the data section.

what does this do? Is it nessacary to mark the beggining of the data
section, when the header is a particular size already? Also, some of
the files I've examined have had this section blank, whle others have
had:

   0x 6461 7461

then there is the length of format data

bytes 17-20 = Length of format data as listed above

My guess is that this specifies how long the formatting before it
lasts, but it seems strange to have this come after the data? Needless
to say, most of my wav files have this set to 16, so I'm guessing that
means 16 bytes of format data.... but then one of them has it set to
20, which is more format data than can fit before it....  this makes
no sense to me

I would be delighted if anyone has any insight into this :D

Pete


Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-04-08 22:56
FromPeter Burgess
SubjectRe: wav file format (header files)
Thanks very much! That's some great resources :D

As for libsndfile.... I hadn't thought about it, lol. I guess I went
in all guns blazing without thinking my plan through. I probably can
use something else to do it for me. All I have to do is have something
write some data that I generate to a wav file. I guess libsndfile will
handle that much easier than me writing my own code will it?

On Fri, Apr 8, 2016 at 10:52 PM, Rory Walsh  wrote:
> Can you not libsndfile. Why reinvent the wheel? Unless this is a purely
> academic exercise, in which case, check out the Audio Programming Book ;)
>
> On 8 April 2016 at 22:22, Richard  wrote:
>>
>> WAVE is a container format, supporting a very wide range of sample
>> formats. It is a "chunked" format, in which each chunk has a four-character
>> name followed by a four-byte size field. It is a mistake to think of it as
>> having a fixed size header. The document you reference only describes the
>> most basic form possible, and is out of date in many ways. In particular,
>> while it is mandated that the "data" chunk must come after the "fmt " chunk,
>> other (arbitrary) chunks can precede it. The fmt chunk itself can have many
>> different sizes.
>>
>> The original reference for handling the WAVE format is Microsoft's own
>> document, which as it happens I have a local copy of here:
>>
>> http://people.bath.ac.uk/masrwd/riffmcidoc.zip
>>
>> This does not cover more recent extensions such as WAVEFORMATEXTENSIBLE,
>> which is the format one must expect these days:
>>
>>
>> https://msdn.microsoft.com/en-us/library/windows/hardware/dn653308%28v=vs.85%29.aspx
>>
>> I have a chapter in the Audio Programming Book which discusses file
>> formats, and presents a small C library "portsf" for reading and writing PCM
>> wav files. The industrial-strength library of course is libsndfile.
>>
>> Richard Dobson
>>
>>
>>
>>
>> On 08/04/2016 21:36, Peter Burgess wrote:
>>>
>>> Hi there, I have been messing around today making some code that
>>> generates wav files in binary format. Let's not worry about why on
>>> earth I'd want to do that while I have csound at my fingertips, but
>>> you know, sometimes things come up!
>>>
>>> Anyways, I thought I'd nailed the format of the header, but my .wav
>>> files I'm exporting don't show any properties, let along play. Anyone
>>> here know much about the wav headers?
>>>
>>> So far I have taken the notes attached, and I have been referencing
>>> the following website:
>>>
>>> http://www.topherlee.com/software/pcm-tut-wavformat.html
>>>
>>> it's taken a while to translate what each bit of the header means, and
>>> there's a few areas I'm still not totally sure of:
>>>
>>> bytes 37-41 = "data" chunk header. Marks the beginning of the data
>>> section.
>>>
>>> what does this do? Is it nessacary to mark the beggining of the data
>>> section, when the header is a particular size already? Also, some of
>>> the files I've examined have had this section blank, whle others have
>>> had:
>>>
>>>    0x 6461 7461
>>>
>>> then there is the length of format data
>>>
>>> bytes 17-20 = Length of format data as listed above
>>>
>>> My guess is that this specifies how long the formatting before it
>>> lasts, but it seems strange to have this come after the data? Needless
>>> to say, most of my wav files have this set to 16, so I'm guessing that
>>> means 16 bytes of format data.... but then one of them has it set to
>>> 20, which is more format data than can fit before it....  this makes
>>> no sense to me
>>>
>>> I would be delighted if anyone has any insight into this :D
>>>
>>> Pete
>>>
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>        https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>
>
> Csound mailing list Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here


Date2016-04-08 23:11
FromRory Walsh
SubjectRe: wav file format (header files)
It sure would be. And if at any stage you wish to write to another format, it has you covered: http://www.mega-nerd.com/libsndfile/#Features 
And it's LGPL so you can use it in commercial software so long as you play ball with the license. 

On 8 April 2016 at 22:56, Peter Burgess <pete.soundtechnician@gmail.com> wrote:
Thanks very much! That's some great resources :D

As for libsndfile.... I hadn't thought about it, lol. I guess I went
in all guns blazing without thinking my plan through. I probably can
use something else to do it for me. All I have to do is have something
write some data that I generate to a wav file. I guess libsndfile will
handle that much easier than me writing my own code will it?

On Fri, Apr 8, 2016 at 10:52 PM, Rory Walsh <rorywalsh@ear.ie> wrote:
> Can you not libsndfile. Why reinvent the wheel? Unless this is a purely
> academic exercise, in which case, check out the Audio Programming Book ;)
>
> On 8 April 2016 at 22:22, Richard <richard@rwdobson.com> wrote:
>>
>> WAVE is a container format, supporting a very wide range of sample
>> formats. It is a "chunked" format, in which each chunk has a four-character
>> name followed by a four-byte size field. It is a mistake to think of it as
>> having a fixed size header. The document you reference only describes the
>> most basic form possible, and is out of date in many ways. In particular,
>> while it is mandated that the "data" chunk must come after the "fmt " chunk,
>> other (arbitrary) chunks can precede it. The fmt chunk itself can have many
>> different sizes.
>>
>> The original reference for handling the WAVE format is Microsoft's own
>> document, which as it happens I have a local copy of here:
>>
>> http://people.bath.ac.uk/masrwd/riffmcidoc.zip
>>
>> This does not cover more recent extensions such as WAVEFORMATEXTENSIBLE,
>> which is the format one must expect these days:
>>
>>
>> https://msdn.microsoft.com/en-us/library/windows/hardware/dn653308%28v=vs.85%29.aspx
>>
>> I have a chapter in the Audio Programming Book which discusses file
>> formats, and presents a small C library "portsf" for reading and writing PCM
>> wav files. The industrial-strength library of course is libsndfile.
>>
>> Richard Dobson
>>
>>
>>
>>
>> On 08/04/2016 21:36, Peter Burgess wrote:
>>>
>>> Hi there, I have been messing around today making some code that
>>> generates wav files in binary format. Let's not worry about why on
>>> earth I'd want to do that while I have csound at my fingertips, but
>>> you know, sometimes things come up!
>>>
>>> Anyways, I thought I'd nailed the format of the header, but my .wav
>>> files I'm exporting don't show any properties, let along play. Anyone
>>> here know much about the wav headers?
>>>
>>> So far I have taken the notes attached, and I have been referencing
>>> the following website:
>>>
>>> http://www.topherlee.com/software/pcm-tut-wavformat.html
>>>
>>> it's taken a while to translate what each bit of the header means, and
>>> there's a few areas I'm still not totally sure of:
>>>
>>> bytes 37-41 = "data" chunk header. Marks the beginning of the data
>>> section.
>>>
>>> what does this do? Is it nessacary to mark the beggining of the data
>>> section, when the header is a particular size already? Also, some of
>>> the files I've examined have had this section blank, whle others have
>>> had:
>>>
>>>    0x 6461 7461
>>>
>>> then there is the length of format data
>>>
>>> bytes 17-20 = Length of format data as listed above
>>>
>>> My guess is that this specifies how long the formatting before it
>>> lasts, but it seems strange to have this come after the data? Needless
>>> to say, most of my wav files have this set to 16, so I'm guessing that
>>> means 16 bytes of format data.... but then one of them has it set to
>>> 20, which is more format data than can fit before it....  this makes
>>> no sense to me
>>>
>>> I would be delighted if anyone has any insight into this :D
>>>
>>> Pete
>>>
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>        https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>
>
> Csound mailing list Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here



--
http://algorythmradio.com
https://soundcloud.com/algorythmradio

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-04-08 23:28
FromPeter Burgess
SubjectRe: wav file format (header files)
bugger! I wish I'd talked to you guys several hours ago :)

On Fri, Apr 8, 2016 at 11:11 PM, Rory Walsh  wrote:
> It sure would be. And if at any stage you wish to write to another format,
> it has you covered: http://www.mega-nerd.com/libsndfile/#Features
> And it's LGPL so you can use it in commercial software so long as you play
> ball with the license.
>
> On 8 April 2016 at 22:56, Peter Burgess 
> wrote:
>>
>> Thanks very much! That's some great resources :D
>>
>> As for libsndfile.... I hadn't thought about it, lol. I guess I went
>> in all guns blazing without thinking my plan through. I probably can
>> use something else to do it for me. All I have to do is have something
>> write some data that I generate to a wav file. I guess libsndfile will
>> handle that much easier than me writing my own code will it?
>>
>> On Fri, Apr 8, 2016 at 10:52 PM, Rory Walsh  wrote:
>> > Can you not libsndfile. Why reinvent the wheel? Unless this is a purely
>> > academic exercise, in which case, check out the Audio Programming Book
>> > ;)
>> >
>> > On 8 April 2016 at 22:22, Richard  wrote:
>> >>
>> >> WAVE is a container format, supporting a very wide range of sample
>> >> formats. It is a "chunked" format, in which each chunk has a
>> >> four-character
>> >> name followed by a four-byte size field. It is a mistake to think of it
>> >> as
>> >> having a fixed size header. The document you reference only describes
>> >> the
>> >> most basic form possible, and is out of date in many ways. In
>> >> particular,
>> >> while it is mandated that the "data" chunk must come after the "fmt "
>> >> chunk,
>> >> other (arbitrary) chunks can precede it. The fmt chunk itself can have
>> >> many
>> >> different sizes.
>> >>
>> >> The original reference for handling the WAVE format is Microsoft's own
>> >> document, which as it happens I have a local copy of here:
>> >>
>> >> http://people.bath.ac.uk/masrwd/riffmcidoc.zip
>> >>
>> >> This does not cover more recent extensions such as
>> >> WAVEFORMATEXTENSIBLE,
>> >> which is the format one must expect these days:
>> >>
>> >>
>> >>
>> >> https://msdn.microsoft.com/en-us/library/windows/hardware/dn653308%28v=vs.85%29.aspx
>> >>
>> >> I have a chapter in the Audio Programming Book which discusses file
>> >> formats, and presents a small C library "portsf" for reading and
>> >> writing PCM
>> >> wav files. The industrial-strength library of course is libsndfile.
>> >>
>> >> Richard Dobson
>> >>
>> >>
>> >>
>> >>
>> >> On 08/04/2016 21:36, Peter Burgess wrote:
>> >>>
>> >>> Hi there, I have been messing around today making some code that
>> >>> generates wav files in binary format. Let's not worry about why on
>> >>> earth I'd want to do that while I have csound at my fingertips, but
>> >>> you know, sometimes things come up!
>> >>>
>> >>> Anyways, I thought I'd nailed the format of the header, but my .wav
>> >>> files I'm exporting don't show any properties, let along play. Anyone
>> >>> here know much about the wav headers?
>> >>>
>> >>> So far I have taken the notes attached, and I have been referencing
>> >>> the following website:
>> >>>
>> >>> http://www.topherlee.com/software/pcm-tut-wavformat.html
>> >>>
>> >>> it's taken a while to translate what each bit of the header means, and
>> >>> there's a few areas I'm still not totally sure of:
>> >>>
>> >>> bytes 37-41 = "data" chunk header. Marks the beginning of the data
>> >>> section.
>> >>>
>> >>> what does this do? Is it nessacary to mark the beggining of the data
>> >>> section, when the header is a particular size already? Also, some of
>> >>> the files I've examined have had this section blank, whle others have
>> >>> had:
>> >>>
>> >>>    0x 6461 7461
>> >>>
>> >>> then there is the length of format data
>> >>>
>> >>> bytes 17-20 = Length of format data as listed above
>> >>>
>> >>> My guess is that this specifies how long the formatting before it
>> >>> lasts, but it seems strange to have this come after the data? Needless
>> >>> to say, most of my wav files have this set to 16, so I'm guessing that
>> >>> means 16 bytes of format data.... but then one of them has it set to
>> >>> 20, which is more format data than can fit before it....  this makes
>> >>> no sense to me
>> >>>
>> >>> I would be delighted if anyone has any insight into this :D
>> >>>
>> >>> Pete
>> >>>
>> >>
>> >> Csound mailing list
>> >> Csound@listserv.heanet.ie
>> >> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> >> Send bugs reports to
>> >>        https://github.com/csound/csound/issues
>> >> Discussions of bugs and features can be posted here
>> >
>> >
>> > Csound mailing list Csound@listserv.heanet.ie
>> > https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> > https://github.com/csound/csound/issues Discussions of bugs and features
>> > can
>> > be posted here
>>
>>
>>
>> --
>> http://algorythmradio.com
>> https://soundcloud.com/algorythmradio
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>>         https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>
>
> Csound mailing list Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here