/// <summary> /// </summary> /// <param name="channelLayout">see <see cref="AVChannelLayout"/></param> /// <param name="nbSamples">recommended use <see cref="AVCodecContext.frame_size"/></param> /// <param name="format"><see cref="AVCodecContext.sample_fmt"/></param> /// <param name="sampleRate"></param> /// <param name="align"> /// Required buffer size alignment. If equal to 0, alignment will be chosen automatically for /// the current CPU. It is highly recommended to pass 0 here unless you know what you are doing. /// </param> public AudioFrame(AVChannelLayout channelLayout, int nbSamples, AVSampleFormat format, int sampleRate = 0, int align = 0) : this(ffmpeg.av_get_channel_layout_nb_channels((ulong)channelLayout), nbSamples, format, sampleRate, align) { unsafe { pFrame->channel_layout = (ulong)channelLayout; } }
public AudioFormat(int sampleRate, AVChannelLayout channelLayout, AVSampleFormat sampleFormat) { SampleRate = sampleRate; ChannelLayout = channelLayout; SampleFormat = sampleFormat; BitsPerSample = GetBytePerSample(sampleFormat) * 8; ValidBitsPerSample = SampleFormat.EqualsType(AVSampleFormat.Int32) ? 24 : BitsPerSample; }
public void Init(AVChannelLayout channelLayout, int nbSamples, AVSampleFormat format, int sampleRate = 0, int align = 0) { Clear(); AllocBuffer(ffmpeg.av_get_channel_layout_nb_channels((ulong)channelLayout), nbSamples, format, sampleRate, align); unsafe { pFrame->channel_layout = (ulong)channelLayout; } }
public AudioFormat(int sampleRate, AVChannelLayout channelLayout, AVSampleFormat sampleFormat) { SampleRate = sampleRate; ChannelLayout = channelLayout; SampleFormat = sampleFormat; Channels = GetChannels(channelLayout); BitsPerSample = GetBytePerSample(sampleFormat) * 8; SampleType = GetSampleType(sampleFormat); IsPlanarFormat = sampleFormat.IsPlanar(); LineCount = IsPlanarFormat ? Channels : 1; LineBlock = IsPlanarFormat ? (BitsPerSample >> 3) : (BitsPerSample >> 3) * Channels; ValidBitsPerSample = SampleFormat.EqualsType(AVSampleFormat.Int32) ? 24 : BitsPerSample; }
public AudioFormat Match(IEnumerable <int> sampleRates, IEnumerable <AVSampleFormat> sampleFormats, IEnumerable <AVChannelLayout> channelLayouts) { int sampleRate = SampleRate; if (sampleRates != null) { foreach (var sr in sampleRates.OrderBy(sr => sr)) { sampleRate = sr; if (sr >= SampleRate) { break; } } } AVSampleFormat sampleFormat = SampleFormat; if (sampleFormats != null) { foreach (var sf in sampleFormats.OrderBy(sf => GetBytePerSample(sf))) { sampleFormat = sf; if (GetBytePerSample(sf) >= BitsPerSample >> 3) { break; } } } AVChannelLayout channelLayout = ChannelLayout; if (channelLayouts != null) { foreach (var cl in channelLayouts.OrderBy(cl => GetChannels(cl))) { channelLayout = cl; if (GetChannels(cl) >= Channels) { break; } } } return(new AudioFormat(sampleRate, channelLayout, sampleFormat)); }
/// <summary> /// Return the number of channels in the channel layout use <see cref="ffmpeg.av_get_channel_layout_nb_channels(ulong)"/> /// </summary> /// <param name="channelLayout"></param> /// <returns></returns> public static int ToChannels(this AVChannelLayout channelLayout) { return(ffmpeg.av_get_channel_layout_nb_channels((ulong)channelLayout)); }
public static extern SwrContext *swr_alloc_set_opts(SwrContext *s, AVChannelLayout out_ch_layout, AVSampleFormat out_sample_fmt, int out_sample_rate, AVChannelLayout in_ch_layout, AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx);
public static extern byte *av_get_channel_description(AVChannelLayout channel);
public static extern byte *av_get_channel_name(AVChannelLayout channel);
public static extern AVChannelLayout av_channel_layout_extract_channel(AVChannelLayout channel_layout, int index);
public static extern int av_get_channel_layout_channel_index(AVChannelLayout channel_layout, AVChannelLayout channel);
public static extern int av_get_channel_layout_nb_channels(AVChannelLayout channel_layout);
public static extern void av_get_channel_layout_string(byte *buf, int buf_size, int nb_channels, AVChannelLayout channel_layout);
public static int GetChannels(AVChannelLayout channelLayout) { return(Internal.FFmpeg.av_get_channel_layout_nb_channels(channelLayout)); }
public extern static int swr_build_matrix(AVChannelLayout in_layout, AVChannelLayout out_layout, double center_mix_level, double surround_mix_level, double lfe_mix_level, double rematrix_maxval, double rematrix_volume, double *matrix, int stride, AVMatrixEncoding matrix_encoding, void *log_ctx);