]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Fix the dither calculation -- it was 12 dB too high, really noticable on the U8 setting.
authorMike Brady <mikebrady@eircom.net>
Sun, 2 Jun 2019 16:56:47 +0000 (17:56 +0100)
committerMike Brady <mikebrady@eircom.net>
Sun, 2 Jun 2019 16:56:47 +0000 (17:56 +0100)
common.c
player.c

index 0f72f6f9d8d6598728ac025c0db1077269be0e04..9775b07efe37704327f4cf31a335d9b9012df506 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1376,12 +1376,14 @@ int64_t generate_zero_frames(char *outp, size_t number_of_frames, enum sps_forma
 
     int64_t hyper_sample = 0;
     // add a TPDF dither -- see
-    // http://www.users.qwest.net/%7Evolt42/cadenzarecording/DitherExplained.pdf
+    // http://educypedia.karadimov.info/library/DitherExplained.pdf
     // and the discussion around https://www.hydrogenaud.io/forums/index.php?showtopic=16963&st=25
 
     // I think, for a 32 --> 16 bits, the range of
     // random numbers needs to be from -2^16 to 2^16, i.e. from -65536 to 65536 inclusive, not from
     // -32768 to +32767
+    
+    // Actually, what would be generated here is from -65535 to 65535, i.e. one less on the limits.
 
     // See the original paper at
     // http://www.ece.rochester.edu/courses/ECE472/resources/Papers/Lipshitz_1992.pdf
@@ -1392,23 +1394,23 @@ int64_t generate_zero_frames(char *outp, size_t number_of_frames, enum sps_forma
     case SPS_FORMAT_S32:
     case SPS_FORMAT_S32_LE:
     case SPS_FORMAT_S32_BE:
-      dither_mask = (int64_t)1 << (64 + 1 - 32);
+      dither_mask = (int64_t)1 << (64 - 32);
       break;
     case SPS_FORMAT_S24:
     case SPS_FORMAT_S24_LE:
     case SPS_FORMAT_S24_BE:
     case SPS_FORMAT_S24_3LE:
     case SPS_FORMAT_S24_3BE:
-      dither_mask = (int64_t)1 << (64 + 1 - 24);
+      dither_mask = (int64_t)1 << (64 - 24);
       break;
     case SPS_FORMAT_S16:
     case SPS_FORMAT_S16_LE:
     case SPS_FORMAT_S16_BE:
-      dither_mask = (int64_t)1 << (64 + 1 - 16);
+      dither_mask = (int64_t)1 << (64 - 16);
       break;
     case SPS_FORMAT_S8:
     case SPS_FORMAT_U8:
-      dither_mask = (int64_t)1 << (64 + 1 - 8);
+      dither_mask = (int64_t)1 << (64 - 8);
       break;
     case SPS_FORMAT_UNKNOWN:
       die("Unexpected SPS_FORMAT_UNKNOWN while calculating dither mask.");
index 1cd88ea9aec5c98c076f5fb323912ffeb83b1326..92bda3a5cd93b33f3f8aa833152de4bfa8f0184e 100644 (file)
--- a/player.c
+++ b/player.c
@@ -650,12 +650,14 @@ static inline void process_sample(int32_t sample, char **outp, enum sps_format_t
   if (dither) {
 
     // add a TPDF dither -- see
-    // http://www.users.qwest.net/%7Evolt42/cadenzarecording/DitherExplained.pdf
+    // http://educypedia.karadimov.info/library/DitherExplained.pdf
     // and the discussion around https://www.hydrogenaud.io/forums/index.php?showtopic=16963&st=25
 
     // I think, for a 32 --> 16 bits, the range of
     // random numbers needs to be from -2^16 to 2^16, i.e. from -65536 to 65536 inclusive, not from
     // -32768 to +32767
+    
+    // Actually, what would be generated here is from -65535 to 65535, i.e. one less on the limits.
 
     // See the original paper at
     // http://www.ece.rochester.edu/courses/ECE472/resources/Papers/Lipshitz_1992.pdf
@@ -666,23 +668,23 @@ static inline void process_sample(int32_t sample, char **outp, enum sps_format_t
     case SPS_FORMAT_S32:
     case SPS_FORMAT_S32_LE:
     case SPS_FORMAT_S32_BE:
-      dither_mask = (int64_t)1 << (64 + 1 - 32);
+      dither_mask = (int64_t)1 << (64 - 32);
       break;
     case SPS_FORMAT_S24:
     case SPS_FORMAT_S24_LE:
     case SPS_FORMAT_S24_BE:
     case SPS_FORMAT_S24_3LE:
     case SPS_FORMAT_S24_3BE:
-      dither_mask = (int64_t)1 << (64 + 1 - 24);
+      dither_mask = (int64_t)1 << (64 - 24);
       break;
     case SPS_FORMAT_S16:
     case SPS_FORMAT_S16_LE:
     case SPS_FORMAT_S16_BE:
-      dither_mask = (int64_t)1 << (64 + 1 - 16);
+      dither_mask = (int64_t)1 << (64 - 16);
       break;
     case SPS_FORMAT_S8:
     case SPS_FORMAT_U8:
-      dither_mask = (int64_t)1 << (64 + 1 - 8);
+      dither_mask = (int64_t)1 << (64 - 8);
       break;
     case SPS_FORMAT_UNKNOWN:
       die("Unexpected SPS_FORMAT_UNKNOWN while calculating dither mask.");