]> git.sesse.net Git - ffmpeg/commitdiff
avfilter/af_afreqshift: add level option
authorPaul B Mahol <onemda@gmail.com>
Sat, 5 Dec 2020 13:44:14 +0000 (14:44 +0100)
committerPaul B Mahol <onemda@gmail.com>
Sat, 5 Dec 2020 13:46:16 +0000 (14:46 +0100)
doc/filters.texi
libavfilter/af_afreqshift.c

index 6200590f84c333f86dc57d4604963ac27eb7e2df..99fcae2650e01f957d48f44e54f9d285755f1405 100644 (file)
@@ -1419,11 +1419,15 @@ The filter accepts the following options:
 @item shift
 Specify frequency shift. Allowed range is -INT_MAX to INT_MAX.
 Default value is 0.0.
+
+@item level
+Set output gain applied to final output. Allowed range is from -1.0 to 1.0.
+Default value is 1.0.
 @end table
 
 @subsection Commands
 
-This filter supports the above option as @ref{commands}.
+This filter supports the all above options as @ref{commands}.
 
 @section agate
 
@@ -2182,11 +2186,15 @@ The filter accepts the following options:
 @item shift
 Specify phase shift. Allowed range is from -1.0 to 1.0.
 Default value is 0.0.
+
+@item level
+Set output gain applied to final output. Allowed range is from -1.0 to 1.0.
+Default value is 1.0.
 @end table
 
 @subsection Commands
 
-This filter supports the above option as @ref{commands}.
+This filter supports the all above options as @ref{commands}.
 
 @section apulsator
 
index a61c15a97ee4a5143b09bc2141ff86b8be1be5c9..4cc4e27c1c8040e39f81c2467a1f4d81fe9d97c1 100644 (file)
@@ -32,6 +32,7 @@ typedef struct AFreqShift {
     const AVClass *class;
 
     double shift;
+    double level;
 
     double c[NB_COEFS];
 
@@ -85,7 +86,8 @@ static void pfilter_channel(AVFilterContext *ctx,
                             double *i2, double *o2)
 {
     AFreqShift *s = ctx->priv;
-    double *c = s->c;
+    const double *c = s->c;
+    const double level = s->level;
     double shift = s->shift * M_PI;
     double cos_theta = cos(shift);
     double sin_theta = sin(shift);
@@ -113,7 +115,7 @@ static void pfilter_channel(AVFilterContext *ctx,
         }
         Q = o2[NB_COEFS - 1];
 
-        dst[n] = I * cos_theta - Q * sin_theta;
+        dst[n] = (I * cos_theta - Q * sin_theta) * level;
     }
 }
 
@@ -125,7 +127,8 @@ static void ffilter_channel(AVFilterContext *ctx,
                             double *i2, double *o2)
 {
     AFreqShift *s = ctx->priv;
-    double *c = s->c;
+    const double *c = s->c;
+    const double level = s->level;
     double ts = 1. / sample_rate;
     double shift = s->shift;
     int64_t N = s->in_samples;
@@ -154,7 +157,7 @@ static void ffilter_channel(AVFilterContext *ctx,
         Q = o2[NB_COEFS - 1];
 
         theta = 2. * M_PI * fmod(shift * (N + n) * ts, 1.);
-        dst[n] = I * cos(theta) - Q * sin(theta);
+        dst[n] = (I * cos(theta) - Q * sin(theta)) * level;
     }
 }
 
@@ -345,6 +348,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 
 static const AVOption afreqshift_options[] = {
     { "shift", "set frequency shift", OFFSET(shift), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -INT_MAX, INT_MAX, FLAGS },
+    { "level", "set output level",    OFFSET(level), AV_OPT_TYPE_DOUBLE, {.dbl=1},      0.0,     1.0, FLAGS },
     { NULL }
 };
 
@@ -384,6 +388,7 @@ AVFilter ff_af_afreqshift = {
 
 static const AVOption aphaseshift_options[] = {
     { "shift", "set phase shift", OFFSET(shift), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1.0, 1.0, FLAGS },
+    { "level", "set output level",OFFSET(level), AV_OPT_TYPE_DOUBLE, {.dbl=1},  0.0, 1.0, FLAGS },
     { NULL }
 };