Exemple #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;
            }));
        }
Exemple #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;
            }));
        }
Exemple #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;
            }));
        }
Exemple #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;
            }));
        }