File: WavHeader.txt

package info (click to toggle)
wavtools 1.3.2-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 196 kB
  • ctags: 92
  • sloc: ansic: 416; makefile: 103; tcl: 72; sh: 20
file content (56 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
I had one hell of a time finding a clear document on how to write the header
of a basic PCM wav file.  This is what i've found out mostly by reading docs
and a little by exploratory surgery.  If ever you find any of this to be 
incorrect, please let me know via email at tannoy@wep.net.


Basic structure of a simple PCM wav header.
struct{
	char	RiffTag[4]; 	// 'RIFF'
	int32_t	FileLength;
	char	FormatTag[8];	// 'WAVEfmt '
	int32_t	FormatLength;	// 16
	int16_t	DataFormat;
	int16_t	NumChannels;
	int32_t	SampleRate;
	int32_t	BytesPerSecond;
	int16_t	BlockAlignment;
	int16_t	SampleDepth;
	char	DataTag[3];	// 'data'
	int32_t	DataLength;
} WavHeader;

FileLength:
	The length of the rest of the file from this point;  It comes out to
	being DataLength(bytes) + 32(rest of header).
	
DataFormat:
	The format of the sample data; PCM audio is registered as 1 for this
	paramater. You can pretty much just take it as granted unless you
	are using weirdo sampleing.
	
NumChannels:
	1 or 2; Obviously mono or stereo.  There can be more than 2
	channels, but i cant see where that would be applied.

SampleRate:
	Number of samples per second;
	
BytesPerSecond:
	Number of bytes processed in one second; This is usefull for
	buffersize estimation.
		SampleRate * (SampleDepth / 8) * NumChannels;
	
BlockAlignment:
	Number of bytes that must be read (or multiple of this) to correctly
	write the sample data to the device.
		(SampleDepth / 8) * NumChannels;
		
SampleDepth:
	Number of bits per sample; Generally will be 8 or 16.
	
DataLength:
	The length of the sampledata in bytes.
		RecordTime(seconds) * (SampleDepth / 8) *
		SampleRate * NumChannels