Example #1
0
 private void Flush()
 {
     subchunks.Clear();
     foreach (KeyValuePair <string, string> kvp in dictionary)
     {
         RiffSubchunk rs = new RiffSubchunk();
         rs.tag  = kvp.Key;
         rs.data = System.Text.Encoding.ASCII.GetBytes(kvp.Value);
         subchunks.Add(rs);
     }
 }
Example #2
0
            public RiffSubchunk_fmt(RiffSubchunk origin)
            {
                tag = "fmt ";
                BinaryReader br = new BinaryReader(new MemoryStream(origin.ReadAll()));

                format_tag     = (FORMAT_TAG)br.ReadUInt16();
                channels       = br.ReadUInt16();
                samplesPerSec  = br.ReadUInt32();
                avgBytesPerSec = br.ReadUInt32();
                blockAlign     = br.ReadUInt16();
                bitsPerSample  = br.ReadUInt16();
            }
Example #3
0
 public RiffContainer_INFO(RiffContainer rc)
 {
     subchunks = rc.subchunks;
     type      = "INFO";
     foreach (RiffChunk chunk in subchunks)
     {
         RiffSubchunk rsc = chunk as RiffSubchunk;
         if (chunk == null)
         {
             throw new FormatException("Invalid subchunk of INFO list");
         }
         dictionary[rsc.tag] = System.Text.Encoding.ASCII.GetString(rsc.ReadAll());
     }
 }
Example #4
0
 /// <exception cref="FormatException"><paramref name="rc"/>.<see cref="RiffContainer.subchunks"/> contains a chunk that does not inherit <see cref="RiffSubchunk"/></exception>
 public RiffContainer_INFO(RiffContainer rc)
 {
     subchunks = rc.subchunks;
     type      = "INFO";
     foreach (RiffChunk chunk in subchunks)
     {
         RiffSubchunk rsc = chunk as RiffSubchunk;
         if (chunk == null)
         {
             throw new FormatException("Invalid subchunk of INFO list");                                    //TODO is this supposed to be a check on `rsc` (i.e. as a type check)? --yoshi
         }
         dictionary[rsc.tag] = System.Text.Encoding.ASCII.GetString(rsc.ReadAll());
     }
 }
Example #5
0
 private void Flush()
 {
     subchunks.Clear();
     foreach (KeyValuePair <string, string> kvp in dictionary)
     {
         RiffSubchunk rs = new RiffSubchunk
         {
             tag      = kvp.Key,
             Source   = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(kvp.Value)),
             Position = 0
         };
         rs.Length = (uint)rs.Source.Length;
         subchunks.Add(rs);
     }
 }
Example #6
0
 private void Flush()
 {
     subchunks.Clear();
     foreach (var(subchunkTag, s) in dictionary)
     {
         RiffSubchunk rs = new RiffSubchunk
         {
             tag      = subchunkTag,
             Source   = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(s)),
             Position = 0
         };
         rs.Length = (uint)rs.Source.Length;
         subchunks.Add(rs);
     }
 }
Example #7
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 #8
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 #9
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 #10
0
			private void Flush()
			{
				subchunks.Clear();
				foreach (KeyValuePair<string, string> kvp in dictionary)
				{
					RiffSubchunk rs = new RiffSubchunk
						{
							tag = kvp.Key,
							Source = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(kvp.Value)),
							Position = 0
						};
					rs.Length = (uint)rs.Source.Length;
					subchunks.Add(rs);
				}
			}
Example #11
0
			public RiffSubchunk_fmt(RiffSubchunk origin)
			{
				tag = "fmt ";
				BinaryReader br = new BinaryReader(new MemoryStream(origin.ReadAll()));
				format_tag = (FORMAT_TAG)br.ReadUInt16();
				channels = br.ReadUInt16();
				samplesPerSec = br.ReadUInt32();
				avgBytesPerSec = br.ReadUInt32();
				blockAlign = br.ReadUInt16();
				bitsPerSample = br.ReadUInt16();
			}