public RIFFFormatChunk ReadFormatChunk() { fFormat = new RIFFFormatChunk(); fFormat.chunkID = FOURCC.fmt; fFormat.dwChunkSize = fReader.ReadUInt32(); fFormat.wFormatTag = fReader.ReadUInt16(); fFormat.wChannels = fReader.ReadUInt16(); fFormat.dwSamplesPerSec = fReader.ReadUInt32(); fFormat.dwAvgBytesPerSec = fReader.ReadUInt32(); fFormat.wBlockAlign = fReader.ReadUInt16(); // If the wFormatTag indicates WAVE_FORMAT_PCM // Then the following bitsPerSample is read in as 16 bits if ((ushort)WAVEFORMAT.WAVE_FORMAT_PCM == fFormat.wFormatTag) fFormat.dwBitsPerSample = fReader.ReadUInt16(); return fFormat; }
public WaveFile(string filename) { fFileName = filename; RIFFStreamReader fReader = new RIFFStreamReader(filename); fBinaryReader = fReader.BinaryReader; fHeader = fReader.ReadHeader(); // Read the chunks from the file uint chunkName = 0; while (fReader.Position < (long) fHeader.dwFileLength) { chunkName = fReader.ReadFourCC(); switch (chunkName) { case FOURCC.fmt: fFormat = fReader.ReadFormatChunk(); if (fReader.Position + fFormat.dwChunkSize == fHeader.dwFileLength) return; break; case FOURCC.fact: fFact = fReader.ReadFactChunk(); if (fReader.Position + fFact.dwChunkSize == fHeader.dwFileLength) return; break; case FOURCC.data: fData = fReader.ReadDataChunk(); if (fReader.Position + fData.dwChunkSize == fHeader.dwFileLength) return; break; default: // Skip over unsupported chunks. fReader.AdvanceToNext(); break; } } }
public RIFFStreamReader(Stream inStream) { fFact = null; fFormat = null; fReader = new BinaryReader(inStream); }