Commit 3689b58a authored by Paul B Mahol's avatar Paul B Mahol

avfilter/af_biquads: display clipping warnings once per filtered frame

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent e29db08c
...@@ -94,7 +94,7 @@ typedef struct ChanCache { ...@@ -94,7 +94,7 @@ typedef struct ChanCache {
double o1, o2; double o1, o2;
} ChanCache; } ChanCache;
typedef struct { typedef struct BiquadsContext {
const AVClass *class; const AVClass *class;
enum FilterType filter_type; enum FilterType filter_type;
...@@ -110,8 +110,9 @@ typedef struct { ...@@ -110,8 +110,9 @@ typedef struct {
double b0, b1, b2; double b0, b1, b2;
ChanCache *cache; ChanCache *cache;
int clippings;
void (*filter)(AVFilterContext *ctx, const void *ibuf, void *obuf, int len, void (*filter)(struct BiquadsContext *s, const void *ibuf, void *obuf, int len,
double *i1, double *i2, double *o1, double *o2, double *i1, double *i2, double *o1, double *o2,
double b0, double b1, double b2, double a1, double a2); double b0, double b1, double b2, double a1, double a2);
} BiquadsContext; } BiquadsContext;
...@@ -165,7 +166,7 @@ static int query_formats(AVFilterContext *ctx) ...@@ -165,7 +166,7 @@ static int query_formats(AVFilterContext *ctx)
} }
#define BIQUAD_FILTER(name, type, min, max, need_clipping) \ #define BIQUAD_FILTER(name, type, min, max, need_clipping) \
static void biquad_## name (AVFilterContext *ctx, \ static void biquad_## name (BiquadsContext *s, \
const void *input, void *output, int len, \ const void *input, void *output, int len, \
double *in1, double *in2, \ double *in1, double *in2, \
double *out1, double *out2, \ double *out1, double *out2, \
...@@ -186,10 +187,10 @@ static void biquad_## name (AVFilterContext *ctx, \ ...@@ -186,10 +187,10 @@ static void biquad_## name (AVFilterContext *ctx, \
o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \ o2 = i2 * b2 + i1 * b1 + ibuf[i] * b0 + o2 * a2 + o1 * a1; \
i2 = ibuf[i]; \ i2 = ibuf[i]; \
if (need_clipping && o2 < min) { \ if (need_clipping && o2 < min) { \
av_log(ctx, AV_LOG_WARNING, "clipping\n"); \ s->clippings++; \
obuf[i] = min; \ obuf[i] = min; \
} else if (need_clipping && o2 > max) { \ } else if (need_clipping && o2 > max) { \
av_log(ctx, AV_LOG_WARNING, "clipping\n"); \ s->clippings++; \
obuf[i] = max; \ obuf[i] = max; \
} else { \ } else { \
obuf[i] = o2; \ obuf[i] = o2; \
...@@ -198,10 +199,10 @@ static void biquad_## name (AVFilterContext *ctx, \ ...@@ -198,10 +199,10 @@ static void biquad_## name (AVFilterContext *ctx, \
o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \ o1 = i1 * b2 + i2 * b1 + ibuf[i] * b0 + o1 * a2 + o2 * a1; \
i1 = ibuf[i]; \ i1 = ibuf[i]; \
if (need_clipping && o1 < min) { \ if (need_clipping && o1 < min) { \
av_log(ctx, AV_LOG_WARNING, "clipping\n"); \ s->clippings++; \
obuf[i] = min; \ obuf[i] = min; \
} else if (need_clipping && o1 > max) { \ } else if (need_clipping && o1 > max) { \
av_log(ctx, AV_LOG_WARNING, "clipping\n"); \ s->clippings++; \
obuf[i] = max; \ obuf[i] = max; \
} else { \ } else { \
obuf[i] = o1; \ obuf[i] = o1; \
...@@ -214,10 +215,10 @@ static void biquad_## name (AVFilterContext *ctx, \ ...@@ -214,10 +215,10 @@ static void biquad_## name (AVFilterContext *ctx, \
o2 = o1; \ o2 = o1; \
o1 = o0; \ o1 = o0; \
if (need_clipping && o0 < min) { \ if (need_clipping && o0 < min) { \
av_log(ctx, AV_LOG_WARNING, "clipping\n"); \ s->clippings++; \
obuf[i] = min; \ obuf[i] = min; \
} else if (need_clipping && o0 > max) { \ } else if (need_clipping && o0 > max) { \
av_log(ctx, AV_LOG_WARNING, "clipping\n"); \ s->clippings++; \
obuf[i] = max; \ obuf[i] = max; \
} else { \ } else { \
obuf[i] = o0; \ obuf[i] = o0; \
...@@ -411,12 +412,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) ...@@ -411,12 +412,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
} }
for (ch = 0; ch < av_frame_get_channels(buf); ch++) for (ch = 0; ch < av_frame_get_channels(buf); ch++)
s->filter(ctx, buf->extended_data[ch], s->filter(s, buf->extended_data[ch],
out_buf->extended_data[ch], nb_samples, out_buf->extended_data[ch], nb_samples,
&s->cache[ch].i1, &s->cache[ch].i2, &s->cache[ch].i1, &s->cache[ch].i2,
&s->cache[ch].o1, &s->cache[ch].o2, &s->cache[ch].o1, &s->cache[ch].o2,
s->b0, s->b1, s->b2, s->a1, s->a2); s->b0, s->b1, s->b2, s->a1, s->a2);
if (s->clippings > 0)
av_log(ctx, AV_LOG_WARNING, "clipping %d times. Please reduce gain.\n", s->clippings);
if (buf != out_buf) if (buf != out_buf)
av_frame_free(&buf); av_frame_free(&buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment