Serialize() public method

Writes this WaveFormat object to a stream
public Serialize ( BinaryWriter writer ) : void
writer System.IO.BinaryWriter the output stream
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Createa a new BwfWriter
        /// </summary>
        /// <param name="filename">Rarget filename</param>
        /// <param name="format">WaveFormat</param>
        /// <param name="bextChunkInfo">Chunk information</param>
        public BwfWriter(string filename, WaveFormat format, BextChunkInfo bextChunkInfo)
        {
            this.format = format;
            writer      = new BinaryWriter(File.OpenWrite(filename));
            writer.Write(Encoding.UTF8.GetBytes("RIFF")); // will be updated to RF64 if large
            writer.Write(0);                              // placeholder
            writer.Write(Encoding.UTF8.GetBytes("WAVE"));

            writer.Write(Encoding.UTF8.GetBytes("JUNK")); // ds64
            writer.Write(28);                             // ds64 size
            writer.Write(0L);                             // RIFF size
            writer.Write(0L);                             // data size
            writer.Write(0L);                             // sampleCount size
            writer.Write(0);                              // table length
            // TABLE appears here - to store the sizes of other huge chunks other than

            // write the broadcast audio extension
            writer.Write(Encoding.UTF8.GetBytes("bext"));
            var codingHistory = Encoding.ASCII.GetBytes(bextChunkInfo.CodingHistory ?? "");
            var bextLength    = 602 + codingHistory.Length;

            if (bextLength % 2 != 0)
            {
                bextLength++;
            }
            writer.Write(bextLength); // bext size
            var bextStart = writer.BaseStream.Position;

            writer.Write(GetAsBytes(bextChunkInfo.Description, 256));
            writer.Write(GetAsBytes(bextChunkInfo.Originator, 32));
            writer.Write(GetAsBytes(bextChunkInfo.OriginatorReference, 32));
            writer.Write(GetAsBytes(bextChunkInfo.OriginationDate, 10));
            writer.Write(GetAsBytes(bextChunkInfo.OriginationTime, 8));
            writer.Write(bextChunkInfo.TimeReference); // 8 bytes long
            writer.Write(bextChunkInfo.Version);       // 2 bytes long
            writer.Write(GetAsBytes(bextChunkInfo.UniqueMaterialIdentifier, 64));
            writer.Write(bextChunkInfo.Reserved);      // for version 1 this is 190 bytes
            writer.Write(codingHistory);
            if (codingHistory.Length % 2 != 0)
            {
                writer.Write((byte)0);
            }
            Debug.Assert(writer.BaseStream.Position == bextStart + bextLength, "Invalid bext chunk size");

            // write the format chunk
            writer.Write(Encoding.UTF8.GetBytes("fmt "));
            format.Serialize(writer);

            writer.Write(Encoding.UTF8.GetBytes("data"));
            dataChunkSizePosition = writer.BaseStream.Position;
            writer.Write(-1); // will be overwritten unless this is RF64
            // now finally the data chunk
        }
Ejemplo n.º 2
0
 /// <summary>
 /// WaveFileWriter that actually writes to a stream
 /// </summary>
 /// <param name="outStream">Stream to be written to</param>
 /// <param name="format">Wave format to use</param>
 // Token: 0x06000919 RID: 2329 RVA: 0x0001A39C File Offset: 0x0001859C
 public WaveFileWriter(Stream outStream, WaveFormat format)
 {
     this.outStream = outStream;
     this.format    = format;
     this.writer    = new BinaryWriter(outStream, Encoding.UTF8);
     this.writer.Write(Encoding.UTF8.GetBytes("RIFF"));
     this.writer.Write(0);
     this.writer.Write(Encoding.UTF8.GetBytes("WAVE"));
     this.writer.Write(Encoding.UTF8.GetBytes("fmt "));
     format.Serialize(this.writer);
     this.CreateFactChunk();
     this.WriteDataChunkHeader();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// WaveFileWriter that actually writes to a stream
        /// </summary>
        /// <param name="outStream">Stream to be written to</param>
        /// <param name="format">Wave format to use</param>
        public WaveFileWriter(Stream outStream, WaveFormat format)
        {
            this.outStream = outStream;
            this.format    = format;
            writer         = new BinaryWriter(outStream, System.Text.Encoding.UTF8);
            writer.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"));
            writer.Write((int)0); // placeholder
            writer.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"));

            writer.Write(System.Text.Encoding.UTF8.GetBytes("fmt "));
            format.Serialize(writer);

            CreateFactChunk();
            WriteDataChunkHeader();
        }
        /// <summary>
        /// WaveFileWriter that actually writes to a stream
        /// </summary>
        /// <param name="outStream">Stream to be written to</param>
        /// <param name="format">Wave format to use</param>
        public WaveFileWriter(Stream outStream, WaveFormat format)
        {
            this.outStream = outStream;
            this.format = format;
            this.writer = new BinaryWriter(outStream, System.Text.Encoding.UTF8);
            this.writer.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"));
            this.writer.Write((int)0); // placeholder
            this.writer.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"));

            this.writer.Write(System.Text.Encoding.UTF8.GetBytes("fmt "));
            format.Serialize(this.writer);

            CreateFactChunk();
            WriteDataChunkHeader();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// WaveFileWriter that actually writes to a stream
        /// </summary>
        /// <param name="outStream">Stream to be written to</param>
        /// <param name="format">Wave format to use</param>
        public WaveFileWriter(Stream outStream, WaveFormat format)
        {
            this.outStream = outStream;
            BinaryWriter w = new BinaryWriter(outStream, System.Text.Encoding.ASCII);
            w.Write(System.Text.Encoding.ASCII.GetBytes("RIFF"));
            w.Write((int)0); // placeholder
            w.Write(System.Text.Encoding.ASCII.GetBytes("WAVEfmt "));
            this.format = format;

            format.Serialize(w);

            CreateFactChunk(outStream, format, w);

            WriteDataChunkHeader(outStream, w);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new instance of the AudioFormat class
        /// </summary>
        /// <param name="waveFormat">The WaveFormat representing the WAV header.</param>
        internal AudioFormat(WaveFormat waveFormat)
        {
            averageBytesPerSecond = waveFormat.AverageBytesPerSecond;
            bitsPerSample = waveFormat.BitsPerSample;
            blockAlign = waveFormat.BlockAlign;
            channelCount = waveFormat.Channels;
            format = (int)waveFormat.Encoding;
            sampleRate = waveFormat.SampleRate;

            var stream = new MemoryStream();
            using (var writer = new BinaryWriter(stream))
            {
                waveFormat.Serialize(writer);
                nativeWaveFormat = new List<byte>(stream.ToArray());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// WaveFileWriter that actually writes to a stream
        /// </summary>
        /// <param name="outStream">Stream to be written to</param>
        /// <param name="format">Wave format to use</param>
        public WaveFileWriter(Stream outStream, WaveFormat format)
        {
            this.outStream = outStream;
            BinaryWriter w = new BinaryWriter(outStream, System.Text.Encoding.ASCII);

            w.Write(System.Text.Encoding.ASCII.GetBytes("RIFF"));
            w.Write((int)0); // placeholder
            w.Write(System.Text.Encoding.ASCII.GetBytes("WAVEfmt "));
            this.format = format;

            format.Serialize(w);

            CreateFactChunk(outStream, format, w);

            WriteDataChunkHeader(outStream, w);
        }