shithub: sox

Download patch

ref: ba9146d9ffac0d8eaada41bbc9839279c994a4d0
parent: 892e60436b7b9d2014d4aa8dc583bc6331c41ad8
author: robs <robs>
date: Fri Sep 26 07:02:25 EDT 2008

add gnuplot support to filter effect

--- a/sox.1
+++ b/sox.1
@@ -1513,7 +1513,7 @@
 need to use the beta parameter at all, unless you are just curious
 about comparing the effects of Blackman-Nuttall vs. Kaiser windows.
 .SP
-This effect supports the \fB\-\-plot octave\fR global option.
+This effect supports the \fB\-\-plot\fR global option.
 .TP
 \fBflanger\fR [\fIdelay depth regen width speed shape phase interp\fR]
 Apply a flanging effect to the audio.
--- a/src/filter.c
+++ b/src/filter.c
@@ -199,6 +199,13 @@
         return (SOX_SUCCESS);
 }
 
+static int p2(int n)
+{
+  int N;
+  for (N = 1; n; n >>= 1, N <<= 1);
+  return max(N, 1024);
+}
+
 /*
  * Prepare processing.
  */
@@ -268,6 +275,34 @@
         f->Nwin = 2*Xh + 1;  /* not really used afterwards */
         f->Xh = Xh;
         f->Xt = Xh;
+
+   if (effp->global_info->plot == sox_plot_gnuplot) {
+     int N = p2(2 * Xh + 1);
+     double * h = lsx_calloc(N, sizeof(*h));
+     double * H = lsx_malloc((N / 2 + 1) * sizeof(*H));
+     for (i = 1; i < Xh + 1; ++i)
+       h[i - 1] = f->Fp[Xh + 1 - i];
+     for (i = 0; i < Xh + 1; ++i)
+       h[Xh + i] = f->Fp[i];
+     lsx_power_spectrum(N, h, H);
+     free(h);
+     printf(
+       "# gnuplot file\n"
+       "set title 'SoX effect: filter frequency=%g-%g'\n"
+       "set xlabel 'Frequency (Hz)'\n"
+       "set ylabel 'Amplitude Response (dB)'\n"
+       "set grid xtics ytics\n"
+       "set key off\n"
+       "plot '-' with lines\n"
+       , f->freq0, f->freq1);
+     for (i = 0; i <= N/2; ++i)
+       printf("%g %g\n", i * effp->in_signal.rate / N, 10 * log10(H[i]));
+     printf(
+       "e\n"
+       "pause -1 'Hit return to continue'\n");
+     free(H);
+     return SOX_EOF;
+   }
 
    if (effp->global_info->plot == sox_plot_octave) {
      printf("%% GNU Octave file (may also work with MATLAB(R) )\nb=[");