Example #1
0
        private RiffChunk ReadChunk(BinaryReader br)
        {
            RiffChunk ret;
            string    tag  = ReadTag(br); readCounter += 4;
            uint      size = br.ReadUInt32(); readCounter += 4;

            if (size > int.MaxValue)
            {
                throw new FormatException("chunk too big");
            }
            if (tag == "RIFF" || tag == "LIST")
            {
                RiffContainer rc = new RiffContainer
                {
                    tag  = tag,
                    type = ReadTag(br)
                };

                readCounter += 4;
                long readEnd = readCounter - 4 + size;
                while (readEnd > readCounter)
                {
                    rc.subchunks.Add(ReadChunk(br));
                }
                ret = rc.Morph();
            }
            else
            {
                RiffSubchunk rsc = new RiffSubchunk
                {
                    tag      = tag,
                    Source   = br.BaseStream,
                    Position = br.BaseStream.Position,
                    Length   = size
                };
                readCounter            += size;
                br.BaseStream.Position += size;
                ret = rsc.Morph();
            }
            if (size % 2 != 0)
            {
                br.ReadByte();
                readCounter += 1;
            }
            return(ret);
        }
Example #2
0
    private RiffChunk ReadChunk(BinaryReader br)
    {
        RiffChunk ret;
        string    tag  = ReadTag(br); readCounter += 4;
        uint      size = br.ReadUInt32(); readCounter += 4;

        if (size > int.MaxValue)
        {
            throw new FormatException("chunk too big");
        }
        if (tag == "RIFF" || tag == "LIST")
        {
            RiffContainer rc = new RiffContainer();
            rc.tag  = tag;
            rc.type = ReadTag(br); readCounter += 4;
            long readEnd = readCounter - 4 + size;
            while (readEnd > readCounter)
            {
                rc.subchunks.Add(ReadChunk(br));
            }
            ret = rc.Morph();
        }
        else
        {
            RiffSubchunk rsc = new RiffSubchunk();
            rsc.tag  = tag;
            rsc.data = br.ReadBytes((int)size); readCounter += size;
            ret      = rsc.Morph();
        }
        if (size % 2 != 0)
        {
            br.ReadByte();
            readCounter += 1;
        }
        return(ret);
    }
Example #3
0
		private RiffChunk ReadChunk(BinaryReader br)
		 {
			RiffChunk ret;
			string tag = ReadTag(br); readCounter += 4;
			uint size = br.ReadUInt32(); readCounter += 4;
			if (size > int.MaxValue)
				throw new FormatException("chunk too big");
			if (tag == "RIFF" || tag == "LIST")
			{
				RiffContainer rc = new RiffContainer
					{
						tag = tag,
						type = ReadTag(br)
					};

				readCounter += 4;
				long readEnd = readCounter - 4 + size;
				while (readEnd > readCounter)
					rc.subchunks.Add(ReadChunk(br));
				ret = rc.Morph();
			}
			else
			{
				RiffSubchunk rsc = new RiffSubchunk
					{
						tag = tag,
						Source = br.BaseStream,
						Position = br.BaseStream.Position,
						Length = size
					};
				readCounter += size;
				br.BaseStream.Position += size;
				ret = rsc.Morph();
			}
			if (size % 2 != 0)
			{
				br.ReadByte();
				readCounter += 1;
			}
			return ret;

		}