public void Parse(BinaryReader reader) { _header = RiffHeader.Parse(reader); _format = WaveFormat.Parse(reader); // Every format except the original PCM format must have a fact chunk if ((AudioFormatType)_format.AudioFormat != AudioFormatType.Pcm) { _fact = WaveFact.Parse(reader); } _data = WaveData.Parse(reader); _buffer = WavParser .GetParser((AudioFormatType)_format.AudioFormat) .Parse(reader, (int)_data.SubChunkSize, _format); }
public void Parse(BinaryReader reader) { _header = RiffHeader.Parse(reader); if (new string(_header.ChunkId) != "RIFF" || new string(_header.Format) != "WAVE") { throw new InvalidDataException("Invalid .wav file!"); } _format = WaveFormat.Parse(reader); if (new string(_format.SubChunkID) != "fmt ") { throw new InvalidDataException("Invalid .wav file!"); } if (_format.AudioFormat != 1) { throw new NotSupportedException("Invalid .wav compression!"); } //probably a compressed format if (_format.SubChunkSize > 16) { reader.BaseStream.Seek(_format.SubChunkSize - 16, SeekOrigin.Current); } _data = WaveData.Parse(reader); if (new string(_data.SubChunkID) != "data") { throw new InvalidDataException("Invalid .wav file!"); } _buffer = reader.ReadBytes((int)_data.SubChunkSize); }