shithub: sox

Download patch

ref: 6887a7c79ade167e0681d078c90edb25a4bb9d4f
parent: 8b3ab9b0f12e8e2e3321fe49e8269c5f61ed7a9c
author: robs <robs>
date: Sat Apr 21 15:30:52 EDT 2007

Fix for reading reversed-bit file types

--- a/src/adpcms.c
+++ b/src/adpcms.c
@@ -128,7 +128,7 @@
 
   sox_adpcm_reset(state, type);
   
-  return sox_rawstart(ft, sox_true, sox_false, type, SOX_SIZE_16BIT, SOX_OPTION_DEFAULT);
+  return sox_rawstart(ft, sox_true, sox_false, type, SOX_SIZE_16BIT);
 }
 
 int sox_adpcm_oki_start(ft_t ft, adpcm_io_t state)
--- a/src/raw.c
+++ b/src/raw.c
@@ -55,7 +55,7 @@
 
 /* Works nicely for starting read and write; sox_rawstart{read,write}
    are #defined in sox_i.h */
-int sox_rawstart(ft_t ft, sox_bool default_rate, sox_bool default_channels, sox_encoding_t encoding, int size, sox_option_t rev_bits)
+int sox_rawstart(ft_t ft, sox_bool default_rate, sox_bool default_channels, sox_encoding_t encoding, int size)
 {
   if (default_rate && ft->signal.rate == 0) {
     sox_warn("'%s': sample rate not specified; trying 8kHz", ft->filename);
@@ -82,14 +82,6 @@
     else ft->signal.size = size;
   }
 
-  if (rev_bits != SOX_OPTION_DEFAULT) {
-    if (ft->mode == 'r' &&
-        ft->signal.reverse_bits != SOX_OPTION_DEFAULT &&
-        ft->signal.reverse_bits != rev_bits)
-      sox_report("'%s': Format options overriding file-type bit-order", ft->filename);
-    else ft->signal.reverse_bits = rev_bits;
-  }
-
   return SOX_SUCCESS;
 }
 
@@ -243,7 +235,7 @@
 }
 
 static int raw_start(ft_t ft) {
-  return sox_rawstart(ft,sox_false,sox_false,SOX_ENCODING_UNKNOWN,-1,SOX_OPTION_DEFAULT);
+  return sox_rawstart(ft,sox_false,sox_false,SOX_ENCODING_UNKNOWN,-1);
 }
 sox_format_t const * sox_raw_format_fn(void) {
   static char const * names[] = {"raw", NULL};
@@ -256,14 +248,14 @@
   return &driver;
 }
 
-#define RAW_FORMAT(id,alt1,alt2,size,rev_bits,encoding) \
+#define RAW_FORMAT(id,alt1,alt2,size,flags,encoding) \
 static int id##_start(ft_t ft) { \
-  return sox_rawstart(ft,sox_true,sox_true,SOX_ENCODING_##encoding,SOX_SIZE_##size,SOX_OPTION_##rev_bits); \
+  return sox_rawstart(ft,sox_true,sox_true,SOX_ENCODING_##encoding,SOX_SIZE_##size); \
 } \
 sox_format_t const * sox_##id##_format_fn(void) { \
   static char const * names[] = {#id, alt1, alt2, NULL}; \
   static sox_format_t driver = { \
-    names, 0, \
+    names, flags, \
     id##_start, sox_rawread , sox_format_nothing, \
     id##_start, sox_rawwrite, sox_format_nothing, \
     sox_format_nothing_seek \
@@ -271,17 +263,17 @@
   return &driver; \
 }
 
-RAW_FORMAT(sb,NULL ,NULL  ,BYTE , DEFAULT,SIGN2)
-RAW_FORMAT(sl,NULL ,NULL  ,32BIT, DEFAULT,SIGN2)
-RAW_FORMAT(s3,NULL ,NULL  ,24BIT, DEFAULT,SIGN2)
-RAW_FORMAT(sw,NULL ,NULL  ,16BIT, DEFAULT,SIGN2)
+RAW_FORMAT(sb,NULL ,NULL  ,BYTE , 0,SIGN2)
+RAW_FORMAT(sl,NULL ,NULL  ,32BIT, 0,SIGN2)
+RAW_FORMAT(s3,NULL ,NULL  ,24BIT, 0,SIGN2)
+RAW_FORMAT(sw,NULL ,NULL  ,16BIT, 0,SIGN2)
                    
-RAW_FORMAT(ub,"sou","fssd",BYTE , DEFAULT,UNSIGNED)
-RAW_FORMAT(uw,NULL ,NULL  ,16BIT, DEFAULT,UNSIGNED)
-RAW_FORMAT(u3,NULL ,NULL  ,24BIT, DEFAULT,UNSIGNED)
-RAW_FORMAT(u4,NULL ,NULL  ,32BIT, DEFAULT,UNSIGNED)
+RAW_FORMAT(ub,"sou","fssd",BYTE , 0,UNSIGNED)
+RAW_FORMAT(uw,NULL ,NULL  ,16BIT, 0,UNSIGNED)
+RAW_FORMAT(u3,NULL ,NULL  ,24BIT, 0,UNSIGNED)
+RAW_FORMAT(u4,NULL ,NULL  ,32BIT, 0,UNSIGNED)
                    
-RAW_FORMAT(al,NULL ,NULL  ,BYTE ,NO     ,ALAW)
-RAW_FORMAT(ul,NULL ,NULL  ,BYTE ,NO     ,ULAW)
-RAW_FORMAT(la,NULL ,NULL  ,BYTE ,YES    ,ALAW)
-RAW_FORMAT(lu,NULL ,NULL  ,BYTE ,YES    ,ULAW)
+RAW_FORMAT(al,NULL ,NULL  ,BYTE ,0     ,ALAW)
+RAW_FORMAT(ul,NULL ,NULL  ,BYTE ,0     ,ULAW)
+RAW_FORMAT(la,NULL ,NULL  ,BYTE ,SOX_FILE_BIT_REV    ,ALAW)
+RAW_FORMAT(lu,NULL ,NULL  ,BYTE ,SOX_FILE_BIT_REV    ,ULAW)
--- a/src/sox.h
+++ b/src/sox.h
@@ -329,6 +329,8 @@
 /* These two for use by libSoX drivers: */
 #define SOX_FILE_LIT_END  (0   + 64)
 #define SOX_FILE_BIG_END  (128 + 64)
+#define SOX_FILE_BIT_REV 256
+#define SOX_FILE_NIB_REV 512
 
 /* Size field */
 #define SOX_SIZE_BYTE    1
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -317,8 +317,8 @@
 int sox_effect_nothing_drain(eff_t effp, sox_ssample_t *obuf, sox_size_t *osamp);
 int sox_effect_nothing_getopts(eff_t effp, int n, char **argv UNUSED);
 
-int sox_rawstart(ft_t ft, sox_bool default_rate, sox_bool default_channels, sox_encoding_t encoding, int size, sox_option_t rev_bits);
-#define sox_rawstartread(ft) sox_rawstart(ft, sox_false, sox_false, SOX_ENCODING_UNKNOWN, -1, SOX_OPTION_DEFAULT)
+int sox_rawstart(ft_t ft, sox_bool default_rate, sox_bool default_channels, sox_encoding_t encoding, int size);
+#define sox_rawstartread(ft) sox_rawstart(ft, sox_false, sox_false, SOX_ENCODING_UNKNOWN, -1)
 #define sox_rawstartwrite sox_rawstartread
 #define sox_rawstopread sox_format_nothing
 #define sox_rawstopwrite sox_format_nothing
--- a/src/soxio.c
+++ b/src/soxio.c
@@ -36,10 +36,15 @@
     else
       ft->signal.reverse_bytes = SOX_OPTION_NO;
   }
-  if (ft->signal.reverse_nibbles == SOX_OPTION_DEFAULT)
-    ft->signal.reverse_nibbles = SOX_OPTION_NO;
   if (ft->signal.reverse_bits == SOX_OPTION_DEFAULT)
-    ft->signal.reverse_bits = SOX_OPTION_NO;
+    ft->signal.reverse_bits = !!(ft->h->flags & SOX_FILE_BIT_REV);
+  else if (ft->signal.reverse_bits != !!(ft->h->flags & SOX_FILE_BIT_REV))
+      sox_report("'%s': Format options overriding file-type bit-order", ft->filename);
+
+  if (ft->signal.reverse_nibbles == SOX_OPTION_DEFAULT)
+    ft->signal.reverse_nibbles = !!(ft->h->flags & SOX_FILE_NIB_REV);
+  else if (ft->signal.reverse_nibbles != !!(ft->h->flags & SOX_FILE_NIB_REV))
+      sox_report("'%s': Format options overriding file-type nibble-order", ft->filename);
 }
 
 static int is_seekable(ft_t ft)
@@ -148,7 +153,7 @@
         goto input_error;
     }
 
-    /* Go a head and assume 1 channel audio if nothing is detected.
+    /* Go ahead and assume 1 channel audio if nothing is detected.
      * This is because libsox usually doesn't set this for mono file
      * formats (for historical reasons).
      */