summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2023-05-08 22:23:35 +0200
committerPaul B Mahol <onemda@gmail.com>2023-05-09 00:42:36 +0200
commit086a0f3e5edee4d5f97c5759fbf5c893f58fb6e5 (patch)
treee43791343d6cbb31a998fc41035318969f9c221d /libavfilter
parent90096dd04216b1bb398525631206172f07e382ca (diff)
downloadffmpeg-086a0f3e5edee4d5f97c5759fbf5c893f58fb6e5.tar.gz
avfilter/asrc_anoisesrc: improve velvet noise output
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/asrc_anoisesrc.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/libavfilter/asrc_anoisesrc.c b/libavfilter/asrc_anoisesrc.c
index 96a8fd63e9..1c8dccf689 100644
--- a/libavfilter/asrc_anoisesrc.c
+++ b/libavfilter/asrc_anoisesrc.c
@@ -31,6 +31,7 @@ typedef struct ANoiseSrcContext {
const AVClass *class;
int sample_rate;
double amplitude;
+ double density;
int64_t duration;
int color;
int64_t seed;
@@ -38,7 +39,7 @@ typedef struct ANoiseSrcContext {
int64_t pts;
int infinite;
- double (*filter)(double white, double *buf, double half_amplitude);
+ double (*filter)(double white, double *buf);
double buf[7];
AVLFG c;
} ANoiseSrcContext;
@@ -76,6 +77,7 @@ static const AVOption anoisesrc_options[] = {
{ "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 },
{ "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, INT_MAX, FLAGS },
+ { "density", "set density", OFFSET(density), AV_OPT_TYPE_DOUBLE, {.dbl = 0.05}, 0., 1., FLAGS },
{NULL}
};
@@ -101,12 +103,12 @@ static av_cold int query_formats(AVFilterContext *ctx)
return ff_set_common_samplerates_from_list(ctx, sample_rates);
}
-static double white_filter(double white, double *buf, double ha)
+static double white_filter(double white, double *buf)
{
return white;
}
-static double pink_filter(double white, double *buf, double ha)
+static double pink_filter(double white, double *buf)
{
double pink;
@@ -122,7 +124,7 @@ static double pink_filter(double white, double *buf, double ha)
return pink * 0.11;
}
-static double blue_filter(double white, double *buf, double ha)
+static double blue_filter(double white, double *buf)
{
double blue;
@@ -138,7 +140,7 @@ static double blue_filter(double white, double *buf, double ha)
return blue * 0.11;
}
-static double brown_filter(double white, double *buf, double ha)
+static double brown_filter(double white, double *buf)
{
double brown;
@@ -147,7 +149,7 @@ static double brown_filter(double white, double *buf, double ha)
return brown * 3.5;
}
-static double violet_filter(double white, double *buf, double ha)
+static double violet_filter(double white, double *buf)
{
double violet;
@@ -156,9 +158,10 @@ static double violet_filter(double white, double *buf, double ha)
return violet * 3.5;
}
-static double velvet_filter(double white, double *buf, double ha)
+static double velvet_filter(double white, double *buf)
{
- return 2. * ha * ((white > ha) - (white < -ha));
+ double awhite = fabs(white);
+ return FFDIFFSIGN(white, 0.0) * buf[1] * (awhite < buf[0]);
}
static av_cold int config_props(AVFilterLink *outlink)
@@ -180,7 +183,9 @@ 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;
+ case NM_VELVET: s->buf[0] = s->amplitude * s->density;
+ s->buf[1] = s->amplitude;
+ s->filter = velvet_filter; break;
}
return 0;
@@ -213,7 +218,7 @@ static int activate(AVFilterContext *ctx)
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, s->amplitude * 0.5);
+ dst[i] = s->filter(white, s->buf);
}
if (!s->infinite)