34 lines
807 B
C#
34 lines
807 B
C#
using System.IO;
|
|
|
|
namespace MoonWorks.Audio
|
|
{
|
|
public static class AudioUtils
|
|
{
|
|
public static Format ReadWaveFormat(string filePath, out int dataLength)
|
|
{
|
|
var fileInfo = new FileInfo(filePath);
|
|
using FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
|
using BinaryReader br = new BinaryReader(fs);
|
|
|
|
fs.Position = 20;
|
|
var formatTag = br.ReadInt16();
|
|
fs.Position = 22;
|
|
var channels = br.ReadInt16();
|
|
fs.Position = 24;
|
|
var sampleRate = br.ReadInt32();
|
|
fs.Position = 34;
|
|
var bitsPerSample = br.ReadInt16();
|
|
fs.Position = 40;
|
|
dataLength = br.ReadInt32();
|
|
|
|
return new Format
|
|
{
|
|
Tag = (FormatTag) formatTag,
|
|
Channels = (ushort) channels,
|
|
SampleRate = (uint) sampleRate,
|
|
BitsPerSample = (ushort) bitsPerSample
|
|
};
|
|
}
|
|
}
|
|
}
|