public WaveFile(string fileName) { var stream = File.OpenRead(fileName); RiffHeader = RiffHeader.GetRiffHeader(stream); var pos = stream.Position; FormatChunk = FormatChunk.GetFormatChunk(stream); stream.Position = pos + FormatChunk.Size + 8; DataChunk = DataChunk.GetDataChunk(stream); //if (stream.Length < 12 + 8 + FormatChunk.Size + 8 + DataChunk.Size) throw new InvalidDataException("The Wave file format is invalid.") Data = new short[DataChunk.Size / 2]; byte[] bytes = new byte[DataChunk.Size]; stream.Read(bytes, 0, bytes.Length); stream.Dispose(); for (int i = 0; i < Data.Length; i++) { Data[i] = BitConverter.ToInt16(new byte[2] { bytes[2 * i], bytes[2 * i + 1] }, 0); } }