aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/af_afade.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2023-08-20 17:36:45 +0200
committerPaul B Mahol <onemda@gmail.com>2023-08-24 22:20:06 +0200
commit52ebb15ec1a9c5c80548262750ba07bde816cdf2 (patch)
treed617f7bc9085bc134793260a2ce666eb683f17d0 /libavfilter/af_afade.c
parente41bd6e65e1485fd1b44540638d06638406be2f4 (diff)
downloadffmpeg-52ebb15ec1a9c5c80548262750ba07bde816cdf2.tar.gz
avfilter/af_afade: add 4 more curves
Diffstat (limited to 'libavfilter/af_afade.c')
-rw-r--r--libavfilter/af_afade.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/libavfilter/af_afade.c b/libavfilter/af_afade.c
index 226b63c275..3de673f73f 100644
--- a/libavfilter/af_afade.c
+++ b/libavfilter/af_afade.c
@@ -58,7 +58,7 @@ typedef struct AudioFadeContext {
int curve0, int curve1);
} AudioFadeContext;
-enum CurveType { NONE = -1, TRI, QSIN, ESIN, HSIN, LOG, IPAR, QUA, CUB, SQU, CBR, PAR, EXP, IQSIN, IHSIN, DESE, DESI, LOSI, SINC, ISINC, NB_CURVES };
+enum CurveType { NONE = -1, TRI, QSIN, ESIN, HSIN, LOG, IPAR, QUA, CUB, SQU, CBR, PAR, EXP, IQSIN, IHSIN, DESE, DESI, LOSI, SINC, ISINC, QUAT, QUATR, QSIN2, HSIN2, NB_CURVES };
#define OFFSET(x) offsetof(AudioFadeContext, x)
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
@@ -142,6 +142,18 @@ static double fade_gain(int curve, int64_t index, int64_t range, double silence,
case ISINC:
gain = gain <= 0.0 ? 0.0 : 1.0 - sin(M_PI * gain) / (M_PI * gain);
break;
+ case QUAT:
+ gain = gain * gain * gain * gain;
+ break;
+ case QUATR:
+ gain = pow(gain, 0.25);
+ break;
+ case QSIN2:
+ gain = sin(gain * M_PI / 2.0) * sin(gain * M_PI / 2.0);
+ break;
+ case HSIN2:
+ gain = pow((1.0 - cos(gain * M_PI)) / 2.0, 2.0);
+ break;
case NONE:
gain = 1.0;
break;
@@ -316,6 +328,10 @@ static const AVOption afade_options[] = {
{ "losi", "logistic sigmoid", 0, AV_OPT_TYPE_CONST, {.i64 = LOSI }, 0, 0, TFLAGS, "curve" },
{ "sinc", "sine cardinal function", 0, AV_OPT_TYPE_CONST, {.i64 = SINC }, 0, 0, TFLAGS, "curve" },
{ "isinc", "inverted sine cardinal function", 0, AV_OPT_TYPE_CONST, {.i64 = ISINC}, 0, 0, TFLAGS, "curve" },
+ { "quat", "quartic", 0, AV_OPT_TYPE_CONST, {.i64 = QUAT }, 0, 0, TFLAGS, "curve" },
+ { "quatr", "quartic root", 0, AV_OPT_TYPE_CONST, {.i64 = QUATR}, 0, 0, TFLAGS, "curve" },
+ { "qsin2", "squared quarter of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = QSIN2}, 0, 0, TFLAGS, "curve" },
+ { "hsin2", "squared half of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = HSIN2}, 0, 0, TFLAGS, "curve" },
{ "silence", "set the silence gain", OFFSET(silence), AV_OPT_TYPE_DOUBLE, {.dbl = 0 }, 0, 1, TFLAGS },
{ "unity", "set the unity gain", OFFSET(unity), AV_OPT_TYPE_DOUBLE, {.dbl = 1 }, 0, 1, TFLAGS },
{ NULL }
@@ -464,6 +480,10 @@ static const AVOption acrossfade_options[] = {
{ "losi", "logistic sigmoid", 0, AV_OPT_TYPE_CONST, {.i64 = LOSI }, 0, 0, FLAGS, "curve" },
{ "sinc", "sine cardinal function", 0, AV_OPT_TYPE_CONST, {.i64 = SINC }, 0, 0, FLAGS, "curve" },
{ "isinc", "inverted sine cardinal function", 0, AV_OPT_TYPE_CONST, {.i64 = ISINC}, 0, 0, FLAGS, "curve" },
+ { "quat", "quartic", 0, AV_OPT_TYPE_CONST, {.i64 = QUAT }, 0, 0, FLAGS, "curve" },
+ { "quatr", "quartic root", 0, AV_OPT_TYPE_CONST, {.i64 = QUATR}, 0, 0, FLAGS, "curve" },
+ { "qsin2", "squared quarter of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = QSIN2}, 0, 0, FLAGS, "curve" },
+ { "hsin2", "squared half of sine wave", 0, AV_OPT_TYPE_CONST, {.i64 = HSIN2}, 0, 0, FLAGS, "curve" },
{ "curve2", "set fade curve type for 2nd stream", OFFSET(curve2), AV_OPT_TYPE_INT, {.i64 = TRI }, NONE, NB_CURVES - 1, FLAGS, "curve" },
{ "c2", "set fade curve type for 2nd stream", OFFSET(curve2), AV_OPT_TYPE_INT, {.i64 = TRI }, NONE, NB_CURVES - 1, FLAGS, "curve" },
{ NULL }