avfilter/asrc_anoisesrc: improve velvet noise output

This commit is contained in:
Paul B Mahol 2023-05-08 22:23:35 +02:00
parent 90096dd042
commit 086a0f3e5e
2 changed files with 18 additions and 10 deletions

View File

@ -7951,6 +7951,9 @@ Specify a value used to seed the PRNG.
@item nb_samples, n
Set the number of samples per each output frame, default is 1024.
@item density
Set the density (0.0 - 1.0) for the velvet noise generator, default is 0.05.
@end table
@subsection Examples

View File

@ -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)