From c5d00a066ea782c2c32eb3ff3e15f87d23b82c60 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Wed, 26 May 2010 11:27:32 -0400 Subject: [PATCH] Bunch of fixes for frames of 2.5 ms. --- libcelt/bands.c | 90 +++++++++++++++++++++++++++++++------------------ libcelt/modes.c | 2 +- libcelt/rate.c | 2 ++ 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 49f92626..7faa7fff 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -490,6 +490,33 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ split = stereo = Y != NULL; + /* Special case for one sample */ + if (N==1) + { + if (b>=1<=1< 1 && level == 0 && tf_change>0) { while (spread>1 && tf_change>0) @@ -507,6 +534,7 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ N_B0 = N_B; } + /* Increasing the time resolution */ if (!stereo && spread>1 && level==0) { while ((N_B&1) == 0 && tf_change<0 && spread <= (1< 32< 32<2) { if (LM>0 || (N&1)==0) { @@ -547,52 +575,50 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ if (split) { int qb; - int itheta; + int itheta=0; int mbits, sbits, delta; int qalloc; celt_word16 mid, side; - if (N>1) - { - qb = (b-2*(N-1)*(QTHETA_OFFSET-m->logN[i]-(LM< (b>>(BITRES+1))-1) - qb = (b>>(BITRES+1))-1; - } else { - /* For N==1, allocate two bits for the signs and the rest goes to qb */ - qb = b-(2<logN[i]+(LM<2) + N2--; + qb = (b+N2*offset)/(N2< (b>>(BITRES+1))-1) + qb = (b>>(BITRES+1))-1; + if (qb<0) qb = 0; if (qb>14) qb = 14; - if (encode) - { - if (stereo) - stereo_band_mix(m, X, Y, bandE, qb==0, i, 1, N); - - mid = renormalise_vector(X, Q15ONE, N, 1); - side = renormalise_vector(Y, Q15ONE, N, 1); - - /* 0.63662 = 2/pi */ -#ifdef FIXED_POINT - itheta = MULT16_16_Q15(QCONST16(0.63662f,15),celt_atan2p(side, mid)); -#else - itheta = floor(.5f+16384*0.63662f*atan2(side,mid)); -#endif - } - qalloc = 0; - if (qb==0) + if (qb!=0) { - itheta=0; - } else { int shift; shift = 14-qb; + if (encode) + { + if (stereo) + stereo_band_mix(m, X, Y, bandE, qb==0, i, 1, N); + + mid = renormalise_vector(X, Q15ONE, N, 1); + side = renormalise_vector(Y, Q15ONE, N, 1); + + /* 0.63662 = 2/pi */ + #ifdef FIXED_POINT + itheta = MULT16_16_Q15(QCONST16(0.63662f,15),celt_atan2p(side, mid)); + #else + itheta = floor(.5f+16384*0.63662f*atan2(side,mid)); + #endif + + itheta = (itheta+(1<>1))>>shift; + } + /* Entropy coding of the angle. We use a uniform pdf for the first stereo split but a triangular one for the rest. */ - if (encode) - itheta = (itheta+(1<>1))>>shift; if (stereo || qb>9 || spread>1) { if (encode) diff --git a/libcelt/modes.c b/libcelt/modes.c index b7f9b010..c205db4f 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -339,7 +339,7 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) } else if (frame_size >= 320 && (frame_size%8)==0) { mode->nbShortMdcts = 4; - } else if (frame_size >= 120 && (frame_size%4)==0) + } else if (frame_size >= 160 && (frame_size%4)==0) { mode->nbShortMdcts = 2; } else diff --git a/libcelt/rate.c b/libcelt/rate.c index 08be39be..9456b237 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -171,6 +171,8 @@ static inline void interp_bits2pulses(const CELTMode *m, int start, int *bits1, ebits[j] = (2*offset+d)/(2*d); fine_priority[j] = ebits[j]*d >= offset; + if (N==1) + ebits[j] = (bits[j]/C >> BITRES)-1; /* Make sure not to bust */ if (C*ebits[j] > (bits[j]>>BITRES)) ebits[j] = bits[j]/C >> BITRES;