From 9b34bd835ca4e6c7597873cbb4e1ff47f7b9f0c3 Mon Sep 17 00:00:00 2001 From: "Timothy B. Terriberry" Date: Fri, 28 Jan 2011 22:20:59 -0800 Subject: [PATCH] Change qb cap to prevent side-fold collapses. Previously, in a stereo split with itheta==16384, but without enough bits left over to actually code a pulse, the target band would completely collapse, because the mid gain would be zero and we don't fold the side. This changes the limit to ensure that we never set qn>1 unless we know we'll have enough bits for at least one pulse. This should eliminate the last possible whole-band collapse. --- libcelt/bands.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 97daef94..92caee49 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -594,7 +594,7 @@ void haar1(celt_norm *X, int N0, int stride) } } -static int compute_qn(int N, int b, int offset, int stereo) +static int compute_qn(int N, int b, int offset, int pulse_cap, int stereo) { static const celt_int16 exp2_table8[8] = {16384, 17866, 19483, 21247, 23170, 25267, 27554, 30048}; @@ -602,9 +602,12 @@ static int compute_qn(int N, int b, int offset, int stereo) int N2 = 2*N-1; if (stereo && N==2) N2--; - qb = IMIN((b>>1)-(1<>1)) { qn = 1; @@ -748,13 +751,15 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c int itheta=0; int mbits, sbits, delta; int qalloc; + int pulse_cap; int offset; int orig_fill; celt_int32 tell; /* Decide on the resolution to give to the split parameter theta */ - offset = ((m->logN[i]+(LM<>1) - (stereo ? QTHETA_OFFSET_STEREO : QTHETA_OFFSET); - qn = compute_qn(N, b, offset, stereo); + pulse_cap = m->logN[i]+(LM<>1) - (stereo ? QTHETA_OFFSET_STEREO : QTHETA_OFFSET); + qn = compute_qn(N, b, offset, pulse_cap, stereo); if (stereo && i>=intensity) qn = 1; if (encode)