Re: [FFmpeg-devel] [PATCH] avfilter: add declick and declip audio filters

2018-05-17 Thread James Almer
On 5/17/2018 2:19 PM, Paul B Mahol wrote:
> +static int config_input(AVFilterLink *inlink)
> +{
> +AVFilterContext *ctx = inlink->dst;
> +DeclickContext *s = ctx->priv;
> +int i;
> +
> +s->pts = AV_NOPTS_VALUE;
> +s->window_size = inlink->sample_rate * s->w / 1000.;
> +if (s->window_size < 100)
> +return AVERROR(EINVAL);
> +s->ar_order = FFMAX(s->window_size * s->ar / 100., 1);
> +s->nb_burst_samples = s->window_size * s->burst / 1000.;
> +s->hop_size = s->window_size * (1. - (s->overlap / 100.));
> +if (s->hop_size < 1)
> +return AVERROR(EINVAL);
> +
> +s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, 
> s->window_size);
> +if (!s->fifo)
> +return AVERROR(ENOMEM);
> +
> +s->window_func_lut = av_realloc_f(s->window_func_lut, s->window_size,
> +  sizeof(*s->window_func_lut));

av_malloc_array()
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avfilter: add declick and declip audio filters

2018-05-17 Thread Moritz Barsnick
On Thu, May 17, 2018 at 19:19:06 +0200, Paul B Mahol wrote:

Valuable filters. I had compiled your previous separate patches, but
didn't have any samples for testing.

> +Setting this to very high value increases impulsive noise removal but makes 
> whole
  ^ a very high ...   ^ 
the whole ...
> +processs much slower.
   ^ process

> +This controls the strength of impulse noise which is going to be removed.
 ^ impulsive ?

> +This controls between how much samples, which are detected as impulsive 
> noise,
> +any sample between 2 detected noise samples is considered also as noise 
> sample.

This sentence makes no sense, I think you may have dropped a line?
(BTW:
 - 2 -> two
 - is considered also -> is also considered)

> +autoregressive modeling.
  ^ nit: This is the US spelling, while you use non-US
spelling for e.g. "neighbour".

> +Any sample which absolute value is equal or higher of this value will be
... "the absolute value of which is equal or higher than this", or
... "whose absolute value is equal or higher than this"

> +detected as clipped and be replaced with interpolated value.
^ an interpolated...

Cheers,
Moritz
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avfilter: add declick and declip audio filters

2018-05-17 Thread Paul B Mahol
Signed-off-by: Paul B Mahol 
---
 doc/filters.texi |  95 +++
 libavfilter/Makefile |   2 +
 libavfilter/af_declick.c | 699 +++
 libavfilter/allfilters.c |   2 +
 4 files changed, 798 insertions(+)
 create mode 100644 libavfilter/af_declick.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 7646efb918..7ba61135fd 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2576,6 +2576,101 @@ Optional. It should have a value much less than 1 (e.g. 
0.05 or 0.02) and is
 used to prevent clipping.
 @end table
 
+@section declick
+Remove impulsive noise from input audio.
+
+Samples detected as impulsive noise are replaced by interpolated samples using
+autoregressive modeling.
+
+@table @option
+@item w
+Set window size, in milliseconds. Allowed range is from @code{10} to 
@code{100}.
+Default value is @code{55} milliseconds.
+This sets size of window which will be processed at once.
+
+@item o
+Set window overlap, in percentage of window size. Allowed range is from 
@code{50}
+to @code{95}. Default value is @code{75} percent.
+Setting this to very high value increases impulsive noise removal but makes 
whole
+processs much slower.
+
+@item a
+Set autoregression order, in percentage of window size. Allowed range is from
+@code{0} to @code{25}. Default value is @code{2} percent. This option also 
controls
+quality of interpolated samples using neighbour good samples.
+
+@item t
+Set threshold value. Allowed range is from @code{1} to @code{100}.
+Default value is @code{2}.
+This controls the strength of impulse noise which is going to be removed.
+
+@item b
+Set burst fusion, in percentage of window size. Allowed range is @code{0} to
+@code{40}. Default value is @code{10} percent.
+This controls between how much samples, which are detected as impulsive noise,
+any sample between 2 detected noise samples is considered also as noise sample.
+
+@item m
+Set overlap method.
+
+It accepts the following values:
+@table @option
+@item a
+Select overlap-add method. Clicks are best removed with this method.
+Even not interpolated samples are slightly changed with this method.
+
+@item s
+Select overlap-save method. Less effective method for impulsive noise 
reduction,
+but not interpolated samples remain unchanged.
+@end table
+
+Default value is @code{a}.
+@end table
+
+@section declip
+Remove clipped samples from input audio.
+
+Samples detected as clipped are replaced by interpolated samples using
+autoregressive modeling.
+
+@table @option
+@item w
+Set window size, in milliseconds. Allowed range is from @code{10} to 
@code{100}.
+Default value is @code{55} milliseconds.
+This sets size of window which will be processed at once.
+
+@item o
+Set window overlap, in percentage of window size. Allowed range is from 
@code{50}
+to @code{95}. Default value is @code{75} percent.
+
+@item a
+Set autoregression order, in percentage of window size. Allowed range is from
+@code{0} to @code{25}. Default value is @code{8} percent. This option also 
controls
+quality of interpolated samples using neighbour good samples.
+
+@item t
+Set threshold value. Allowed range is from @code{0.2} to @code{1.0}.
+Default value is @code{0.98}.
+Any sample which absolute value is equal or higher of this value will be
+detected as clipped and be replaced with interpolated value.
+
+@item m
+Set overlap method.
+
+It accepts the following values:
+@table @option
+@item a
+Select overlap-add method. Clips are best removed with this method.
+Even not interpolated samples are slightly changed with this method.
+
+@item s
+Select overlap-save method. Less effective method for clip reduction,
+but not interpolated samples remain unchanged.
+@end table
+
+Default value is @code{a}.
+@end table
+
 @section drmeter
 Measure audio dynamic range.
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f83a2b30ee..4fa9164429 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -89,6 +89,8 @@ OBJS-$(CONFIG_COMPENSATIONDELAY_FILTER)  += 
af_compensationdelay.o
 OBJS-$(CONFIG_CROSSFEED_FILTER)  += af_crossfeed.o
 OBJS-$(CONFIG_CRYSTALIZER_FILTER)+= af_crystalizer.o
 OBJS-$(CONFIG_DCSHIFT_FILTER)+= af_dcshift.o
+OBJS-$(CONFIG_DECLICK_FILTER)+= af_declick.o
+OBJS-$(CONFIG_DECLIP_FILTER) += af_declick.o
 OBJS-$(CONFIG_DRMETER_FILTER)+= af_drmeter.o
 OBJS-$(CONFIG_DYNAUDNORM_FILTER) += af_dynaudnorm.o
 OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o
diff --git a/libavfilter/af_declick.c b/libavfilter/af_declick.c
new file mode 100644
index 00..93ca42c975
--- /dev/null
+++ b/libavfilter/af_declick.c
@@ -0,0 +1,699 @@
+/*
+ * Copyright (c) 2018 Paul B Mahol
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by