forked from soiaf/C-Sharp-WavPack-Decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaveHeader.cs
56 lines (46 loc) · 1.17 KB
/
WaveHeader.cs
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
/*
** WaveHeader.cs
**
** Copyright (c) 2010-2016 Peter McQuillan
**
** All Rights Reserved.
**
** Distributed under the BSD Software License (see license.txt)
***/
namespace WavPack.Decoder
{
class WaveHeader
{
internal const uint Size = 16;
internal ushort FormatTag, NumChannels;
internal uint SampleRate, BytesPerSecond;
internal ushort BlockAlign, BitsPerSample;
internal byte[] AsBytes()
{
byte[] bytes = new byte[Size];
// swap endians
bytes[1] = (byte)(FormatTag >> 8);
bytes[0] = (byte)FormatTag;
// swap endians
bytes[3] = (byte)(NumChannels >> 8);
bytes[2] = (byte)NumChannels;
// swap endians
bytes[7] = (byte)(SampleRate >> 24);
bytes[6] = (byte)(SampleRate >> 16);
bytes[5] = (byte)(SampleRate >> 8);
bytes[4] = (byte)SampleRate;
// swap endians
bytes[11] = (byte)(BytesPerSecond >> 24);
bytes[10] = (byte)(BytesPerSecond >> 16);
bytes[9] = (byte)(BytesPerSecond >> 8);
bytes[8] = (byte)BytesPerSecond;
// swap endians
bytes[13] = (byte)(BlockAlign >> 8);
bytes[12] = (byte)BlockAlign;
// swap endians
bytes[15] = (byte)(BitsPerSample >> 8);
bytes[14] = (byte)BitsPerSample;
return bytes;
}
}
}