26 #include "libavutil/opt.h"
41 int nb_samples,
int channels,
int direction,
42 int64_t
start,
int range,
int curve);
47 #define OFFSET(x) offsetof(AudioFadeContext, x)
48 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
55 {
"start_sample",
"set number of first sample to start fading",
OFFSET(start_sample),
AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, INT64_MAX,
FLAGS },
57 {
"nb_samples",
"set number of samples for fade duration",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64 = 44100}, 1, INT32_MAX,
FLAGS },
124 gain =
FFMAX(0.0,
FFMIN(1.0, 1.0 * index / range));
128 gain = sin(gain *
M_PI / 2.0);
131 gain = 1.0 - cos(
M_PI / 4.0 * (pow(2.0*gain - 1, 3) + 1));
134 gain = (1.0 - cos(gain *
M_PI)) / 2.0;
137 gain = pow(0.1, (1 - gain) * 5.0);
140 gain = (1 - (1 - gain) * (1 - gain));
146 gain = gain * gain * gain;
159 #define FADE_PLANAR(name, type) \
160 static void fade_samples_## name ##p(uint8_t **dst, uint8_t * const *src, \
161 int nb_samples, int channels, int dir, \
162 int64_t start, int range, int curve) \
166 for (i = 0; i < nb_samples; i++) { \
167 double gain = fade_gain(curve, start + i * dir, range); \
168 for (c = 0; c < channels; c++) { \
169 type *d = (type *)dst[c]; \
170 const type *s = (type *)src[c]; \
172 d[i] = s[i] * gain; \
177 #define FADE(name, type) \
178 static void fade_samples_## name (uint8_t **dst, uint8_t * const *src, \
179 int nb_samples, int channels, int dir, \
180 int64_t start, int range, int curve) \
182 type *d = (type *)dst[0]; \
183 const type *s = (type *)src[0]; \
186 for (i = 0; i < nb_samples; i++) { \
187 double gain = fade_gain(curve, start + i * dir, range); \
188 for (c = 0; c < channels; c++, k++) \
189 d[k] = s[k] * gain; \
208 switch (inlink->format) {
235 if ((!
s->type && (
s->start_sample +
s->nb_samples < cur_sample)) ||
236 (
s->type && (cur_sample +
s->nb_samples <
s->start_sample)))
248 if ((!
s->type && (cur_sample + nb_samples < s->start_sample)) ||
249 (
s->type && (
s->start_sample +
s->nb_samples < cur_sample))) {
256 start = cur_sample -
s->start_sample;
258 start =
s->start_sample +
s->nb_samples - cur_sample;
260 s->fade_samples(out_buf->extended_data,
buf->extended_data,
262 s->type ? -1 : 1, start,
263 s->nb_samples,
s->curve);
296 .
inputs = avfilter_af_afade_inputs,
297 .
outputs = avfilter_af_afade_outputs,
298 .priv_class = &afade_class,
static double fade_gain(int curve, int64_t index, int range)
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
static const AVFilterPad avfilter_af_afade_inputs[]
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
static enum AVSampleFormat formats[]
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int64_t start_time
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int query_formats(AVFilterContext *ctx)
#define FADE_PLANAR(name, type)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
void(* fade_samples)(uint8_t **dst, uint8_t *const *src, int nb_samples, int channels, int direction, int64_t start, int range, int curve)
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
static av_always_inline double cbrt(double x)
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int av_frame_get_channels(const AVFrame *frame)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int64_t av_rescale(int64_t a, int64_t b, int64_t c) av_const
Rescale a 64-bit integer with rounding to nearest.
#define AV_TIME_BASE
Internal time base represented as integer.
static const AVOption afade_options[]
A list of supported channel layouts.
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
AVSampleFormat
Audio Sample Formats.
static const AVFilterPad avfilter_af_afade_outputs[]
typedef void(RENAME(mix_any_func_type))
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
rational number numerator/denominator
AVFilterContext * dst
dest filter
enum MovChannelLayoutTag * layouts
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
static int config_input(AVFilterLink *inlink)
static av_cold int init(AVFilterContext *ctx)
#define AVFILTER_DEFINE_CLASS(fname)
static enum AVSampleFormat sample_fmts[]
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
int nb_samples
number of audio samples (per channel) described by this frame
AVFilter avfilter_af_afade