Doing mid-side stereo when not doing intensity.
authorJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Fri, 23 May 2008 07:27:39 +0000 (17:27 +1000)
committerJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Fri, 23 May 2008 07:27:39 +0000 (17:27 +1000)
libcelt/bands.c
libcelt/celt.c

index d30876e..7207c75 100644 (file)
@@ -327,21 +327,28 @@ static void stereo_band_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_t
    const int C = CHANNELS(m);
    {
       int j;
-      celt_word16_t left, right;
-      celt_word16_t a1, a2;
-      celt_word16_t norm;
-#ifdef FIXED_POINT
-      int shift = celt_zlog2(MAX32(bank[i*C], bank[i*C+1]))-13;
-#endif
-      left = VSHR32(bank[i*C],shift);
-      right = VSHR32(bank[i*C+1],shift);
-      norm = EPSILON + celt_sqrt(EPSILON+MULT16_16(left,left)+MULT16_16(right,right));
-      a1 = DIV32_16(SHL32(EXTEND32(left),14),norm);
-      a2 = dir*DIV32_16(SHL32(EXTEND32(right),14),norm);
       if (stereo_mode[i] && dir <0)
       {
          dup_band(X+C*eBands[i], eBands[i+1]-eBands[i]);
       } else {
+         celt_word16_t a1, a2;
+         if (stereo_mode[i]==0)
+         {
+            /* Do mid-side when not doing intensity stereo */
+            a1 = QCONST16(.70711f,14);
+            a2 = dir*QCONST16(.70711f,14);
+         } else {
+            celt_word16_t left, right;
+            celt_word16_t norm;
+#ifdef FIXED_POINT
+            int shift = celt_zlog2(MAX32(bank[i*C], bank[i*C+1]))-13;
+#endif
+            left = VSHR32(bank[i*C],shift);
+            right = VSHR32(bank[i*C+1],shift);
+            norm = EPSILON + celt_sqrt(EPSILON+MULT16_16(left,left)+MULT16_16(right,right));
+            a1 = DIV32_16(SHL32(EXTEND32(left),14),norm);
+            a2 = dir*DIV32_16(SHL32(EXTEND32(right),14),norm);
+         }
          for (j=eBands[i];j<eBands[i+1];j++)
          {
             celt_norm_t r, l;
index ed867dc..7f5566b 100644 (file)
@@ -322,7 +322,7 @@ int EXPORT celt_encode(CELTEncoder * restrict st, celt_int16_t * restrict pcm, u
       for (i=0;i<C*N;i++)
          P[i] = 0;
    }
-   quant_energy(st->mode, bandE, st->oldBandE, 20+nbCompressedBytes*8/5, st->mode->prob, &st->enc);
+   quant_energy(st->mode, bandE, st->oldBandE, 20*C+nbCompressedBytes*8/5, st->mode->prob, &st->enc);
 
    ALLOC(stereo_mode, st->mode->nbEBands, int);
    stereo_decision(st->mode, X, stereo_mode, st->mode->nbEBands);
@@ -584,7 +584,7 @@ int EXPORT celt_decode(CELTDecoder * restrict st, unsigned char *data, int len,
    }
 
    /* Get band energies */
-   unquant_energy(st->mode, bandE, st->oldBandE, 20+len*8/5, st->mode->prob, &dec);
+   unquant_energy(st->mode, bandE, st->oldBandE, 20*C+len*8/5, st->mode->prob, &dec);
 
    /* Pitch MDCT */
    compute_mdcts(st->mode, st->mode->window, st->out_mem+pitch_index*C, freq);