Ejemplo n.º 1
0
        private void ParseSubchunks(Stream input, RiffChunk chunk, long size)
        {
            var num = input.Position + size;

            while (num - input.Position > 8L)
            {
                RiffChunk chunk1;
                ParseChunk(input, out chunk1);
                chunk.AddSubchunk(chunk1);
            }
            input.Position = num;
        }
Ejemplo n.º 2
0
        private static void WriteChunk(RiffChunk chunk, Stream stream)
        {
            var binaryWriter = new BinaryWriter(stream);

            binaryWriter.Write(Encoding.ASCII.GetBytes(chunk.Id));
            binaryWriter.Write((uint)chunk.Size);
            binaryWriter.Write(chunk.Data);
            foreach (var chunk1 in chunk.Subchunks)
            {
                WriteChunk(chunk1, stream);
            }
            if (chunk.Size % 2L == 0L)
            {
                return;
            }
            binaryWriter.Write((byte)0);
        }
Ejemplo n.º 3
0
        private void ParseFormatChunk(RiffChunk chunk)
        {
            var binaryReader = new BinaryReader(new MemoryStream(chunk.Data));

            FormatTag      = binaryReader.ReadUInt16();
            Channels       = binaryReader.ReadUInt16();
            SamplesPerSec  = binaryReader.ReadUInt32();
            AvgBytesPerSec = binaryReader.ReadUInt32();
            BlockAlign     = binaryReader.ReadUInt16();
            if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position > 0L)
            {
                BitsPerSample = binaryReader.ReadUInt16();
            }
            if (binaryReader.BaseStream.Length - binaryReader.BaseStream.Position > 0L)
            {
                int count = binaryReader.ReadUInt16();
                FormatExtension = binaryReader.ReadBytes(count);
            }
            binaryReader.Close();
        }
Ejemplo n.º 4
0
 private void UpdateFormatChunk(RiffChunk chunk)
 {
     using (var memoryStream = new MemoryStream(22))
     {
         var binaryWriter = new BinaryWriter(memoryStream);
         binaryWriter.Write(FormatTag);
         binaryWriter.Write(Channels);
         binaryWriter.Write(SamplesPerSec);
         binaryWriter.Write(AvgBytesPerSec);
         binaryWriter.Write(BlockAlign);
         binaryWriter.Write(BitsPerSample);
         if (FormatExtension != null)
         {
             binaryWriter.Write((ushort)FormatExtension.Length);
             binaryWriter.Write(FormatExtension);
         }
         else
         {
             binaryWriter.Write((ushort)0);
         }
         chunk.Data = memoryStream.ToArray();
     }
 }
Ejemplo n.º 5
0
 public void RemoveSubchunk(RiffChunk subchunk)
 {
     _subchunks.Remove(subchunk);
 }
Ejemplo n.º 6
0
 public void InsertSubchunk(RiffChunk subchunk, int index)
 {
     _subchunks.Insert(index, subchunk);
 }
Ejemplo n.º 7
0
 public void AddSubchunk(RiffChunk subchunk)
 {
     _subchunks.Add(subchunk);
 }
Ejemplo n.º 8
0
 private void UpdateDataChunk(RiffChunk chunk)
 {
     chunk.Data = AudioData;
 }
Ejemplo n.º 9
0
 private void ParseDataChunk(RiffChunk chunk)
 {
     AudioData = chunk.Data;
 }