Serialize() 공개 메소드

Writes this WaveFormat object to a stream
public Serialize ( BinaryWriter Writer ) : void
Writer System.IO.BinaryWriter the output stream
리턴 void
예제 #1
1
        /// <summary>
        /// Creates a <see cref="WaveFileWriter"/> that writes to a <see cref="Stream"/>.
        /// </summary>
        public WaveFileWriter(Stream outStream, WaveFormat format)
        {
            _ofstream = outStream;
            _writer = new BinaryWriter(outStream, UTF8);

            _writer.Write(UTF8.GetBytes("RIFF"));
            _writer.Write(0); // placeholder
            _writer.Write(UTF8.GetBytes("WAVEfmt "));
            _waveFormat = format;

            _writer.Write(18 + format.ExtraSize); // wave format Length
            format.Serialize(_writer);

            // CreateFactChunk
            if (format.Encoding != WaveFormatTag.Pcm)
            {
                _writer.Write(UTF8.GetBytes("fact"));
                _writer.Write(4);
                _factSampleCountPos = outStream.Position;
                _writer.Write(0); // number of samples
            }

            // WriteDataChunkHeader
            _writer.Write(UTF8.GetBytes("data"));
            _dataSizePos = outStream.Position;
            _writer.Write(0); // placeholder

            Length = 0;
        }
예제 #2
0
        /// <summary>
        /// Creates a <see cref="WaveFileWriter"/> that writes to a <see cref="Stream"/>.
        /// </summary>
        public WaveFileWriter(Stream outStream, WaveFormat format)
        {
            _ofstream = outStream;
            _writer   = new BinaryWriter(outStream, UTF8);

            _writer.Write(UTF8.GetBytes("RIFF"));
            _writer.Write(0); // placeholder
            _writer.Write(UTF8.GetBytes("WAVEfmt "));
            _waveFormat = format;

            _writer.Write(18 + format.ExtraSize); // wave format Length
            format.Serialize(_writer);

            // CreateFactChunk
            if (format.Encoding != WaveFormatTag.Pcm)
            {
                _writer.Write(UTF8.GetBytes("fact"));
                _writer.Write(4);
                _factSampleCountPos = outStream.Position;
                _writer.Write(0); // number of samples
            }

            // WriteDataChunkHeader
            _writer.Write(UTF8.GetBytes("data"));
            _dataSizePos = outStream.Position;
            _writer.Write(0); // placeholder

            Length = 0;
        }
예제 #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>
        WaveFileWriter(Stream outStream, WaveFormat format)
        {
            this.outStream = outStream;
            BinaryWriter w = new BinaryWriter(outStream, Encoding.ASCII);

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

            format.Serialize(w);

            CreateFactChunk(outStream, format, w);

            WriteDataChunkHeader(outStream, w);
        }