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,