// Private functions for packing files // Reads the beginning of each file and verifies it is formatted as a WAVE file. Locates // the WaveFormatEx structure and start of data. The WaveFormat is stored in the waveFormats container. // The current stream position is set to the start of the data chunk. // Note: This function assumes that all stream positions are initially set to the beginning // of the file. When reading the wave file header, it does not seek to the file start. private static void ReadAllWaveHeaders(List <FileStream> filesToPackReaders, List <WaveFormatEx> waveFormats, List <IndexEntry> indexEntries) { RiffHeader header; // Read in all the headers and find start of data for (int i = 0; i < filesToPackReaders.Count; ++i) { using (BinaryReader reader = new BinaryReader(filesToPackReaders[i], System.Text.Encoding.ASCII, true)) { // Read the file header filesToPackReaders[i].Seek(0, SeekOrigin.Begin); header = new RiffHeader(reader); if (header.riffTag != CommonTags.tagRIFF || header.waveTag != CommonTags.tagWAVE) { throw new System.Exception("Error reading header from file " + filesToPackReaders[i].Name); } // Check that the file size makes sense (matches with header chunk length + 8) if (header.chunkSize + 8 != filesToPackReaders[i].Length) { throw new System.Exception("Chunk size does not match file length in " + filesToPackReaders[i].Name); } // Find the format tag FindChunk(CommonTags.tagFMT_, reader); // Read in the wave format WaveFormatEx waveFormat = new WaveFormatEx(reader); waveFormat.cbSize = 0; waveFormats.Add(waveFormat); // Find the start of the data and record length IndexEntry entry = new IndexEntry(); entry.dataLength = (int)FindChunk(CommonTags.tagDATA, reader); indexEntries.Add(entry); // Note: Current stream position is set to the start of the wave data } } }
public WaveHeader(BinaryReader reader) { riffHeader = new RiffHeader(reader); formatChunk = new FormatChunk(reader); dataChunk = new ChunkHeader(reader); }