shithub: sox

Download patch

ref: 1285ab107bfb9f1ad16886e2870dffb6db647291
parent: c09ddfe6d31b84a682a993bfad23c50fe7c41faf
author: rrt <rrt>
date: Fri Jan 5 20:16:44 EST 2007

Remove ST_EFF_NULL. I've tested the various effects with this by ear,
in particular resample and polyphase to the same frequency, and all
seems fine.

--- a/src/avg.c
+++ b/src/avg.c
@@ -501,19 +501,7 @@
          return ST_EOF;
      }
 
-#if 0  /* TODO: test the following: */
-     if (effp->ininfo.channels != effp->outinfo.channels)
-       return ST_SUCCESS;
-
-     for (i = 0; i < (int)effp->ininfo.channels; ++i)
-       for (j = 0; j < (int)effp->outinfo.channels; ++j)
-         if (avg->sources[i][j] != (i == j))
-           return ST_SUCCESS;
-
-     return ST_EFF_NULL;
-#else
      return ST_SUCCESS;
-#endif
 }
 
 /*
--- a/src/dcshift.c
+++ b/src/dcshift.c
@@ -76,17 +76,13 @@
 {
     dcs_t dcs = (dcs_t) effp->priv;
 
-    if (dcs->dcshift == 0)
-      return ST_EFF_NULL;
-
-    if (effp->outinfo.channels != effp->ininfo.channels)
-    {
-        st_warn("DCSHIFT cannot handle different channels (in=%d, out=%d)"
+    if (effp->outinfo.channels != effp->ininfo.channels) {
+        st_fail("DCSHIFT cannot handle different channels (in=%d, out=%d)"
              " use avg or pan", effp->ininfo.channels, effp->outinfo.channels);
+        return ST_EOF;
     }
 
-    if (effp->outinfo.rate != effp->ininfo.rate)
-    {
+    if (effp->outinfo.rate != effp->ininfo.rate) {
         st_fail("DCSHIFT cannot handle different rates (in=%ld, out=%ld)"
              " use resample or rate", effp->ininfo.rate, effp->outinfo.rate);
         return ST_EOF;
--- a/src/equalizer.c
+++ b/src/equalizer.c
@@ -74,9 +74,6 @@
   double amp;
   double alpha;
 
-  if (eq->gain == 0)
-    return ST_EFF_NULL;
-
   /* Set the filter constants */
   w0 = 2*M_PI*eq->fc/effp->ininfo.rate;
   amp = pow( 10, eq->gain/40 );
--- a/src/fade.c
+++ b/src/fade.c
@@ -184,15 +184,11 @@
     } /* endif fade time sanity */
 
     fade->samplesdone = fade->in_start;
-
     fade->endpadwarned = 0;
 
     st_debug("fade: in_start = %d in_stop = %d out_start = %d out_stop = %d", fade->in_start, fade->in_stop, fade->out_start, fade->out_stop);
 
-    if (fade->in_start == fade->in_stop && fade->out_start == fade->out_stop)
-      return ST_EFF_NULL;
-
-    return(ST_SUCCESS);
+    return ST_SUCCESS;
 }
 
 /*
--- a/src/mask.c
+++ b/src/mask.c
@@ -1,4 +1,6 @@
 /*
+ * Sound Tools masking noise effect file.
+ *
  * July 5, 1991
  * Copyright 1991 Lance Norskog And Sundry Contributors
  * This source code is freely redistributable and may be used for
@@ -5,12 +7,9 @@
  * any purpose.  This copyright notice must be maintained. 
  * Lance Norskog And Sundry Contributors are not responsible for 
  * the consequences of using this software.
- */
-
-/*
- * Sound Tools masking noise effect file.
  *
  * TODO: does triangular noise, could do local shaping
+ *
  */
 
 #include <stdlib.h>
@@ -49,34 +48,14 @@
   return ST_SUCCESS;
 }
 
-static int st_mask_start(eff_t effp)
-{
-  mask_t mask = (mask_t) effp->priv;
-
-  if (effp->outinfo.encoding == ST_ENCODING_ULAW ||
-      effp->outinfo.encoding == ST_ENCODING_ALAW) {
-    mask->amount *= 16;
-    return ST_SUCCESS;
-  }
-  if (effp->outinfo.size == ST_SIZE_BYTE) {
-    mask->amount *= 256;
-    return ST_SUCCESS;
-  }
-  if (effp->outinfo.size == ST_SIZE_WORD)
-    return ST_SUCCESS;
-
-  return ST_EFF_NULL;   /* Dithering not needed at >= 24 bits */
-}
-
 static int st_mask_flow(eff_t effp, const st_sample_t * ibuf,
     st_sample_t * obuf, st_size_t * isamp, st_size_t * osamp)
 {
-  mask_t mask = (mask_t) effp->priv;
-  st_size_t len = *isamp > *osamp ? *osamp : *isamp;
+  mask_t mask = (mask_t)effp->priv;
+  st_size_t len = min(*isamp, *osamp);
 
   *isamp = *osamp = len;
-  while (len--)
-  {                     /* 16 signed bits of triangular noise */
+  while (len--) {             /* 16 signed bits of triangular noise */
     int tri16 = ((rand() % 32768L) + (rand() % 32768L)) - 32767;
     double l = *ibuf++ + tri16 * mask->amount;
     *obuf++ = ST_ROUND_CLIP_COUNT(l, effp->clippedCount);
@@ -89,7 +68,7 @@
   "Usage: mask [amount]",
   ST_EFF_MCHAN,
   st_mask_getopts,
-  st_mask_start,
+  st_effect_nothing,
   st_mask_flow,
   st_effect_nothing_drain,
   st_effect_nothing,
@@ -106,7 +85,7 @@
   "Usage: dither [amount]",
   ST_EFF_MCHAN,
   st_mask_getopts,
-  st_mask_start,
+  st_effect_nothing,
   st_mask_flow,
   st_effect_nothing_drain,
   st_effect_nothing,
--- a/src/pad.c
+++ b/src/pad.c
@@ -23,7 +23,7 @@
 {
   int npads;         /* Number of pads requested */
   struct {
-    char * str;      /* Command-line argument to parse for this pad */
+    char *str;       /* Command-line argument to parse for this pad */
     st_size_t start; /* Start padding when in_pos equals this */
     st_size_t pad;   /* Number of samples to pad */
   } * pads;
@@ -73,14 +73,10 @@
 static int start(eff_t effp)
 {
   pad_t p = (pad_t) effp->priv;
-  int i;
 
   parse(effp, 0, effp->ininfo.rate); /* Re-parse now rate is known */
   p->in_pos = p->pad_pos = p->pads_pos = 0;
-  for (i = 0; i < p->npads; ++i)
-    if (p->pads[i].pad)
-      return ST_SUCCESS;
-  return ST_EFF_NULL;
+  return ST_SUCCESS;
 }
 
 static int flow(eff_t effp, const st_sample_t * ibuf, st_sample_t * obuf,
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -433,9 +433,6 @@
         return ST_EOF;
     }
 
-    if (pitch->shift == 0)
-      return ST_EFF_NULL;
-
     return ST_SUCCESS;
 }
 
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -372,9 +372,6 @@
     int total, size, uprate;
     int k;
 
-    if (effp->ininfo.rate == effp->outinfo.rate)
-      return ST_EFF_NULL;
-
     rate->lcmrate = st_lcm((st_sample_t)effp->ininfo.rate,
                            (st_sample_t)effp->outinfo.rate);
 
--- a/src/resample.c
+++ b/src/resample.c
@@ -197,12 +197,9 @@
         resample_t r = (resample_t) effp->priv;
         long Xoff, gcdrate;
         int i;
-  double in_rate = floor(effp->ininfo.rate / effp->globalinfo->speed + .5)
-    * effp->globalinfo->speed;/* Make "speed" more accurate (st_rate_t is int)*/
-
-        if (effp->ininfo.rate == effp->outinfo.rate)
-          return ST_EFF_NULL;
-                
+        double in_rate = floor(effp->ininfo.rate / effp->globalinfo->speed + .5)
+          * effp->globalinfo->speed;/* Make "speed" more accurate (st_rate_t is int)*/
+
         r->Factor = (double)effp->outinfo.rate / in_rate;
 
         gcdrate = st_gcd((long)effp->ininfo.rate, (long)effp->outinfo.rate);
--- a/src/sox.c
+++ b/src/sox.c
@@ -940,14 +940,6 @@
   int effects_mask = 0;
   int status;
 
-  /* Remove any null effects: */
-  for (i = 0; i < nuser_effects; ++i)
-    if (user_efftab[i].h->flags & ST_EFF_NULL) {
-      --nuser_effects;
-      for (j = i--; j < nuser_effects; ++j)
-        user_efftab[j] = user_efftab[j + 1];
-    }
-
   needrate = (file_desc[0]->signal.rate != file_desc[file_count-1]->signal.rate);
   needchan = (file_desc[0]->signal.channels != file_desc[file_count-1]->signal.channels);
 
@@ -1106,9 +1098,7 @@
     efftab[e].clippedCount = 0;
     if ((ret = (*efftab[e].h->start)(&efftab[e])) == ST_EOF)
       break;
-    if (ret == ST_EFF_NULL)
-      st_report("`%s' has no effect in this configuration", efftab[e].name);
-    else if (efftabR[e].name) {
+    if (efftabR[e].name) {
       efftabR[e].clippedCount = 0;
       if ((ret = (*efftabR[e].h->start)(&efftabR[e])) != ST_SUCCESS)
         break;
--- a/src/st.h
+++ b/src/st.h
@@ -342,7 +342,6 @@
 #define ST_EFF_RATE     2               /* Effect can alter data rate */
 #define ST_EFF_MCHAN    4               /* Effect can handle multi-channel */
 #define ST_EFF_REPORT   8               /* Effect does not affect the audio */
-#define ST_EFF_NULL    16               /* Effect does nothing */
 
 /*
  * Handler structure for each effect.