Beispiel #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);
        }
Beispiel #2
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);
 }
Beispiel #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.AudioBufferPadding, spec.Format, 1);
            return(spec);
        }