public static WaveFact Parse(BinaryReader reader) { var fact = new WaveFact(); fact.SubChunkID = reader.ReadFourCc(); if (fact.SubChunkID != "fact") { throw new InvalidDataException("Invalid or missing .wav file fact chunk!"); } fact.SubChunkSize = reader.ReadUInt32(); if (fact.SubChunkSize != 4) { throw new NotSupportedException("Invalid or unknown .wav compression format!"); } fact.NumSamples = reader.ReadUInt32(); return(fact); }
public WaveDecoder(Stream s) { using (BinaryReader br = new BinaryReader(s)) { _header = RiffHeader.Parse(br); _format = WaveFormat.Parse(br); if (_format.AudioFormat != WaveFormatType.Pcm) { _fact = WaveFact.Parse(br); } _data = WaveData.Parse(br); var variant = WavParser.GetParser(_format.AudioFormat); _decodedData = variant.Parse(br, (int)_data.SubChunkSize, _format); _audioFormat.BitsPerSample = variant.BitsPerSample; _audioFormat.Channels = _format.NumChannels; _audioFormat.SampleRate = (int)_format.SampleRate; _numSamples = _samplesLeft = _decodedData.Length / _audioFormat.BytesPerSample; } }