[FFmpeg-cvslog] avfilter/asrc_anoisesrc: add velvet noise
Paul B Mahol
git at videolan.org
Sat Jan 18 18:27:56 EET 2020
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Jan 13 17:56:19 2020 +0100| [273886fa60c347e07c57ec2b927f70ad94fc84bb] | committer: Paul B Mahol
avfilter/asrc_anoisesrc: add velvet noise
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=273886fa60c347e07c57ec2b927f70ad94fc84bb
---
doc/filters.texi | 2 +-
libavfilter/asrc_anoisesrc.c | 22 +++++++++++++++-------
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 237e182aa8..05739c7c6c 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -5985,7 +5985,7 @@ results in noise with an infinite length.
@item color, colour, c
Specify the color of noise. Available noise colors are white, pink, brown,
-blue and violet. Default color is white.
+blue, violet and velvet. Default color is white.
@item seed, s
Specify a value used to seed the PRNG.
diff --git a/libavfilter/asrc_anoisesrc.c b/libavfilter/asrc_anoisesrc.c
index cedadde6c9..ebcc446ae1 100644
--- a/libavfilter/asrc_anoisesrc.c
+++ b/libavfilter/asrc_anoisesrc.c
@@ -36,7 +36,7 @@ typedef struct ANoiseSrcContext {
int64_t pts;
int infinite;
- double (*filter)(double white, double *buf);
+ double (*filter)(double white, double *buf, double half_amplitude);
double buf[7];
AVLFG c;
} ANoiseSrcContext;
@@ -47,6 +47,7 @@ enum NoiseMode {
NM_BROWN,
NM_BLUE,
NM_VIOLET,
+ NM_VELVET,
NM_NB
};
@@ -68,6 +69,7 @@ static const AVOption anoisesrc_options[] = {
{ "brown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = NM_BROWN}, 0, 0, FLAGS, "color" },
{ "blue", 0, 0, AV_OPT_TYPE_CONST, {.i64 = NM_BLUE}, 0, 0, FLAGS, "color" },
{ "violet", 0, 0, AV_OPT_TYPE_CONST, {.i64 = NM_VIOLET}, 0, 0, FLAGS, "color" },
+ { "velvet", 0, 0, AV_OPT_TYPE_CONST, {.i64 = NM_VELVET}, 0, 0, FLAGS, "color" },
{ "seed", "set random seed", OFFSET(seed), AV_OPT_TYPE_INT64, {.i64 = -1}, -1, UINT_MAX, FLAGS },
{ "s", "set random seed", OFFSET(seed), AV_OPT_TYPE_INT64, {.i64 = -1}, -1, UINT_MAX, FLAGS },
{ "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, INT_MAX, FLAGS },
@@ -111,12 +113,12 @@ static av_cold int query_formats(AVFilterContext *ctx)
return ff_set_common_samplerates(ctx, formats);
}
-static double white_filter(double white, double *buf)
+static double white_filter(double white, double *buf, double ha)
{
return white;
}
-static double pink_filter(double white, double *buf)
+static double pink_filter(double white, double *buf, double ha)
{
double pink;
@@ -132,7 +134,7 @@ static double pink_filter(double white, double *buf)
return pink * 0.11;
}
-static double blue_filter(double white, double *buf)
+static double blue_filter(double white, double *buf, double ha)
{
double blue;
@@ -148,7 +150,7 @@ static double blue_filter(double white, double *buf)
return blue * 0.11;
}
-static double brown_filter(double white, double *buf)
+static double brown_filter(double white, double *buf, double ha)
{
double brown;
@@ -157,7 +159,7 @@ static double brown_filter(double white, double *buf)
return brown * 3.5;
}
-static double violet_filter(double white, double *buf)
+static double violet_filter(double white, double *buf, double ha)
{
double violet;
@@ -166,6 +168,11 @@ static double violet_filter(double white, double *buf)
return violet * 3.5;
}
+static double velvet_filter(double white, double *buf, double ha)
+{
+ return 2. * ha * ((white > ha) - (white < -ha));
+}
+
static av_cold int config_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
@@ -185,6 +192,7 @@ static av_cold int config_props(AVFilterLink *outlink)
case NM_BROWN: s->filter = brown_filter; break;
case NM_BLUE: s->filter = blue_filter; break;
case NM_VIOLET: s->filter = violet_filter; break;
+ case NM_VELVET: s->filter = velvet_filter; break;
}
return 0;
@@ -213,7 +221,7 @@ static int request_frame(AVFilterLink *outlink)
for (i = 0; i < nb_samples; i++) {
double white;
white = s->amplitude * ((2 * ((double) av_lfg_get(&s->c) / 0xffffffff)) - 1);
- dst[i] = s->filter(white, s->buf);
+ dst[i] = s->filter(white, s->buf, s->amplitude * 0.5);
}
if (!s->infinite)
More information about the ffmpeg-cvslog
mailing list