[FFmpeg-cvslog] avfilter/af_afade: add 4 more curves

Paul B Mahol git at videolan.org
Thu Aug 24 23:12:57 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Aug 20 17:36:45 2023 +0200| [52ebb15ec1a9c5c80548262750ba07bde816cdf2] | committer: Paul B Mahol

avfilter/af_afade: add 4 more curves

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=52ebb15ec1a9c5c80548262750ba07bde816cdf2
---

 doc/filters.texi       |  8 ++++++++
 libavfilter/af_afade.c | 22 +++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index cac1ee4381..90e6c433c4 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1459,6 +1459,14 @@ select logistic sigmoid
 select sine cardinal function
 @item isinc
 select inverted sine cardinal function
+ at item quat
+select quartic
+ at item quatr
+select quartic root
+ at item qsin2
+select squared quarter of sine wave
+ at item hsin2
+select squared half of sine wave
 @item nofade
 no fade applied
 @end table
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 }



More information about the ffmpeg-cvslog mailing list