[FFmpeg-cvslog] avfilter/af_aiir: check for stability
Paul B Mahol
git at videolan.org
Fri Nov 22 17:07:21 EET 2019
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Fri Nov 22 12:51:48 2019 +0100| [c36e72ed279b072bce325c7a11a85020c0a310fc] | committer: Paul B Mahol
avfilter/af_aiir: check for stability
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c36e72ed279b072bce325c7a11a85020c0a310fc
---
libavfilter/af_aiir.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/libavfilter/af_aiir.c b/libavfilter/af_aiir.c
index ac9558b8aa..214aefcde4 100644
--- a/libavfilter/af_aiir.c
+++ b/libavfilter/af_aiir.c
@@ -596,9 +596,9 @@ static int decompose_zp2biquads(AVFilterContext *ctx, int channels)
iir->biquads[current_biquad].a0 = 1.0;
iir->biquads[current_biquad].a1 = a[2] / a[4];
iir->biquads[current_biquad].a2 = a[0] / a[4];
- iir->biquads[current_biquad].b0 = b[4] / a[4] * (current_biquad ? 1.0 : iir->g);
- iir->biquads[current_biquad].b1 = b[2] / a[4] * (current_biquad ? 1.0 : iir->g);
- iir->biquads[current_biquad].b2 = b[0] / a[4] * (current_biquad ? 1.0 : iir->g);
+ iir->biquads[current_biquad].b0 = (b[4] / a[4]) * (current_biquad ? 1.0 : iir->g);
+ iir->biquads[current_biquad].b1 = (b[2] / a[4]) * (current_biquad ? 1.0 : iir->g);
+ iir->biquads[current_biquad].b2 = (b[0] / a[4]) * (current_biquad ? 1.0 : iir->g);
av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n",
iir->biquads[current_biquad].a0,
@@ -669,6 +669,25 @@ static void convert_pd2zp(AVFilterContext *ctx, int channels)
}
}
+static void check_stability(AVFilterContext *ctx, int channels)
+{
+ AudioIIRContext *s = ctx->priv;
+ int ch;
+
+ for (ch = 0; ch < channels; ch++) {
+ IIRChannel *iir = &s->iir[ch];
+
+ for (int n = 0; n < iir->nb_ab[0]; n++) {
+ double pr = hypot(iir->ab[0][2*n], iir->ab[0][2*n+1]);
+
+ if (pr >= 1.) {
+ av_log(ctx, AV_LOG_WARNING, "pole %d at channel %d is unstable\n", n, ch);
+ break;
+ }
+ }
+ }
+}
+
static void drawtext(AVFrame *pic, int x, int y, const char *txt, uint32_t color)
{
const uint8_t *font;
@@ -885,6 +904,9 @@ static int config_output(AVFilterLink *outlink)
} else if (s->format == 3) {
convert_pd2zp(ctx, inlink->channels);
}
+ if (s->format > 0) {
+ check_stability(ctx, inlink->channels);
+ }
av_frame_free(&s->video);
if (s->response) {
More information about the ffmpeg-cvslog
mailing list