shithub: sox

Download patch

ref: a043cf72d4c034c7a6b8bfd94e6e22588d952281
parent: 1062888a6f9f2da0d490d98e0d86555315e3042e
author: rrt <rrt>
date: Sat Nov 25 19:00:19 EST 2006

Turn #if 0'ed debug code into proper debug code.

Make verbosity_level a global, st_output_verbosity_level, for the case
where debug code needs to do extra processing.

Document the -V levels in the command-line help.

Remove dead #if 0 code. That's what CVS is for!

--- a/src/adpcm.c
+++ b/src/adpcm.c
@@ -35,7 +35,7 @@
 #include <sys/types.h>
 #include <math.h>
 #include <stdio.h>
-#include "stconfig.h"
+#include "st_i.h"
 #include "adpcm.h"
 
 typedef struct MsState {
@@ -173,8 +173,7 @@
         const SAMPL *ibuff,  /* ibuff[] is interleaved input samples */
         int n,               /* samples to encode PER channel */
         int *iostep,         /* input/output step, REQUIRE 16 <= *st <= 0x7fff */
-        unsigned char *obuff,       /* output buffer[blockAlign], or NULL for no output  */
-        int sho              /* nonzero for debug printout */
+        unsigned char *obuff /* output buffer[blockAlign], or NULL for no output  */
 )
 {
         const SAMPL *ip, *itop;
@@ -231,10 +230,9 @@
                 d2 += d*d; /* update square-error */
 
                 if (op) {   /* if we want output, put it in proper place */
-                        /* FIXME: does c<<0 work properly? */
                         op[ox>>3] |= (ox&4)? c:(c<<4);
                         ox += 4*chans;
-                        /* if (sho) fprintf(stderr,"%.1x",c); */
+                        st_debug_more("%.1x",c);
 
                 }
 
@@ -243,66 +241,13 @@
                 if (step < 16) step = 16;
 
         }
-        /* if (sho && op) fprintf(stderr,"\n");*/
+        if (op) st_debug_more("\n");
         d2 /= n; /* be sure it's non-negative */
-#ifdef DEBUG
-        if (sho) {
-                fprintf(stderr, "ch%d: st %d->%d, d %.1f\n", ch, *iostep, step, sqrt(d2));
-                fflush(stderr);
-        }
-#endif
+        st_debug_more("ch%d: st %d->%d, d %.1f\n", ch, *iostep, step, sqrt(d2));
         *iostep = step;
         return (int) sqrt(d2);
 }
 
-#if 0
-
-static long AvgDelta(int ch, int chans, const SAMPL *ibuff, int n)
-{
-        const SAMPL *ip, *itop;
-        long v0;
-        long d1;
-
-        ip = ibuff + ch;
-        itop = ip + n*chans;
-        d1 = 0;
-        v0 = *ip;
-        ip += chans;
-        for ( ; ip < itop; ip+=chans) {
-                long v1;
-
-                v1 = *ip;
-                d1 = abs(v1-v0);
-                v0 = v1;
-        }
-        return (d1/(n-1));
-}
-
-static long ReAvgDelta(int ch, int chans, const SAMPL *ibuff, int n, int step)
-{
-        const SAMPL *ip, *itop;
-        long v0;
-        long d1;
-
-        ip = ibuff + ch;
-        itop = ip + n*chans;
-        d1 = 0;
-        v0 = *ip;
-        ip += chans;
-        for ( ; ip < itop; ip+=chans) {
-                long v1, c;
-
-                v1 = *ip;
-                c = abs(v1-v0);
-                if (step && c>2*step) c=2*step;
-                d1 += c;
-                v0 = v1;
-        }
-        return (d1/(n-1));
-}
-
-#endif
-
 inline void AdpcmMashChannel(
         int ch,             /* channel number to encode, REQUIRE 0 <= ch < chans  */
         int chans,          /* total channels */
@@ -318,12 +263,6 @@
         int d,dmin,k,kmin;
 
         n0 = n/2; if (n0>32) n0=32;
-#if 0
-        s0=ReAvgDelta(ch, chans, ip, n, 0);
-        s1=ReAvgDelta(ch, chans, ip, n, s0);
-        fprintf(stderr, "ReAvg%d: %d->%d (%d)\n", ch, s0,s1,*st);
-        fflush(stderr);
-#endif
         if (*st<16) *st = 16;
         v[1] = ip[ch];
         v[0] = ip[ch+chans];
@@ -336,13 +275,13 @@
         for (k=0; k<7; k++) {
                 int d0,d1;
                 ss = s0 = *st;
-                d0=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL, 0); /* with step s0 */
+                d0=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL); /* with step s0 */
 
                 s1 = s0;
-                AdpcmMashS(ch, chans, v, iCoef[k], ip, n0, &s1, NULL, 0);
-                /* fprintf(stderr," s32 %d\n",s1); */
+                AdpcmMashS(ch, chans, v, iCoef[k], ip, n0, &s1, NULL);
+                st_debug_more(" s32 %d\n",s1);
                 ss = s1 = (3*s0+s1)/4;
-                d1=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL, 0); /* with step s1 */
+                d1=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL); /* with step s1 */
                 if (!k || d0<dmin || d1<dmin) {
                         kmin = k;
                         if (d0<=d1) {
@@ -355,12 +294,8 @@
                 }
         }
         *st = smin;
-#ifdef DEBUG
-        fprintf(stderr,"kmin %d, smin %5d, ",kmin,smin);
-        d=AdpcmMashS(ch, chans, v, iCoef[kmin], ip, n, st, obuff, 1);
-#else
-        d=AdpcmMashS(ch, chans, v, iCoef[kmin], ip, n, st, obuff, 0);
-#endif
+        st_debug_more("kmin %d, smin %5d, ",kmin,smin);
+        d=AdpcmMashS(ch, chans, v, iCoef[kmin], ip, n, st, obuff);
         obuff[ch] = kmin;
 }
 
@@ -377,8 +312,8 @@
         int ch;
         unsigned char *p;
 
-        /*fprintf(stderr,"AdpcmMashI(chans %d, ip %p, n %d, st %p, obuff %p, bA %d)\n",
-                                                                 chans, ip, n, st, obuff, blockAlign);*/
+        st_debug("AdpcmMashI(chans %d, ip %p, n %d, st %p, obuff %p, bA %d)\n",
+                                                                 chans, ip, n, st, obuff, blockAlign);
 
         for (p=obuff+7*chans; p<obuff+blockAlign; p++) *p=0;
 
@@ -417,7 +352,6 @@
                 n += m;
         }
         return n;
-        /* wSamplesPerBlock = 2*(wBlockAlign - 7*wChannels)/wChannels + 2; */
 }
 
 st_size_t AdpcmBytesPerBlock(
--- a/src/alsa.c
+++ b/src/alsa.c
@@ -44,9 +44,6 @@
     int err;
     alsa_priv_t alsa = (alsa_priv_t)ft->priv;
     snd_pcm_hw_params_t *hw_params = NULL;
-#if 0
-    snd_pcm_sw_params_t *sw_params;
-#endif
     unsigned int min_rate, max_rate;
     unsigned int min_chan, max_chan;
     unsigned int rate;
--- a/src/ima_rw.c
+++ b/src/ima_rw.c
@@ -377,67 +377,3 @@
   n = ((st_size_t)samplesPerBlock + 14)/8 * 4 * chans;
   return n;
 }
-
-#if 0
-static void ImaMashChannel(int ch, const SAMPL *ip, int n, int *st)
-{
-        int s,snext,d;
-        int s0,d0;
-        int s32,d32;
-        int sho = 0;
-        int mx[ISSTMAX+1];
-
-#if 0
-        s32=-1; d32=0x10000;
-        for (s=3; s<=ISSTMAX; s += 9) {
-                snext = s;
-                d = ImaMashS(ch, O.chans, ip[0], ip,n,&snext, NULL, sho);
-                if (d<d32) {
-                        d32=d; s32=s;
-                }
-        }
-#endif
-        s0=-1; d0=0x10000;
-        for (s=0; s<=ISSTMAX;s++) {
-                snext = s;
-                mx[s] = d = ImaMashS(ch, O.chans, ip[0], ip,n,&snext, NULL, sho);
-                /* if (s==s32) d32 = d; */
-                if (d<d0) {
-                        d0=d; s0=s;
-                }
-        }
-        s32 = *st;
-        d32 = mx[s32];
-#if 1
-        {
-                int low,hi,w;
-                int low0,hi0;
-                w = 0;
-                low=hi=s32;
-                d32 = mx[s32];
-                low0 = low-9; if (low0<0) low0=0;
-                hi0 = hi+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
-                while (low>low0 || hi<hi0) {
-                        if (!w && low>low0) {
-                                if (mx[--low]<d32) {
-                                        d32=mx[low]; s32=low;
-                                        low0 = low-9; if (low0<0) low0=0;
-                                        hi0 = low+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
-                                }
-                        }
-                        if (w && hi<hi0) {
-                                if (mx[++hi]<d32) {
-                                        d32=mx[hi]; s32=hi;
-                                        low0 = hi-9; if (low0<0) low0=0;
-                                        hi0 = hi+9; if (hi0>ISSTMAX) hi0=ISSTMAX;
-                                }
-                        }
-                        w=1-w;
-                }
-        }
-#endif
-        *st = s0;
-        d = ImaMashS(ch, O.chans, ip[0], ip,n,st, O.packet, 0);
-}
-#endif
-
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -268,14 +268,14 @@
       if (c_min>cost) {
         c_min = cost;
         u_min = u;
-#if 0
-        st_debug("c_min %d, [%d-%d]:",c_min,numer,denom);
-        for (j=0; j<u; j++)
-          st_debug(" (%d,%d)",m1[j],m2[j]);
-        st_debug("");
-#endif
-       memcpy(b1,m1,u*sizeof(int));
-       memcpy(b2,m2,u*sizeof(int));
+        if (st_output_verbosity_level >= 4) {
+          st_debug("c_min %d, [%d-%d]:",c_min,numer,denom);
+          for (j=0; j<u; j++)
+            st_debug(" (%d,%d)",m1[j],m2[j]);
+          st_debug("");
+        }
+        memcpy(b1,m1,u*sizeof(int));
+        memcpy(b2,m2,u*sizeof(int));
       }
      fail:
         ;;
--- a/src/sox.c
+++ b/src/sox.c
@@ -164,14 +164,12 @@
 static struct st_effect user_efftab[MAX_USER_EFF];
 static int nuser_effects;
 
-static int verbosity_level = 2;        /* be noisy on stderr */
 static char * myname = 0;
 
 
-
 static void sox_output_message(int level, st_output_message_t m)
 {
-  if (verbosity_level >= level)
+  if (st_output_verbosity_level >= level)
   {
     fprintf(stderr, "%s ", myname);
     st_output_message(stderr, m);
@@ -180,7 +178,6 @@
 }
 
 
-
 int main(int argc, char **argv)
 {
     file_options_t *fo;
@@ -467,9 +464,9 @@
                 str = optarg;
                 if (optarg == NULL)
                 {
-                  ++verbosity_level;
+                  ++st_output_verbosity_level;
                 }
-                else if (sscanf(str, "%i", &verbosity_level) == 0)
+                else if (sscanf(str, "%i", &st_output_verbosity_level) == 0)
                 {
                   st_fail("argument for -V must be an integer");
                   cleanup();
@@ -1250,9 +1247,7 @@
            */
           if (efftab[e].odone < efftab[e].olen)
           {
-#if 0
-              fprintf(stderr, "Breaking out of loop to flush buffer\n");
-#endif
+              st_debug("Breaking out of loop to flush buffer");
               break;
           }
       }
@@ -1375,9 +1370,7 @@
      */
     if (input_eff > 0)
     {
-#if 0
-        fprintf(stderr, "Effect return ST_EOF\n");
-#endif
+        st_debug("Effect return ST_EOF\n");
         return ST_EOF;
     }
 
@@ -1399,9 +1392,7 @@
     /* I have no input data ? */
     if (efftab[e-1].odone == efftab[e-1].olen)
     {
-#if 0
-        fprintf(stderr, "%s no data to pull to me!\n", efftab[e].name);
-#endif
+        st_debug("%s no data to pull to me!\n", efftab[e].name);
         return 0;
     }
 
@@ -1411,10 +1402,8 @@
          */
         idone = efftab[e-1].olen - efftab[e-1].odone;
         odone = ST_BUFSIZ - efftab[e].olen;
-#if 0
-        fprintf(stderr, "pre %s idone=%d, odone=%d\n", efftab[e].name, idone, odone);
-        fprintf(stderr, "pre %s odone1=%d, olen1=%d odone=%d olen=%d\n", efftab[e].name, efftab[e-1].odone, efftab[e-1].olen, efftab[e].odone, efftab[e].olen); 
-#endif
+        st_debug("pre %s idone=%d, odone=%d\n", efftab[e].name, idone, odone);
+        st_debug("pre %s odone1=%d, olen1=%d odone=%d olen=%d\n", efftab[e].name, efftab[e-1].odone, efftab[e-1].olen, efftab[e].odone, efftab[e].olen); 
 
         effstatus = (* efftab[e].h->flow)(&efftab[e],
                                           &efftab[e-1].obuf[efftab[e-1].odone],
@@ -1426,10 +1415,8 @@
         /* Leave efftab[e].odone were it was since we didn't consume data */
         /*efftab[e].odone = 0;*/
         efftab[e].olen += odone; 
-#if 0
-        fprintf(stderr, "post %s idone=%d, odone=%d\n", efftab[e].name, idone, odone); 
-        fprintf(stderr, "post %s odone1=%d, olen1=%d odone=%d olen=%d\n", efftab[e].name, efftab[e-1].odone, efftab[e-1].olen, efftab[e].odone, efftab[e].olen);
-#endif
+        st_debug("post %s idone=%d, odone=%d\n", efftab[e].name, idone, odone); 
+        st_debug("post %s odone1=%d, olen1=%d odone=%d olen=%d\n", efftab[e].name, efftab[e-1].odone, efftab[e-1].olen, efftab[e].odone, efftab[e].olen);
 
         done = idone + odone;
     } 
@@ -1450,10 +1437,8 @@
         /* left */
         idonel = (idone + 1)/2;         /* odd-length logic */
         odonel = odone/2;
-#if 0
-        fprintf(stderr, "pre %s idone=%d, odone=%d\n", efftab[e].name, idone, odone);
-        fprintf(stderr, "pre %s odone1=%d, olen1=%d odone=%d olen=%d\n", efftab[e].name, efftab[e-1].odone, efftab[e-1].olen, efftab[e].odone, efftab[e].olen); 
-#endif
+        st_debug("pre %s idone=%d, odone=%d\n", efftab[e].name, idone, odone);
+        st_debug("pre %s odone1=%d, olen1=%d odone=%d olen=%d\n", efftab[e].name, efftab[e-1].odone, efftab[e-1].olen, efftab[e].odone, efftab[e].olen); 
 
         effstatusl = (* efftab[e].h->flow)(&efftab[e],
                                           ibufl, obufl, (st_size_t *)&idonel, 
@@ -1478,10 +1463,8 @@
         /* Don't clear since nothng has been consumed yet */
         /*efftab[e].odone = 0;*/
         efftab[e].olen += odonel + odoner;
-#if 0
-        fprintf(stderr, "post %s idone=%d, odone=%d\n", efftab[e].name, idone, odone); 
-        fprintf(stderr, "post %s odone1=%d, olen1=%d odone=%d olen=%d\n", efftab[e].name, efftab[e-1].odone, efftab[e-1].olen, efftab[e].odone, efftab[e].olen);
-#endif
+        st_debug("post %s idone=%d, odone=%d\n", efftab[e].name, idone, odone); 
+        st_debug("post %s odone1=%d, olen1=%d odone=%d olen=%d\n", efftab[e].name, efftab[e-1].odone, efftab[e-1].olen, efftab[e].odone, efftab[e].olen);
 
         done = idonel + idoner + odonel + odoner;
 
@@ -1747,7 +1730,14 @@
 "-q              run in quiet mode.  Inverse of -S option\n"
 "-S              print status while processing audio data.\n"
 "--version       print version number of SoX and exit\n"
-"-V [level]      increase verbosity (or set level).\n"
+"-V [level]      increase verbosity (or set level). Default is 2. Levels are:\n"
+"\n"
+"                  1: failure messages\n"
+"                  2: warnings\n"
+"                  3: process reporting\n"
+"                  4-6: increasing levels of debug messages\n"
+"\n"
+"                each level includes messages from lower levels.\n"
 "\n"
 "Format options (fopts):\n"
 "\n"
--- a/src/st_i.h
+++ b/src/st_i.h
@@ -106,6 +106,7 @@
 typedef struct st_output_message_s * st_output_message_t;
 typedef void (* st_output_message_handler_t)(int level, st_output_message_t);
 extern st_output_message_handler_t st_output_message_handler;
+extern int st_output_verbosity_level;
 void st_output_message(FILE * file, st_output_message_t);
 
 void st_fail(const char *, ...);
--- a/src/util.c
+++ b/src/util.c
@@ -1,4 +1,12 @@
 /*
+ * util.c.
+ * Incorporate Jimen Ching's fixes for real library operation: Aug 3, 1994.
+ * Redo all work from scratch, unfortunately.
+ * Separate out all common variables used by effects & handlers,
+ * and utility routines for other main programs to use.
+ */
+
+/*
  * July 5, 1991
  * Copyright 1991 Lance Norskog And Sundry Contributors
  * This source code is freely redistributable and may be used for
@@ -17,17 +25,6 @@
 #include <varargs.h>
 #endif
 
-/*
- * util.c.
- * Incorporate Jimen Ching's fixes for real library operation: Aug 3, 1994.
- * Redo all work from scratch, unfortunately.
- * Separate out all common variables used by effects & handlers,
- * and utility routines for other main programs to use.
- */
-
-
-
-
 struct st_output_message_s
 {
   char const * filename;
@@ -35,11 +32,8 @@
   va_list      ap;
 };
 
-
-
 st_output_message_handler_t st_output_message_handler = NULL;
-
-
+int st_output_verbosity_level = 2;
 
 void st_output_message(FILE * file, st_output_message_t message)
 {