Commit c36e72ed authored by Paul B Mahol's avatar Paul B Mahol

avfilter/af_aiir: check for stability

parent 1b78da44
...@@ -596,9 +596,9 @@ static int decompose_zp2biquads(AVFilterContext *ctx, int channels) ...@@ -596,9 +596,9 @@ static int decompose_zp2biquads(AVFilterContext *ctx, int channels)
iir->biquads[current_biquad].a0 = 1.0; iir->biquads[current_biquad].a0 = 1.0;
iir->biquads[current_biquad].a1 = a[2] / a[4]; iir->biquads[current_biquad].a1 = a[2] / a[4];
iir->biquads[current_biquad].a2 = a[0] / 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].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].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].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", av_log(ctx, AV_LOG_VERBOSE, "a=%f %f %f:b=%f %f %f\n",
iir->biquads[current_biquad].a0, iir->biquads[current_biquad].a0,
...@@ -669,6 +669,25 @@ static void convert_pd2zp(AVFilterContext *ctx, int channels) ...@@ -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) static void drawtext(AVFrame *pic, int x, int y, const char *txt, uint32_t color)
{ {
const uint8_t *font; const uint8_t *font;
...@@ -885,6 +904,9 @@ static int config_output(AVFilterLink *outlink) ...@@ -885,6 +904,9 @@ static int config_output(AVFilterLink *outlink)
} else if (s->format == 3) { } else if (s->format == 3) {
convert_pd2zp(ctx, inlink->channels); convert_pd2zp(ctx, inlink->channels);
} }
if (s->format > 0) {
check_stability(ctx, inlink->channels);
}
av_frame_free(&s->video); av_frame_free(&s->video);
if (s->response) { if (s->response) {
......
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