예제 #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;
        }
예제 #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);
        }
예제 #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();
        }
예제 #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();
     }
 }
예제 #5
0
 public void RemoveSubchunk(RiffChunk subchunk)
 {
     _subchunks.Remove(subchunk);
 }
예제 #6
0
 public void InsertSubchunk(RiffChunk subchunk, int index)
 {
     _subchunks.Insert(index, subchunk);
 }
예제 #7
0
 public void AddSubchunk(RiffChunk subchunk)
 {
     _subchunks.Add(subchunk);
 }
예제 #8
0
 private void UpdateDataChunk(RiffChunk chunk)
 {
     chunk.Data = AudioData;
 }
예제 #9
0
 private void ParseDataChunk(RiffChunk chunk)
 {
     AudioData = chunk.Data;
 }