forked from hughpyle/inguz-DSPUtil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaveChunk.cs
77 lines (69 loc) · 1.94 KB
/
WaveChunk.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DSPUtil
{
public class WaveChunkFactory
{
public static WaveChunk ReadChunk(BinaryReader rdr, bool bigEndian)
{
WaveChunk chunk = null;
string id = new string(rdr.ReadChars(4));
if (id.Length > 0)
{
int chunkSize = rdr.ReadInt32();
if (bigEndian)
chunkSize = System.Net.IPAddress.NetworkToHostOrder(chunkSize);
switch (id)
{
case "fmt ":
chunk = new WaveFmtChunk(chunkSize);
break;
default:
chunk = new WaveChunk(id, chunkSize);
break;
}
}
return chunk;
}
}
/// <summary>
/// An undifferentiated Wave chunk
/// </summary>
public class WaveChunk
{
protected string _id = "";
protected int _chunkSize = 0;
protected int _structSize = 0;
protected int _dataSize;
public WaveChunk(string id, int chunkSize)
{
_id = id;
_chunkSize = chunkSize;
}
public string ID { get { return _id; } }
public virtual int DataSize { get { return _dataSize; } set { _dataSize = value; } }
public int TotalSize { get { return _dataSize + _structSize; } }
public virtual void Skip(BinaryReader rdr)
{
rdr.ReadBytes(_chunkSize);
}
public virtual void Write(BinaryWriter w)
{
}
}
class WaveFmtChunk : WaveChunk
{
public WaveFmtChunk(int chunkSize) : base("fmt ", chunkSize)
{
}
public override int DataSize
{
set
{
throw new InvalidOperationException();
}
}
}
}