Skip to content

Instantly share code, notes, and snippets.

@fumiya-kume
Created June 26, 2019 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumiya-kume/4efa59190168bcadc4add59f25eb2135 to your computer and use it in GitHub Desktop.
Save fumiya-kume/4efa59190168bcadc4add59f25eb2135 to your computer and use it in GitHub Desktop.
public class WavAnalyzer
{
public string riffId;
public uint fileSize;
public string wavId;
public string formatId;
// フォーマットのチャンク数
public uint formatChunkSize;
public ushort format;
// チャネル数
public ushort channnelsCount;
public uint samplingRate;
public uint bytePerSec;
// データのブロックサイズ
public ushort blockSize;
// 量子化ビット数
public uint bit;
public string dataId;
public uint dataSize;
public List<List<short>> data;
public WavAnalyzer(string fileName)
{
using (FileStream fileReader = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
using (BinaryReader binaryReader = new BinaryReader(fileReader))
{
riffId = Encoding.UTF8.GetString(binaryReader.ReadBytes(4));
fileSize = binaryReader.ReadUInt32();
wavId = Encoding.UTF8.GetString(binaryReader.ReadBytes(4));
formatId = Encoding.UTF8.GetString(binaryReader.ReadBytes(4));
formatChunkSize = binaryReader.ReadUInt32();
format = binaryReader.ReadUInt16();
channnelsCount = binaryReader.ReadUInt16();
samplingRate = binaryReader.ReadUInt32();
bytePerSec = binaryReader.ReadUInt32();
blockSize = binaryReader.ReadUInt16();
bit = binaryReader.ReadUInt32();
dataId = Encoding.UTF8.GetString(binaryReader.ReadBytes(4));
dataSize = binaryReader.ReadUInt32();
data = new List<List<short>>();
for (int i = 0; i < channnelsCount; i++)
{
data.Add(new List<short>());
}
for (int i = 1; i < dataSize / blockSize; i++)
{
// チャンネルの数だけデータを入れてく
for (int j = 0; j < channnelsCount; j++)
{
data.ElementAt(j).Add((short)binaryReader.ReadUInt16());
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment