From patchwork Wed Jul 19 05:59:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: george@spotify.com X-Patchwork-Id: 4366 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp410864vsb; Tue, 18 Jul 2017 22:59:59 -0700 (PDT) X-Received: by 10.28.217.3 with SMTP id q3mr4593330wmg.115.1500443999386; Tue, 18 Jul 2017 22:59:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500443999; cv=none; d=google.com; s=arc-20160816; b=bxgNax41+I+GHM/1QSjq85Isf5OuV9uZ+IitjsyUHwUztYRWnl21gulKbaBM1tPZtx PxUqFOJDaBUXqAwJy2gruXn8goSQidK1eRzbaJ7nf9YwNTtY4YVRvMi2NP/+zpL+8SVb cYrwOEGEO1M//4iH+4TznNDoyb5K+Bt5opJWrM9mp3WbwBlLX6Hb2jvy+h4kWnEDr0/H nYdgvC45dh4CQzT91cRZ0DQXAf36HDIg37CeQBGxLhGDpI4xEOpg5mzHy6a2I5fPMvmy CsXHiQK1ent8iSSlM8CLbIT2wCc/puP7BHRid8XwuyCoHx5UXALw7OKJ+GBFnkcQSDTN oiJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=HESJbFiV9CiUkX6qjwKqMzfXeCaQY3VjJThNWase8x0=; b=vmFgQ5NTTAKyV+DQax6bBNV0a3mMZ2xCgI3yXzMpdsN/L9n20WcanIv9KHdFwMQHCW TT1lDVJJV07tlYRz+EhOvLzGCZvsLzAkYZYzx2MYHkgXzg/dWjMLD/j3F3n0/1LgHtbW 3IUZ5xOpsFzKUJrdMbxQEW8FE1xaRFlnqSFQUATp42PC6SLkzwdCwHym7cvsTCgY15g9 OfQVtCovDnN5iL+jKJKZT3JG2nrDSgocW9lpkPjNgTY5EBo2+86OUA46JEOsM+lw/lFM iiSyDBFT+240VkI87HC4taQRmcTtEiZO2jMduZjQxNTEFBUyxENScuWPY8S5D/4/G5YP dqEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@spotify.com header.b=ST/mNE0z; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=REJECT sp=REJECT dis=QUARANTINE) header.from=spotify.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c19si3266360wrb.192.2017.07.18.22.59.58; Tue, 18 Jul 2017 22:59:59 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@spotify.com header.b=ST/mNE0z; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=REJECT sp=REJECT dis=QUARANTINE) header.from=spotify.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF667689766; Wed, 19 Jul 2017 08:59:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92BE468922C for ; Wed, 19 Jul 2017 08:59:40 +0300 (EEST) Received: by mail-lf0-f50.google.com with SMTP id t72so27571211lff.1 for ; Tue, 18 Jul 2017 22:59:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=spotify.com; s=google; h=from:to:cc:subject:date:message-id; bh=UPSJzc4eTtAmUWwpSuqA0iRpbfmoBvlQWz0aTrtJAi4=; b=ST/mNE0zXS8w1dQOwniMWFLJM6zcDB6cZli+kJZ6S4iJ0bG/VtcmkrmijRXs2YefPx cv2cpzN+p4+oU74UjcDJDhwNfF83bGVt0B5otCyQnJzb5zKM9Lk8wihA0P0PQcd9n8M5 sH4+SKhCZnrDncJidrL5ItLAK5ktauk6YQzQ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UPSJzc4eTtAmUWwpSuqA0iRpbfmoBvlQWz0aTrtJAi4=; b=rVCQ4Jcc8e7RpMEa4pbcNt1vI0PI/7yYvyAZl+qGmtkKSaoWeIpLbCO1kGu14EJg93 SCaWXrPMHBeeCzwLwkl1v6tEvLbY8ZvZcYkb37NPDl/5cB6hwb3XXaYQ+ICrzzsPAByD A0/mfvMXcfP9BrI4e89LPPdZd80CtrqYDerewp69oFzfGNC0cw7J9X8qSawkvHukw7Bp X2yVGXnjTuyBYBVY8T9UZmfuzmSipu9mqC8GVdIHwkndrvF2xZwfda26HZm9RNE3o92v nXx6O9PDpcVrV18fpPpDcl7YjHcr0pUGYKmwpPgLkuAlTtd9X1FKKYpcj+F/SEe/X7yh PHgA== X-Gm-Message-State: AIVw1136Hu9pCIWq0SmIVUJ2a4/T6No4Xe8AJ/K/1yQkCrqvNC0fqCzV TDO2DfZ3vfVP1LvxgIVEZA== X-Received: by 10.25.193.73 with SMTP id r70mr1885362lff.111.1500443987296; Tue, 18 Jul 2017 22:59:47 -0700 (PDT) Received: from porto.spotify.net ([2a01:2b0:3041:3020:6257:18ff:fe8b:872e]) by smtp.gmail.com with ESMTPSA id v13sm1074913ljd.17.2017.07.18.22.59.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 22:59:46 -0700 (PDT) From: george@spotify.com To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Jul 2017 07:59:33 +0200 Message-Id: <20170719055933.10754-1-george@spotify.com> X-Mailer: git-send-email 2.13.3 Subject: [FFmpeg-devel] [PATCH] avfilter: Add blue and violet noise generation filters X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: George Boyle MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: George Boyle 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(-) 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;