Message ID | 20170719055933.10754-1-george@spotify.com |
---|---|
State | Superseded |
Headers | show |
On 7/19/17, george@spotify.com <george@spotify.com> wrote: > From: George Boyle <george@spotify.com> > > For the blue and violet noise, I took the pink and brown noise > respectively and subtracted the offsets instead of adding them. When I > eyeball the frequency spectrum of the resulting outputs it looks correct > to me, i.e. the blue graph appears to be a mirror image of the pink, and > the same can be said of the violet and the brown. I did not do anything > else to confirm the correctness. > --- > doc/filters.texi | 4 ++-- > libavfilter/asrc_anoisesrc.c | 41 +++++++++++++++++++++++++++++++++++------ > 2 files changed, 37 insertions(+), 8 deletions(-) > lgtm
On Wed, Jul 19, 2017 at 07:59:33 +0200, george@spotify.com wrote: > For the blue and violet noise, I took the pink and brown noise > respectively and subtracted the offsets instead of adding them. When I Cool. > - { "color", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 2, FLAGS, "color" }, > - { "colour", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 2, FLAGS, "color" }, > - { "c", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 2, FLAGS, "color" }, > + { "color", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 4, FLAGS, "color" }, > + { "colour", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 4, FLAGS, "color" }, > + { "c", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, FLAGS, "color" }, At this point, it's probably worth adding an enum. enum NoiseMode { NM_WHITE, NM_PINK, [...] NM_NB }; and setting the option's max to "NM_NB-1" instead of "4". > switch (s->color) { > - case 0: s->filter = white_filter; break; > - case 1: s->filter = pink_filter; break; > - case 2: s->filter = brown_filter; break; > + case 0: s->filter = white_filter; break; > + case 1: s->filter = pink_filter; break; > + case 2: s->filter = brown_filter; break; > + case 3: s->filter = blue_filter; break; > + case 4: s->filter = violet_filter; break; And use the enums here. Just a suggestion... Cheers, Moritz
On Wed, Jul 19, 2017 at 1:39 PM, Moritz Barsnick <barsnick@gmx.net> wrote: > On Wed, Jul 19, 2017 at 07:59:33 +0200, george@spotify.com wrote: > > For the blue and violet noise, I took the pink and brown noise > > respectively and subtracted the offsets instead of adding them. When I > > Cool. > > > - { "color", "set noise color", OFFSET(color), > AV_OPT_TYPE_INT, {.i64 = 1}, 0, 2, FLAGS, "color" }, > > - { "colour", "set noise color", OFFSET(color), > AV_OPT_TYPE_INT, {.i64 = 1}, 0, 2, FLAGS, "color" }, > > - { "c", "set noise color", OFFSET(color), > AV_OPT_TYPE_INT, {.i64 = 0}, 0, 2, FLAGS, "color" }, > > + { "color", "set noise color", OFFSET(color), > AV_OPT_TYPE_INT, {.i64 = 1}, 0, 4, FLAGS, "color" }, > > + { "colour", "set noise color", OFFSET(color), > AV_OPT_TYPE_INT, {.i64 = 1}, 0, 4, FLAGS, "color" }, > > + { "c", "set noise color", OFFSET(color), > AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, FLAGS, "color" }, > > At this point, it's probably worth adding an enum. > > enum NoiseMode { > NM_WHITE, > NM_PINK, > [...] > NM_NB > }; > > and setting the option's max to "NM_NB-1" instead of "4". > > > switch (s->color) { > > - case 0: s->filter = white_filter; break; > > - case 1: s->filter = pink_filter; break; > > - case 2: s->filter = brown_filter; break; > > + case 0: s->filter = white_filter; break; > > + case 1: s->filter = pink_filter; break; > > + case 2: s->filter = brown_filter; break; > > + case 3: s->filter = blue_filter; break; > > + case 4: s->filter = violet_filter; break; > > And use the enums here. > > Just a suggestion... > > Thanks for the comments. New patch on the way...
diff --git a/doc/filters.texi b/doc/filters.texi index 2708fdb1df..dd88636bb9 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -4471,8 +4471,8 @@ Specify the duration of the generated audio stream. Not specifying this option results in noise with an infinite length. @item color, colour, c -Specify the color of noise. Available noise colors are white, pink, and brown. -Default color is white. +Specify the color of noise. Available noise colors are white, pink, brown, +blue and violet. 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 be0d5ab6a5..b60fdfe331 100644 --- a/libavfilter/asrc_anoisesrc.c +++ b/libavfilter/asrc_anoisesrc.c @@ -51,12 +51,14 @@ static const AVOption anoisesrc_options[] = { { "a", "set amplitude", OFFSET(amplitude), AV_OPT_TYPE_DOUBLE, {.dbl = 1.}, 0., 1., FLAGS }, { "duration", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, FLAGS }, { "d", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, FLAGS }, - { "color", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 2, FLAGS, "color" }, - { "colour", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 2, FLAGS, "color" }, - { "c", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 2, FLAGS, "color" }, + { "color", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 4, FLAGS, "color" }, + { "colour", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 4, FLAGS, "color" }, + { "c", "set noise color", OFFSET(color), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, FLAGS, "color" }, { "white", 0, 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, FLAGS, "color" }, { "pink", 0, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, FLAGS, "color" }, { "brown", 0, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, FLAGS, "color" }, + { "blue", 0, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, FLAGS, "color" }, + { "violet", 0, 0, AV_OPT_TYPE_CONST, {.i64 = 4}, 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 }, @@ -121,6 +123,22 @@ static double pink_filter(double white, double *buf) return pink * 0.11; } +static double blue_filter(double white, double *buf) +{ + double blue; + + /* Same as pink_filter but subtract the offsets rather than add */ + buf[0] = 0.0555179 * white - 0.99886 * buf[0]; + buf[1] = 0.0750759 * white - 0.99332 * buf[1]; + buf[2] = 0.1538520 * white - 0.96900 * buf[2]; + buf[3] = 0.3104856 * white - 0.86650 * buf[3]; + buf[4] = 0.5329522 * white - 0.55000 * buf[4]; + buf[5] = -0.016898 * white + 0.76160 * buf[5]; + blue = buf[0] + buf[1] + buf[2] + buf[3] + buf[4] + buf[5] + buf[6] + white * 0.5362; + buf[6] = white * 0.115926; + return blue * 0.11; +} + static double brown_filter(double white, double *buf) { double brown; @@ -130,6 +148,15 @@ static double brown_filter(double white, double *buf) return brown * 3.5; } +static double violet_filter(double white, double *buf) +{ + double violet; + + violet = ((0.02 * white) - buf[0]) / 1.02; + buf[0] = violet; + return violet * 3.5; +} + static av_cold int config_props(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; @@ -144,9 +171,11 @@ static av_cold int config_props(AVFilterLink *outlink) s->duration = av_rescale(s->duration, s->sample_rate, AV_TIME_BASE); switch (s->color) { - case 0: s->filter = white_filter; break; - case 1: s->filter = pink_filter; break; - case 2: s->filter = brown_filter; break; + case 0: s->filter = white_filter; break; + case 1: s->filter = pink_filter; break; + case 2: s->filter = brown_filter; break; + case 3: s->filter = blue_filter; break; + case 4: s->filter = violet_filter; break; } return 0;
From: George Boyle <george@spotify.com> For the blue and violet noise, I took the pink and brown noise respectively and subtracted the offsets instead of adding them. When I eyeball the frequency spectrum of the resulting outputs it looks correct to me, i.e. the blue graph appears to be a mirror image of the pink, and the same can be said of the violet and the brown. I did not do anything else to confirm the correctness. --- doc/filters.texi | 4 ++-- libavfilter/asrc_anoisesrc.c | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-)