Adding a tiny amount of noise when folding to prevent/reduce numerical issues
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Thu, 10 Feb 2011 15:50:26 +0000 (10:50 -0500)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Thu, 10 Feb 2011 15:50:26 +0000 (10:50 -0500)
libcelt/bands.c

index e7997f9..1c8fe25 100644 (file)
@@ -1084,7 +1084,14 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
                } else {
                   /* Folded spectrum */
                   for (j=0;j<N;j++)
                } else {
                   /* Folded spectrum */
                   for (j=0;j<N;j++)
-                     X[j] = lowband[j];
+                  {
+                     celt_word16 tmp;
+                     *seed = lcg_rand(*seed);
+                     /* About 48 dB below the "normal" folding level */
+                     tmp = QCONST16(1.0f/256, 10);
+                     tmp = (*seed)&0x8000 ? tmp : -tmp;
+                     X[j] = lowband[j]+tmp;
+                  }
                   cm = fill;
                }
                renormalise_vector(X, N, gain);
                   cm = fill;
                }
                renormalise_vector(X, N, gain);