private void ReadFormatBlock()
{
try {
Debug.Assert(Chunk.FCC == FourCC.WavFmt, "This is not a WavFmt chunk");
Debug.Assert(this.waveFormat == null, "The waveformat structure should have been set before");
// Some .wav files do not include the cbSize field of the WAVEFORMATEX
// structure. For uncompressed PCM audio, field is always zero.
uint formatSize = 0;
if (Chunk.Size < MinFormatSize) {
throw new InvalidOperationException("File is not a WAV file");
}
// Allocate a buffer for the WAVEFORMAT structure.
formatSize = Chunk.Size;
this.waveFormat = new WaveFormatEx();
// Read the format from the current chunk in the file
byte[] data = ReadDataFromChunk(formatSize);
// Copy the read data into our WAVFORMATEX
this.waveFormat.SetFromByteArray(data);
}
catch (Exception) {
this.waveFormat = null;
throw;
}
}