[FFmpeg-cvslog] avfilter/af_afreqshift: add level option

Paul B Mahol git at videolan.org
Sat Dec 5 15:47:32 EET 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sat Dec  5 14:44:14 2020 +0100| [530d1dbcef6b8de4e506e4248a313ba729dfdf4f] | committer: Paul B Mahol

avfilter/af_afreqshift: add level option

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

 doc/filters.texi            | 12 ++++++++++--
 libavfilter/af_afreqshift.c | 13 +++++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 6200590f84..99fcae2650 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -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.
+
+ at 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.
+
+ at 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
 
diff --git a/libavfilter/af_afreqshift.c b/libavfilter/af_afreqshift.c
index a61c15a97e..4cc4e27c1c 100644
--- a/libavfilter/af_afreqshift.c
+++ b/libavfilter/af_afreqshift.c
@@ -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 }
 };
 



More information about the ffmpeg-cvslog mailing list