shithub: sox

Download patch

ref: eb532fc94ba39fd4a91758f08636d7db2cd4b220
parent: d5fd59203b33798ec9ee952dd827e10213bee4f1
parent: 4e023943b0086fab56bca747ece038da14c94172
author: Rob Sykes <robs@users.sourceforge.net>
date: Sun Jun 24 07:47:49 EDT 2012

Merge branch 'robs-120512'

--- a/src/biquads.c
+++ b/src/biquads.c
@@ -131,10 +131,6 @@
 
 
 static int deemph_getopts(sox_effect_t * effp, int argc, char **argv) {
-  priv_t * p = (priv_t *)effp->priv;
-  p->fc    = 5283;
-  p->width = 0.4845;
-  p->gain  = -9.477;
   return lsx_biquad_getopts(effp, argc, argv, 0, 0, 0, 1, 2, "s", filter_deemph);
 }
 
@@ -162,10 +158,29 @@
 static int start(sox_effect_t * effp)
 {
   priv_t * p = (priv_t *)effp->priv;
-  double w0 = 2 * M_PI * p->fc / effp->in_signal.rate;
-  double A  = exp(p->gain / 40 * log(10.));
-  double alpha = 0, mult = dB_to_linear(max(p->gain, 0));
+  double w0, A, alpha, mult;
 
+  if (p->filter_type == filter_deemph) { /* See deemph.plt for documentation */
+    if (effp->in_signal.rate == 44100) {
+      p->fc    = 5283;
+      p->width = 0.4845;
+      p->gain  = -9.477;
+    }
+    else if (effp->in_signal.rate == 48000) {
+      p->fc    = 5356;
+      p->width = 0.479;
+      p->gain  = -9.62;
+    }
+    else {
+      lsx_fail("sample rate must be 44100 (audio-CD) or 48000 (DAT)");
+      return SOX_EOF;
+    }
+  }
+
+  w0 = 2 * M_PI * p->fc / effp->in_signal.rate;
+  A  = exp(p->gain / 40 * log(10.));
+  alpha = 0, mult = dB_to_linear(max(p->gain, 0));
+
   if (w0 > M_PI) {
     lsx_fail("frequency must be less than half the sample-rate (Nyquist rate)");
     return SOX_EOF;
@@ -275,12 +290,7 @@
       p->a2 =        (A+1) + (A-1)*cos(w0) - 2*sqrt(A)*alpha;
       break;
 
-    case filter_deemph:  /* See deemph.plt for documentation */
-      if (effp->in_signal.rate != 44100) {
-        lsx_fail("Sample rate must be 44100 (audio-CD)");
-        return SOX_EOF;
-      }
-      /* Falls through... */
+    case filter_deemph: /* Falls through to high-shelf... */
 
     case filter_highShelf: /* H(s) = A * (A*s^2 + (sqrt(A)/Q)*s + 1)/(s^2 + (sqrt(A)/Q)*s + A) */
       if (!A)