Makes "stereo savings" less aggressive on mono or near-mono.
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Wed, 12 Dec 2012 20:16:27 +0000 (15:16 -0500)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Wed, 12 Dec 2012 20:30:23 +0000 (15:30 -0500)
The max reduction now depends on intensity threshold too.

celt/celt_encoder.c

index fd4a821..d9fb2a5 100644 (file)
@@ -1548,11 +1548,15 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
      {
         int coded_stereo_bands;
         int coded_stereo_dof;
      {
         int coded_stereo_bands;
         int coded_stereo_dof;
+        opus_val16 max_frac;
         coded_stereo_bands = IMIN(st->intensity, coded_bands);
         coded_stereo_dof = (eBands[coded_stereo_bands]<<LM)-coded_stereo_bands;
         coded_stereo_bands = IMIN(st->intensity, coded_bands);
         coded_stereo_dof = (eBands[coded_stereo_bands]<<LM)-coded_stereo_bands;
+        /* Maximum fraction of the bits we can save if the signal is mono. */
+        max_frac = DIV32_16(MULT16_16(QCONST16(0.8f, 15), coded_stereo_dof), coded_bins);
         /*printf("%d %d %d ", coded_stereo_dof, coded_bins, tot_boost);*/
         /*printf("%d %d %d ", coded_stereo_dof, coded_bins, tot_boost);*/
-        target -= MIN32(target/3, SHR16(MULT16_16(st->stereo_saving,(coded_stereo_dof<<BITRES)),8));
-        target += MULT16_16_Q15(QCONST16(0.035,15),coded_stereo_dof<<BITRES);
+        target -= MIN32(MULT16_32_Q15(max_frac,target),
+                        SHR16(MULT16_16(st->stereo_saving,(coded_stereo_dof<<BITRES)),8));
+        target += MULT16_16_Q15(QCONST16(0.1f,15),coded_stereo_dof<<BITRES);
      }
      /* Limits starving of other bands when using dynalloc */
      target += tot_boost;
      }
      /* Limits starving of other bands when using dynalloc */
      target += tot_boost;