ref: fa7215fdb9f8fdbd8498da39b3cc27c14ac888ca
parent: 509ad2086d15cac2488a674bb1f5fc5e648638a3
author: Jean-Marc Valin <[email protected]>
date: Wed Dec 29 10:19:58 EST 2010
Fixing stereo renormalisation Compensate for the fact that the side "energy" is not preserved when the split ends up starving one segment.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -232,10 +232,10 @@
}
}
-static void stereo_merge(celt_norm *X, celt_norm *Y, celt_word16 mid, celt_word16 side, int N)
+static void stereo_merge(celt_norm *X, celt_norm *Y, celt_word16 mid, int N)
{
int j;
- celt_word32 xp=0;
+ celt_word32 xp=0, side=0;
celt_word32 El, Er;
#ifdef FIXED_POINT
int kl, kr;
@@ -244,12 +244,15 @@
/* Compute the norm of X+Y and X-Y as |X|^2 + |Y|^2 +/- sum(xy) */
for (j=0;j<N;j++)
+ {
xp = MAC16_16(xp, X[j], Y[j]);
+ side = MAC16_16(side, Y[j], Y[j]);
+ }
/* mid and side are in Q15, not Q14 like X and Y */
mid = SHR32(mid, 1);
- side = SHR32(side, 1);
- El = MULT16_16(mid, mid) + MULT16_16(side, side) - 2*xp;
- Er = MULT16_16(mid, mid) + MULT16_16(side, side) + 2*xp;
+ //side = SHR32(side, 1);
+ El = MULT16_16(mid, mid) + side - 2*xp;
+ Er = MULT16_16(mid, mid) + side + 2*xp;
if (Er < EPSILON)
Er = EPSILON;
if (El < EPSILON)
@@ -889,7 +892,7 @@
if (stereo)
{
if (N!=2)
- stereo_merge(X, Y, mid, side, N);
+ stereo_merge(X, Y, mid, N);
if (inv)
{
int j;