From 425cfd3e15c9fe88b917c2c4956769763849112a Mon Sep 17 00:00:00 2001
From: JeanMarc Valin
Date: Mon, 13 Dec 2010 16:56:35 0500
Subject: [PATCH] Fix 2phase stereo in the encoder

libcelt/bands.c  21 +++++++++++
1 file changed, 11 insertions(+), 10 deletions()
diff git a/libcelt/bands.c b/libcelt/bands.c
index 3be99a2a..88c44003 100644
 a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ 603,18 +603,18 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_
qalloc = 0;
if (stereo && i>=intensity)
qn = 1;
+ if (encode)
+ {
+ /* theta is the atan() of the ratio between the (normalized)
+ side and mid. With just that parameter, we can rescale both
+ mid and side because we know that 1) they have unit norm and
+ 2) they are orthogonal. */
+ itheta = stereo_itheta(X, Y, stereo, N);
+ }
if (qn!=1)
{
if (encode)
 {
 /* theta is the atan() of the ratio between the (normalized)
 side and mid. With just that parameter, we can rescale both
 mid and side because we know that 1) they have unit norm and
 2) they are orthogonal. */
 itheta = stereo_itheta(X, Y, stereo, N);

itheta = (itheta*qn+8192)>>14;
 }
/* Entropy coding of the angle. We use a uniform pdf for the
first stereo split but a triangular one for the rest. */
@@ 677,15 +677,16 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_
}
intensity_stereo(m, X, Y, bandE, i, N);
}
 if (b>2<2< 2<