示例#1
0
        /// <summary>Adds new encoding audio stream.</summary>
        /// <param name="encoder">Encoder to be used.</param>
        /// <param name="ownsEncoder">Whether encoder should be disposed with the writer.</param>
        /// <returns>Newly added audio stream.</returns>
        /// <remarks>
        /// <para>
        /// Stream is initialized to be to be encoded with the specified encoder.
        /// Method <see cref="IAviAudioStream.WriteBlock"/> expects data in the same format as encoder (see encoder's docs).
        /// The data is passed to the encoder and the encoded result is written to the stream.
        /// </para>
        /// <para>
        /// The encoder defines the following properties of the stream:
        /// <see cref="IAviAudioStream.ChannelCount"/>, <see cref="IAviAudioStream.SamplesPerSecond"/>,
        /// <see cref="IAviAudioStream.BitsPerSample"/>, <see cref="IAviAudioStream.BytesPerSecond"/>,
        /// <see cref="IAviAudioStream.Granularity"/>, <see cref="IAviAudioStream.Format"/>,
        /// <see cref="IAviAudioStream.FormatSpecificData"/>.
        /// These properties cannot be modified.
        /// </para>
        /// </remarks>
        public IAviAudioStream AddEncodingAudioStream(IAudioEncoder encoder, bool ownsEncoder = true)
        {
            Argument.IsNotNull(encoder, nameof(encoder));

            return(AddStream <IAviAudioStreamInternal>(index =>
            {
                var stream = new AviAudioStream(index, this, 1, 44100, 16);
                var encodingStream = new EncodingAudioStreamWrapper(stream, encoder, ownsEncoder);
                var asyncStream = new AsyncAudioStreamWrapper(encodingStream);
                return asyncStream;
            }));
        }
示例#2
0
        /// <summary>Adds new encoding audio stream.</summary>
        /// <param name="encoder">Encoder to be used.</param>
        /// <param name="ownsEncoder">Whether encoder should be disposed with the writer.</param>
        /// <returns>Newly added audio stream.</returns>
        /// <remarks>
        /// <para>
        /// Stream is initialized to be to be encoded with the specified encoder.
        /// Method <see cref="IAviAudioStream.WriteBlock"/> expects data in the same format as encoder (see encoder's docs).
        /// The data is passed to the encoder and the encoded result is written to the stream.
        /// </para>
        /// <para>
        /// The encoder defines the following properties of the stream:
        /// <see cref="IAviAudioStream.ChannelCount"/>, <see cref="IAviAudioStream.SamplesPerSecond"/>,
        /// <see cref="IAviAudioStream.BitsPerSample"/>, <see cref="IAviAudioStream.BytesPerSecond"/>,
        /// <see cref="IAviAudioStream.Granularity"/>, <see cref="IAviAudioStream.Format"/>,
        /// <see cref="IAviAudioStream.FormatSpecificData"/>.
        /// These properties cannot be modified.
        /// </para>
        /// </remarks>
        public IAviAudioStream AddEncodingAudioStream(IAudioEncoder encoder, bool ownsEncoder = true)
        {
            Contract.Requires(encoder != null);
            Contract.Requires(Streams.Count < 100);
            Contract.Ensures(Contract.Result <IAviAudioStream>() != null);

            return(AddStream <IAviAudioStreamInternal>(index =>
            {
                var stream = new AviAudioStream(index, this, 1, 44100, 16);
                var encodingStream = new EncodingAudioStreamWrapper(stream, encoder, ownsEncoder);
                var asyncStream = new AsyncAudioStreamWrapper(encodingStream);
                return asyncStream;
            }));
        }
示例#3
0
        /// <summary>Adds new audio stream.</summary>
        /// <param name="channelCount">Number of channels.</param>
        /// <param name="samplesPerSecond">Sample rate.</param>
        /// <param name="bitsPerSample">Bits per sample (per single channel).</param>
        /// <returns>Newly added audio stream.</returns>
        /// <remarks>
        /// Stream is initialized to be ready for uncompressed audio (PCM) with specified parameters.
        /// However, properties (such as <see cref="IAviAudioStream.Format"/>) can be changed later if the stream is
        /// to be fed with pre-compressed data.
        /// </remarks>
        public IAviAudioStream AddAudioStream(int channelCount = 1, int samplesPerSecond = 44100, int bitsPerSample = 16)
        {
            Argument.IsPositive(channelCount, nameof(channelCount));
            Argument.IsPositive(samplesPerSecond, nameof(samplesPerSecond));
            Argument.IsPositive(bitsPerSample, nameof(bitsPerSample));
            Argument.Meets(bitsPerSample % 8 == 0, nameof(bitsPerSample), "A multiple of 8 is expected.");

            return(AddStream <IAviAudioStreamInternal>(index =>
            {
                var stream = new AviAudioStream(index, this, channelCount, samplesPerSecond, bitsPerSample);
                var asyncStream = new AsyncAudioStreamWrapper(stream);
                return asyncStream;
            }));
        }
示例#4
0
        /// <summary>Adds new audio stream.</summary>
        /// <param name="channelCount">Number of channels.</param>
        /// <param name="samplesPerSecond">Sample rate.</param>
        /// <param name="bitsPerSample">Bits per sample (per single channel).</param>
        /// <returns>Newly added audio stream.</returns>
        /// <remarks>
        /// Stream is initialized to be ready for uncompressed audio (PCM) with specified parameters.
        /// However, properties (such as <see cref="IAviAudioStream.Format"/>) can be changed later if the stream is
        /// to be fed with pre-compressed data.
        /// </remarks>
        public IAviAudioStream AddAudioStream(int channelCount = 1, int samplesPerSecond = 44100, int bitsPerSample = 16)
        {
            Contract.Requires(channelCount > 0);
            Contract.Requires(samplesPerSecond > 0);
            Contract.Requires(bitsPerSample > 0 && (bitsPerSample % 8) == 0);
            Contract.Requires(Streams.Count < 100);
            Contract.Ensures(Contract.Result <IAviAudioStream>() != null);

            return(AddStream <IAviAudioStreamInternal>(index =>
            {
                var stream = new AviAudioStream(index, this, channelCount, samplesPerSecond, bitsPerSample);
                var asyncStream = new AsyncAudioStreamWrapper(stream);
                return asyncStream;
            }));
        }
示例#5
0
 void IAviStreamWriteHandler.WriteStreamHeader(AviAudioStream audioStream)
 {
     // See AVISTREAMHEADER structure
     fileWriter.Write((uint)audioStream.StreamType);
     fileWriter.Write(0U);                                                 // no codec
     fileWriter.Write(0U);                                                 // StreamHeaderFlags
     fileWriter.Write((ushort)0);                                          // priority
     fileWriter.Write((ushort)0);                                          // language
     fileWriter.Write(0U);                                                 // initial frames
     fileWriter.Write((uint)audioStream.Granularity);                      // scale (sample rate denominator)
     fileWriter.Write((uint)audioStream.BytesPerSecond);                   // rate (sample rate numerator)
     fileWriter.Write(0U);                                                 // start
     fileWriter.Write((uint)streamsInfo[audioStream.Index].TotalDataSize); // length
     fileWriter.Write((uint)(audioStream.BytesPerSecond / 2));             // suggested buffer size (half-second)
     fileWriter.Write(-1);                                                 // quality
     fileWriter.Write(audioStream.Granularity);                            // sample size
     fileWriter.SkipBytes(sizeof(short) * 4);
 }
示例#6
0
 void IAviStreamWriteHandler.WriteStreamFormat(AviAudioStream audioStream)
 {
     // See WAVEFORMATEX structure
     fileWriter.Write(audioStream.Format);
     fileWriter.Write((ushort)audioStream.ChannelCount);
     fileWriter.Write((uint)audioStream.SamplesPerSecond);
     fileWriter.Write((uint)audioStream.BytesPerSecond);
     fileWriter.Write((ushort)audioStream.Granularity);
     fileWriter.Write((ushort)audioStream.BitsPerSample);
     if (audioStream.FormatSpecificData != null)
     {
         fileWriter.Write((ushort)audioStream.FormatSpecificData.Length);
         fileWriter.Write(audioStream.FormatSpecificData);
     }
     else
     {
         fileWriter.Write((ushort)0);
     }
 }
示例#7
0
 void IAviStreamWriteHandler.WriteAudioBlock(AviAudioStream stream, byte[] blockData, int startIndex, int count)
 {
     WriteStreamFrame(stream, true, blockData, startIndex, count);
 }
示例#8
0
 void IAviStreamWriteHandler.WriteAudioBlock(AviAudioStream stream, ReadOnlySpan <byte> blockData)
 => WriteStreamFrame(stream, true, blockData);