コード例 #1
0
        /// <summary>
        /// Creates a source audio spec based on the info in the given audio frame
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <returns>The audio parameters</returns>
        internal static FFAudioParams CreateSource(AVFrame *frame)
        {
            var spec = new FFAudioParams(frame);

            if (spec.ChannelLayout == 0)
            {
                spec.ChannelLayout = ffmpeg.av_get_default_channel_layout(spec.ChannelCount);
            }

            return(spec);
        }
コード例 #2
0
        /// <summary>
        /// Initializes static members of the <see cref="FFAudioParams"/> class.
        /// </summary>
        static FFAudioParams()
        {
            Output = new FFAudioParams()
            {
                ChannelCount = Constants.Audio.ChannelCount,
                SampleRate   = Constants.Audio.SampleRate,
                Format       = Constants.Audio.SampleFormat
            };

            Output.ChannelLayout     = ffmpeg.av_get_default_channel_layout(Output.ChannelCount);
            Output.SamplesPerChannel = Output.SampleRate;
            Output.BufferLength      = ffmpeg.av_samples_get_buffer_size(
                null, Output.ChannelCount, Output.SamplesPerChannel + Constants.Audio.BufferPadding, Output.Format, 1);
        }
コード例 #3
0
        /// <summary>
        /// Creates a target audio spec using the sample quantities provided
        /// by the given source audio frame
        /// </summary>
        /// <param name="frame">The frame.</param>
        /// <returns>The audio parameters</returns>
        internal static FFAudioParams CreateTarget(AVFrame *frame)
        {
            var spec = new FFAudioParams
            {
                ChannelCount  = Output.ChannelCount,
                Format        = Output.Format,
                SampleRate    = Output.SampleRate,
                ChannelLayout = Output.ChannelLayout
            };

            // The target transform is just a ratio of the source frame's sample. This is how many samples we desire
            spec.SamplesPerChannel = Convert.ToInt32(Convert.ToDouble(frame->nb_samples) * spec.SampleRate / frame->sample_rate);
            spec.BufferLength      = ffmpeg.av_samples_get_buffer_size(
                null, spec.ChannelCount, spec.SamplesPerChannel + Constants.Audio.BufferPadding, spec.Format, 1);
            return(spec);
        }
コード例 #4
0
 /// <summary>
 /// Determines if the audio specs are compatible between them.
 /// They must share format, channel count, layout and sample rate
 /// </summary>
 /// <param name="a">a.</param>
 /// <param name="b">The b.</param>
 /// <returns>True if the params are compatible, false otherwise.</returns>
 internal static bool AreCompatible(FFAudioParams a, FFAudioParams b)
 {
     if (a.Format != b.Format)
     {
         return(false);
     }
     if (a.ChannelCount != b.ChannelCount)
     {
         return(false);
     }
     if (a.ChannelLayout != b.ChannelLayout)
     {
         return(false);
     }
     return(a.SampleRate == b.SampleRate);
 }