shithub: sox

Download patch

ref: f2a1ad8804401ac047fe9e8b0b198e4bf9eb92eb
parent: e8911c72a5ce7a90674a201778f7a57f8e3cb0ea
author: robs <robs>
date: Tue Dec 26 18:25:48 EST 2006

Stop cvsd format overloading the endian options for bit reversal

--- a/ChangeLog
+++ b/ChangeLog
@@ -79,7 +79,8 @@
     with --force).  (robs)
   o Added silence padding effect.  (robs)
   o Improved multi-channel file reading; fixes [1599990].  (robs)
-  o New options for specifying endian-ness [FR# 1621702].  (robs)
+  o New options for specifying endianness (and separate option for
+    bit reversal) [FR# 1621702].  (robs)
 
 sox-12.18.2
 -----------
--- a/sox.1
+++ b/sox.1
@@ -257,11 +257,11 @@
 .br
 	octave plot.m
 .TP
-\fB\-q\fR, \fB\-\-no-show-progress\fR
+\fB\-q\fR, \fB\-\-no\-show\-progress\fR
 Run in quiet mode when SoX wouldn't otherwise do so;
 this is the converse of the \fB\-S\fR option.
 .TP
-\fB\-S\fR, \fB\-\--show-progress\fR
+\fB\-S\fR, \fB\-\-show\-progress\fR
 Display input file format/header information and input file(s)
 processing progress in terms of elapsed/remaining time and percentage.
 This option is enabled by default when using
@@ -383,6 +383,10 @@
 contains a specific endian-ness identifier, or for an output file that
 is actually an audio device.
 .TP
+\fB\-X\fR, \fB\-\-reverse\-bits\fR
+Specified that the bit ordering should be reversed; available for use
+with few formats.
+.TP
 \fB\-s\fR\^/\fB\-u\fR\^/\fB\-U\fR\^/\fB\-A\fR\^/\fB\-a\fR\^/\fB\-i\fR\^/\fB\-g\fR\^/\fB\-f\fR
 The audio data encoding is signed linear (2's complement),
 unsigned linear, u-law (logarithmic), A-law (logarithmic),
@@ -390,8 +394,8 @@
 .SP
 U-law (actually short for mu-law) and A-law are the U.S. and
 international standards for logarithmic telephone audio compression.
-When uncompressed u-law has roughly the precision of 13-bit PCM audio
-and A-law has roughly the precision of 14-bit PCM audio.
+When uncompressed u-law has roughly the precision of 14-bit PCM audio
+and A-law has roughly the precision of 13-bit PCM audio.
 .SP
 A-law and u-law data is sometimes encoded using a reversed bit-ordering
 (i.e. MSB becomes LSB).  Internally, SoX understands how to work with
@@ -514,6 +518,11 @@
 .B .cvs
 Continuously Variable Slope Delta modulation.
 Used to compress speech audio for applications such as voice mail.
+This format can use the
+.B -X
+format option to set the bit-order; if the
+.B -V
+option is given then the selected bit-order can be viewed.
 .TP
 .B .dat
 Text Data files.
@@ -773,7 +782,7 @@
 It can write all of these formats including the ADPCM encoding.
 Big endian versions of RIFF files, called RIFX, can also be read
 and written.  To write a RIFX file, use the
-.B \-x
+.B \-B
 option with the output file options.
 .TP
 .B .wve
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -452,7 +452,7 @@
         if (is_sowt)
         {
                 aiff->nsamples -= 4;
-                ft->info.swap = !ft->info.swap;
+                ft->info.swap_bytes = !ft->info.swap_bytes;
         }
         
         if (foundmark && !foundinstr)
--- a/src/alsa.c
+++ b/src/alsa.c
@@ -381,7 +381,7 @@
         }
         else
         {
-            read_buf(buf+(len*sizeof(st_sample_t)), alsa->buf, err, ft->info.swap, &ft->clippedCount);
+            read_buf(buf+(len*sizeof(st_sample_t)), alsa->buf, err, ft->info.swap_bytes, &ft->clippedCount);
             len += err * ft->info.channels;
         }
     }
@@ -486,7 +486,7 @@
       st_size_t len;
       
       osamp = min(nsamp - done, alsa->buf_size / ft->info.size);
-      write_buf(alsa->buf, buf, osamp, ft->info.swap, &ft->clippedCount);
+      write_buf(alsa->buf, buf, osamp, ft->info.swap_bytes, &ft->clippedCount);
       buf += osamp;
 
       for (len = 0; len < osamp;) {
--- a/src/au.c
+++ b/src/au.c
@@ -164,11 +164,11 @@
                  * left over from pre-standardize period of testing for
                  * endianess.  Its not hurting though.
                  */
-                ft->info.swap = !ft->info.swap;
+                ft->info.swap_bytes = !ft->info.swap_bytes;
                 st_debug("Found inverted DEC magic word.  Swapping bytes.");
         }
         else if (magic == SUN_INV_MAGIC) {
-                ft->info.swap = !ft->info.swap;
+                ft->info.swap_bytes = !ft->info.swap_bytes;
                 st_debug("Found inverted Sun/NeXT magic word. Swapping bytes.");
         }
         else if (magic == SUN_MAGIC) {
--- a/src/cvsd.c
+++ b/src/cvsd.c
@@ -120,8 +120,7 @@
         ft->info.channels = 1;
         ft->info.size = ST_SIZE_WORD; /* make output format default to words */
         ft->info.encoding = ST_ENCODING_SIGN2;
-        p->swapbits = ft->info.swap;
-        ft->info.swap = 0;
+        p->swapbits = ft->info.reverse_bits;
         /*
          * initialize the decoder
          */
--- a/src/misc.c
+++ b/src/misc.c
@@ -228,7 +228,7 @@
             st_fail_errno(ft,errno,readerr);
             return (ST_EOF);
         }
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 *uw = st_swapw(*uw);
         return ST_SUCCESS;
 }
@@ -236,7 +236,7 @@
 /* Write word. */
 int st_writew(ft_t ft, uint16_t uw)
 {
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 uw = st_swapw(uw);
         if (st_writebuf(ft, &uw, 2, 1) != 1)
         {
@@ -254,7 +254,7 @@
             st_fail_errno(ft,errno,readerr);
             return (ST_EOF);
         }
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 *u3 = st_swap24(*u3);
         return ST_SUCCESS;
 }
@@ -262,7 +262,7 @@
 /* Write three bytes. */
 int st_write3(ft_t ft, uint24_t u3)
 {
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 u3 = st_swap24(u3);
         if (st_writebuf(ft, &u3, 3, 1) != 1)
         {
@@ -280,7 +280,7 @@
             st_fail_errno(ft,errno,readerr);
             return (ST_EOF);
         }
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 *udw = st_swapdw(*udw);
         return ST_SUCCESS;
 }
@@ -288,7 +288,7 @@
 /* Write double word. */
 int st_writedw(ft_t ft, uint32_t udw)
 {
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 udw = st_swapdw(udw);
         if (st_writebuf(ft, &udw, 4, 1) != 1)
         {
@@ -306,7 +306,7 @@
             st_fail_errno(ft,errno,readerr);
             return(ST_EOF);
         }
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 *f = st_swapf(*f);
         return ST_SUCCESS;
 }
@@ -316,7 +316,7 @@
 {
         float t = f;
 
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 t = st_swapf(t);
         if (st_writebuf(ft, &t, sizeof(float), 1) != 1)
         {
@@ -334,7 +334,7 @@
             st_fail_errno(ft,errno,readerr);
             return(ST_EOF);
         }
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 *d = st_swapd(*d);
         return ST_SUCCESS;
 }
@@ -342,7 +342,7 @@
 /* Write double. */
 int st_writedf(ft_t ft, double d)
 {
-        if (ft->info.swap)
+        if (ft->info.swap_bytes)
                 d = st_swapd(d);
         if (st_writebuf(ft, &d, sizeof(double), 1) != 1)
         {
--- a/src/oss.c
+++ b/src/oss.c
@@ -132,7 +132,7 @@
     }
 
     if (samplesize == 16)
-      ft->info.swap = ST_IS_BIGENDIAN != (sampletype == AFMT_S16_BE);
+      ft->info.swap_bytes = ST_IS_BIGENDIAN != (sampletype == AFMT_S16_BE);
 
     if (ft->info.channels == 2) dsp_stereo = 1;
     else dsp_stereo = 0;
--- a/src/raw.c
+++ b/src/raw.c
@@ -24,8 +24,6 @@
 #include <stdlib.h>
 #include <errno.h>
 
-#define MAXWSPEED 1
-
 /* Lookup table to reverse the bit order of a byte. ie MSB become LSB */
 unsigned char cswap[256] = {
   0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0,
--- a/src/sf.c
+++ b/src/sf.c
@@ -39,7 +39,7 @@
         sfcodep = (SFCODE *) &sfcodes(sfhead);
         do {
                 sfcharp = (char *) sfcodep + sizeof(SFCODE);
-                if (ft->info.swap) {
+                if (ft->info.swap_bytes) {
                         sfcodep->bsize = st_swapdw(sfcodep->bsize);
                         sfcodep->code = st_swapdw(sfcodep->code);
                 }
@@ -103,7 +103,7 @@
                 return(ST_EOF);
         }
         memcpy(&sf->info, &sfhead.sfinfo, sizeof(struct sfinfo));
-        if (ft->info.swap) {
+        if (ft->info.swap_bytes) {
                 sf->info.sf_srate = st_swapf(sf->info.sf_srate);
                 sf->info.sf_packmode = st_swapdw(sf->info.sf_packmode);
                 sf->info.sf_chans = st_swapdw(sf->info.sf_chans);
--- a/src/sox.c
+++ b/src/sox.c
@@ -232,7 +232,7 @@
     fo->info.size = -1;
     fo->info.encoding = ST_ENCODING_UNKNOWN;
     fo->info.channels = 0;
-    fo->info.swap = ST_SWAP_DEFAULT;
+    fo->info.swap_bytes = ST_SWAP_DEFAULT;
     fo->info.compression = HUGE_VAL;
     fo->volume = HUGE_VAL;
     fo->volume_clips = 0;
@@ -356,7 +356,7 @@
   return result;
 }
 
-static char *getoptstr = "+r:v:t:c:C:hsuUAaig1b2w34lf8dxV::SqoenmMRLB";
+static char *getoptstr = "+r:v:t:c:C:hsuUAaig1b2w34lf8dxV::SqoenmMRLBX";
 
 static struct option long_options[] =
   {
@@ -375,6 +375,7 @@
     {"no-show-progress",       no_argument, NULL, 'q'},
     {"octave"          ,       no_argument, NULL, 'o'},
     {"rate"            , required_argument, NULL, 'r'},
+    {"reverse-bits"    ,       no_argument, NULL, 'X'},
     {"show-progress"   ,       no_argument, NULL, 'S'},
     {"type"            ,       no_argument, NULL, 't'},
     {"volume"          , required_argument, NULL, 'v'},
@@ -406,11 +407,11 @@
 
       case 2:
         if (!strcmp(optarg, "little"))
-          fo->info.swap = ST_IS_BIGENDIAN;
+          fo->info.swap_bytes = ST_IS_BIGENDIAN;
         else if (!strcmp(optarg, "big"))
-          fo->info.swap = ST_IS_LITTLEENDIAN;
+          fo->info.swap_bytes = ST_IS_LITTLEENDIAN;
         else if (!strcmp(optarg, "swap"))
-          fo->info.swap = true;
+          fo->info.swap_bytes = true;
         break;
 
       case 3:
@@ -515,15 +516,19 @@
       break;
 
     case 'L':
-      fo->info.swap = ST_IS_BIGENDIAN;
+      fo->info.swap_bytes = ST_IS_BIGENDIAN;
       break;
 
     case 'B':
-      fo->info.swap = ST_IS_LITTLEENDIAN;
+      fo->info.swap_bytes = ST_IS_LITTLEENDIAN;
       break;
 
     case 'x':
-      fo->info.swap = 1;
+      fo->info.swap_bytes = ST_SWAP_YES;
+      break;
+
+    case 'X':
+      fo->info.reverse_bits = true;
       break;
 
     case 'V':
--- a/src/sphere.c
+++ b/src/sphere.c
@@ -105,9 +105,9 @@
             {
                 sscanf(buf, "%53s %15s %127s", fldname, fldtype, fldsval);
                 if (strncmp(fldsval,"01",2) == 0)
-                  ft->info.swap = ST_IS_BIGENDIAN; /* Data is little endian. */
+                  ft->info.swap_bytes = ST_IS_BIGENDIAN; /* Data is little endian. */
                 else if (strncmp(fldsval,"10",2) == 0)
-                  ft->info.swap = ST_IS_LITTLEENDIAN; /* Data is big endian. */
+                  ft->info.swap_bytes = ST_IS_LITTLEENDIAN; /* Data is big endian. */
             }
 
             if (st_reads(ft, buf, header_size) == ST_EOF)
@@ -263,7 +263,7 @@
     st_writes(ft, buf);
 
     sprintf(buf, "sample_byte_format -s2 %s\n",
-        ft->info.swap != ST_IS_BIGENDIAN ? "10" : "01");
+        ft->info.swap_bytes != ST_IS_BIGENDIAN ? "10" : "01");
     st_writes(ft, buf);
 
     rate = ft->info.rate;
--- a/src/st.h
+++ b/src/st.h
@@ -205,7 +205,8 @@
     signed char size;     /* word length of data */
     st_encoding_t encoding; /* format of sample numbers */
     unsigned channels;    /* number of sound channels */
-    enum {ST_SWAP_NO, ST_SWAP_YES, ST_SWAP_DEFAULT} swap;  /* byte-ordering */
+    enum {ST_SWAP_NO, ST_SWAP_YES, ST_SWAP_DEFAULT} swap_bytes; /* endian */
+    bool reverse_bits;
     double compression;   /* compression factor (where applicable) */
 } st_signalinfo_t;
 
--- a/src/stio.c
+++ b/src/stio.c
@@ -27,11 +27,11 @@
 
 void set_swap_if_not_already_set(ft_t ft)
 {
-  if (ft->info.swap == ST_SWAP_DEFAULT) {
+  if (ft->info.swap_bytes == ST_SWAP_DEFAULT) {
     if (ft->h->flags & ST_FILE_ENDIAN)
-      ft->info.swap = ST_IS_LITTLEENDIAN != !(ft->h->flags & ST_FILE_ENDBIG);
+      ft->info.swap_bytes = ST_IS_LITTLEENDIAN != !(ft->h->flags & ST_FILE_ENDBIG);
     else
-      ft->info.swap = ST_SWAP_NO;
+      ft->info.swap_bytes = ST_SWAP_NO;
   }
 }
 
--- a/src/wav.c
+++ b/src/wav.c
@@ -408,7 +408,7 @@
     if (strncmp("RIFX", magic, 4) == 0) 
     {
         st_debug("Found RIFX header, swapping bytes");
-        ft->info.swap = ST_IS_LITTLEENDIAN;
+        ft->info.swap_bytes = ST_IS_LITTLEENDIAN;
     }
 
     st_readdw(ft, &dwRiffLength);
@@ -1457,7 +1457,7 @@
     /* If user specified opposite swap then we think, assume they are
      * asking to write a RIFX file.
      */
-    if (ft->info.swap != ST_IS_BIGENDIAN)
+    if (ft->info.swap_bytes != ST_IS_BIGENDIAN)
     {
         if (!second_header)
             st_report("Requested to swap bytes so writing  RIFX header");
--- a/src/wve.c
+++ b/src/wve.c
@@ -79,7 +79,7 @@
                  * testing for endianess was standardized.  Leaving since
                  * it doesn't hurt.
                  */
-                ft->info.swap = !ft->info.swap;
+                ft->info.swap_bytes = !ft->info.swap_bytes;
                 st_debug("Found inverted PSION magic word.  Swapping bytes.");
         }
         else if (version == PSION_VERSION)