Ejemplo n.º 1
0
        private RiffSubChunk ParseSubChunk(BinaryReader reader)
        {
            string id = Utils.ReadUTF8String(reader, 4);

            reader.BaseStream.Position -= 4;
            long startOffset = reader.BaseStream.Position + 8;
            Func <RiffParser, BinaryReader, RiffSubChunk> parser;
            RiffSubChunk subChunk = RegisteredSubChunks.TryGetValue(id, out parser) ? parser(this, reader) : new RiffSubChunk(reader);

            long endOffset      = startOffset + subChunk.SubChunkSize;
            int  remainingBytes = (int)Math.Max(endOffset - reader.BaseStream.Position, 0);

            subChunk.Extra = reader.ReadBytes(remainingBytes);

            reader.BaseStream.Position = endOffset + (endOffset & 1); // Subchunks are 2-byte aligned
            return(subChunk);
        }
Ejemplo n.º 2
0
        public void ParseRiff(Stream file)
        {
            using (BinaryReader reader = new BinaryReader(file))
            {
                RiffChunk = RiffChunk.Parse(reader);
                SubChunks.Clear();

                // Size is counted from after the ChunkSize field, not the RiffType field
                long startOffset = reader.BaseStream.Position - 4;
                long endOffset   = startOffset + RiffChunk.Size;

                // Make sure 8 bytes are available for the subchunk header
                while (reader.BaseStream.Position + 8 < endOffset)
                {
                    RiffSubChunk subChunk = ParseSubChunk(reader);
                    SubChunks[subChunk.SubChunkId] = subChunk;
                }
            }
        }