shithub: sox

Download patch

ref: cab8f2d403495ac493040404149a1db13debdf61
parent: 05ad2f4d4fa908edac9d56e1e6832aae0bc82398
author: idigdoug <idigdoug>
date: Mon Feb 22 01:05:03 EST 2010

Let the flac output format specify its own bit-depth instead of assuming 16 bits (avoid incorrectly dithering). Fix handling of "%n" format when width not specified.

--- a/src/flac.c
+++ b/src/flac.c
@@ -310,6 +310,7 @@
   p->decoded_samples = lsx_malloc(sox_globals.bufsiz * sizeof(FLAC__int32));
 
   p->bits_per_sample = ft->encoding.bits_per_sample;
+  ft->signal.precision = ft->encoding.bits_per_sample;
 
   lsx_report("encoding at %i bits per sample", p->bits_per_sample);
 
--- a/src/sox.c
+++ b/src/sox.c
@@ -1365,34 +1365,28 @@
          */
         if (*fn == '%')
         {
-            int width = 0;
+            char width = 0;
             fn++;
-            if (*fn >= '1' || *fn <= '9')
+            if (*fn >= '1' && *fn <= '9')
             {
                 width = *fn++;
             }
             if (*fn == 'n')
             {
-                char num[10];
                 char format[5];
 
                 found_marker = sox_true;
 
-                strcpy(format, "%");
                 if (width)
                 {
-                    char tmps[2];
-                    tmps[0] = width;
-                    tmps[1] = 0;
-                    strcat(format, "0");
-                    strcat(format, tmps);
+					sprintf(format, "%%0%cd", width);
                 }
-                strcat(format, "d");
-                strcpy(format, "%02d");
-                sprintf(num, format, count);
-                *efn = 0;
-                strcat(efn, num);
-                efn += strlen(num);
+				else
+				{
+                    strcpy(format, "%02d");
+				}
+
+                efn += sprintf(efn, format, count);
                 fn++;
             }
             else