public void ParseWaveHeader()
{
bool foundData = false;
try {
while (!foundData) {
// Go through each chunk and look for the WavFmt which
// contains the format information
if (Chunk.FCC == FourCC.WavFmt) {
this.ReadFormatBlock();
}
else if (Chunk.FCC == FourCC.WavData || Chunk.FCC == FourCC.Wavdata) {
// Found the Wave data.
foundData = true;
break;
}
MoveToNextChunk();
}
}
catch (Exception e) {
if (this.waveFormat == null || !foundData) {
throw new InvalidOperationException("Invalid file format", e);
}
}
// Now that we have a chunk with the data from the file,
// calculate the duration of the file based on the size
// of the buffer.
this.duration = this.waveFormat.AudioDurationFromBufferSize(Chunk.Size);
}