I'm trying to understand the header of a WAV file. I've opened an example file and got this:
5249 4646 e857 1400 5741 5645 666d 7420
1000 0000 0100 0200 44ac 0000 10b1 0200
0400 1000
I've been reading this data representation tutorial.
I understand that 52
is one byte and represents the ASCII letter R
. I understand up to the 1000 0000
. Why does that represent decimal 16? The tutorial says that the value at that position is always 0x10
. How does 1000 0000
equate to 0x10
.
Also, when reading the file, will a program know whether to expect a number or ASCII? Presumably it'll check against a value that is already in HEX?
Thanks
Hope this helps a little, I'm going to mention everything just to clear:
Something to use for hex in general: I use a hex editor,
dhex
, which you should be able toapt-get
,yum
, orbrew
install on your favorite unix like machine. I'll be using this site as the source for most of this material:As you alluded to, the first 4 bytes of hex represent ASCII characters. In this case, those characters area always:
The next 4 bytes represent the chunk size, which is little endian. In your case it is:
The next 8 bytes represent ASCII characters again. In your case:
The next 4 represent the chunk size, which is little endian:
This chuck does not represent decimal 16, it represents decimal 268435456 in 16bits (4 bytes with 1 bytes being 4 bits). for reasons as to "why" the chunks are 16bits, you can read more of on this Intro to Audio Programing. This describes that the chunks in the data section will be 16bit.
01 00
represents the audio format (little endian), 1 stands for PCI in this case.02 00
represents the number of channels, which is 2 in your case.The next 4 bytes represent the sample rate (little endian), or
The next 4 bytes represent the byte rate(little endian):
The next 2 bytes represent the block align:
Next are your 2 bytes that represent bits per sample(little endian), in your case it is 16
The Data Section:
You do not currently have a data section in your
.wav
file, in order to start the data section you first write the ASCII values fordata
like so (big endian):After this you need 4 bytes representing your chunk 2 size and you should be good to go. In terms of testing, I would recommend reading this guide if you have not already. I would also recommenced reading this post about how to build raw wav files Digital Audio - Creating a WAV (RIFF) file , this should also help in understanding how to "decode" them.