Decoding a WAV File Header

我的未来我决定 提交于 2019-12-03 16:21:09

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 to apt-get, yum, or brew 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:

52 49 46 46 - RIFF

The next 4 bytes represent the chunk size, which is little endian. In your case it is:

e8 57 14 00 - 1333224

The next 8 bytes represent ASCII characters again. In your case:

57 41 56 45 - WAVE
66 6d 74 20 - fmt.

The next 4 represent the chunk size, which is little endian:

10 00 00 00 - 268435456

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 number of samples ( frames) that exist for each second of data. This field is represented in Hz. - taken from here.

44 ac 00 00 - 44100

The next 4 bytes represent the byte rate(little endian):

10 b1 02 00 - 1049265

The next 2 bytes represent the block align:

This is the number of bytes in a frame (little endian). This is calculated by multiplying the number of channels by the number of bytes (not bits) in a sample. You can find more detailed calculations here

04 00 - 4 

Next are your 2 bytes that represent bits per sample(little endian), in your case it is 16

10 00 - 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 for data like so (big endian):

64 61 74 61 - data

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!