History

avfilter/af_aiir: simplify polynomial evaluation

Paul B Mahol committed 6 years ago

Commit 1329db81 parent aac16ab1 file · +18 −31Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_aiir.c+18−31
@@ -385,45 +385,32 @@ static int read_channels(AVFilterContext *ctx, int channels, uint8_t *item_str, · 384 unmodified lines
385385 return 0;
386386 }
387387
388−static void multiply(double wre, double wim, int npz, double *coeffs)
388+static void cmul(double re, double im, double re2, double im2, double *RE, double *IM)
389389 {
390− double nwre = -wre, nwim = -wim;
391− double cre, cim;
392− int i;
393−
394− for (i = npz; i >= 1; i--) {
395− cre = coeffs[2 * i + 0];
396− cim = coeffs[2 * i + 1];
397−
398− coeffs[2 * i + 0] = (nwre * cre - nwim * cim) + coeffs[2 * (i - 1) + 0];
399− coeffs[2 * i + 1] = (nwre * cim + nwim * cre) + coeffs[2 * (i - 1) + 1];
400− }
401−
402− cre = coeffs[0];
403− cim = coeffs[1];
404− coeffs[0] = nwre * cre - nwim * cim;
405− coeffs[1] = nwre * cim + nwim * cre;
390+ *RE = re * re2 - im * im2;
391+ *IM = re * im2 + re2 * im;
406392 }
407393
408−static int expand(AVFilterContext *ctx, double *pz, int nb, double *coeffs)
394+static int expand(AVFilterContext *ctx, double *pz, int n, double *coefs)
409395 {
410− int i;
396+ coefs[2 * n] = 1.0;
411397
412− coeffs[0] = 1.0;
413− coeffs[1] = 0.0;
398+ for (int i = 1; i <= n; i++) {
399+ for (int j = n - i; j < n; j++) {
400+ double re, im;
414401
415− for (i = 0; i < nb; i++) {
416− coeffs[2 * (i + 1) ] = 0.0;
417− coeffs[2 * (i + 1) + 1] = 0.0;
418− }
402+ cmul(coefs[2 * (j + 1)], coefs[2 * (j + 1) + 1],
403+ pz[2 * (i - 1)], pz[2 * (i - 1) + 1], &re, &im);
419404
420− for (i = 0; i < nb; i++)
421− multiply(pz[2 * i], pz[2 * i + 1], nb, coeffs);
405+ coefs[2 * j] -= re;
406+ coefs[2 * j + 1] -= im;
407+ }
408+ }
422409
423− for (i = 0; i < nb + 1; i++) {
424− if (fabs(coeffs[2 * i + 1]) > FLT_EPSILON) {
425− av_log(ctx, AV_LOG_ERROR, "coeff: %f of z^%d is not real; poles/zeros are not complex conjugates.\n",
426− coeffs[2 * i + 1], i);
410+ for (int i = 0; i < n + 1; i++) {
411+ if (fabs(coefs[2 * i + 1]) > FLT_EPSILON) {
412+ av_log(ctx, AV_LOG_ERROR, "coefs: %f of z^%d is not real; poles/zeros are not complex conjugates.\n",
413+ coefs[2 * i + 1], i);
427414 return AVERROR(EINVAL);
428415 }
429416 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t