shithub: sox

Download patch

ref: 717f94fbd57743f0fd33c30b25c08d9e715423b8
parent: 9ec39dd0340dc8d26aa26e66c85d8292e178be8a
author: Ulrich Klauer <ulrich@chirlu.de>
date: Tue Dec 27 17:08:51 EST 2011

Extend "--plot=data" mode

Make complete raw filter information available for use by external
programs with --plot=data.

For FIR filters (lsx_plot_fir(), already supports --plot=data), add
the sample rate to the output.

For IIR filters (lsx_biquad_start()), introduce --plot=data and output
filter coefficients as well as sample rate.

--- a/src/biquad.c
+++ b/src/biquad.c
@@ -118,6 +118,25 @@
       , p->b0, p->b1, p->b2, p->a1, p->a2);
     return SOX_EOF;
   }
+  if (effp->global_info->plot == sox_plot_data) {
+    printf("# SoX effect: %s gain=%g frequency=%g %s=%g (rate=%g)\n"
+      "# IIR filter\n"
+      "# rate: %g\n"
+      "# name: b\n"
+      "# type: matrix\n"
+      "# rows: 3\n"
+      "# columns: 1\n"
+      "%24.16e\n%24.16e\n%24.16e\n"
+      "# name: a\n"
+      "# type: matrix\n"
+      "# rows: 3\n"
+      "# columns: 1\n"
+      "%24.16e\n%24.16e\n%24.16e\n"
+      , effp->handler.name, p->gain, p->fc, width_str[p->width_type], p->width
+      , effp->in_signal.rate, effp->in_signal.rate
+      , p->b0, p->b1, p->b2, 1. /* a0 */, p->a1, p->a2);
+    return SOX_EOF;
+  }
   return SOX_SUCCESS;
 }
 
--- a/src/effects_i_dsp.c
+++ b/src/effects_i_dsp.c
@@ -454,10 +454,12 @@
   }
   else if (type == sox_plot_data) {
     printf("# %s\n"
+        "# FIR filter\n"
+        "# rate: %g\n"
         "# name: b\n"
         "# type: matrix\n"
         "# rows: %i\n"
-        "# columns: 1\n", title, num_points);
+        "# columns: 1\n", title, rate, num_points);
     for (i = 0; i < num_points; ++i)
       printf("%24.16e\n", h[i]);
   }