From d5e5436e075312bd3f281fc6556c4e1767c22ced Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Wed, 30 Sep 2009 20:50:41 -0400 Subject: [PATCH] Fix for folding_decision() in stereo mode and more cleaning up of the code now that we no longer do normalized pitch --- libcelt/bands.c | 69 ++++++++++++++++++++----------------------------- libcelt/bands.h | 8 +++--- libcelt/celt.c | 15 +++-------- libcelt/modes.c | 4 +-- libcelt/vq.c | 25 ++++++++---------- libcelt/vq.h | 2 +- 6 files changed, 50 insertions(+), 73 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 916f35e4..5314b0c5 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -377,23 +377,26 @@ void deinterleave(celt_norm_t *x, int N) int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, int *last_decision) { - int i; + int i, c; int NR=0; celt_word32_t ratio = EPSILON; + const int C = CHANNELS(m); const celt_int16_t * restrict eBands = m->eBands; + for (c=0;cnbEBands;i++) { int j, N; int max_i=0; celt_word16_t max_val=EPSILON; celt_word32_t floor_ener=EPSILON; - celt_norm_t * restrict x = X+eBands[i]; + celt_norm_t * restrict x = X+C*eBands[i]+c; N = eBands[i+1]-eBands[i]; for (j=0;jmax_val) + if (ABS16(x[C*j])>max_val) { - max_val = ABS16(x[j]); + max_val = ABS16(x[C*j]); max_i = j; } } @@ -406,13 +409,13 @@ int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, #else floor_ener = QCONST32(1.,28)-MULT16_16(max_val,max_val); if (max_i < N-1) - floor_ener -= MULT16_16(x[max_i+1], x[max_i+1]); + floor_ener -= MULT16_16(x[C*(max_i+1)], x[C*(max_i+1)]); if (max_i < N-2) - floor_ener -= MULT16_16(x[max_i+2], x[max_i+2]); + floor_ener -= MULT16_16(x[C*(max_i+2)], x[C*(max_i+2)]); if (max_i > 0) - floor_ener -= MULT16_16(x[max_i-1], x[max_i-1]); + floor_ener -= MULT16_16(x[C*(max_i-1)], x[C*(max_i-1)]); if (max_i > 1) - floor_ener -= MULT16_16(x[max_i-2], x[max_i-2]); + floor_ener -= MULT16_16(x[C*(max_i-2)], x[C*(max_i-2)]); floor_ener = MAX32(floor_ener, EPSILON); #endif if (N>7) @@ -425,6 +428,7 @@ int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, NR++; } } + } if (NR>0) ratio = DIV32_16(ratio, NR); ratio = ADD32(HALF32(ratio), HALF32(*average)); @@ -439,7 +443,7 @@ int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, } /* Quantisation of the residual */ -void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc) +void quant_bands(const CELTMode *m, celt_norm_t * restrict X, const celt_ener_t *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc) { int i, j, remaining_bits, balance; const celt_int16_t * restrict eBands = m->eBands; @@ -493,7 +497,7 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, co int spread = fold ? B : 0; alg_quant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc); } else { - intra_fold(m, X+eBands[i], eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B); + intra_fold(m, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B); } for (j=eBands[i];jeBands; @@ -515,7 +519,7 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t SAVE_STACK; B = shortBlocks ? m->nbShortMdcts : 1; - ALLOC(_norm, C*eBands[m->nbEBands+1], celt_norm_t); + ALLOC(_norm, eBands[m->nbEBands+1], celt_norm_t); norm = _norm; balance = 0; @@ -680,19 +684,13 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t remaining_bits -= curr_bits; } - /* If pitch isn't available, use intra-frame prediction */ - if (q1==0) - { - intra_fold(m, X+C*eBands[i], eBands[i+1]-eBands[i], norm, P+C*eBands[i], eBands[i], B); - deinterleave(P+C*eBands[i], C*N); - } deinterleave(X+C*eBands[i], C*N); if (q1 > 0) { int spread = fold ? B : 0; alg_quant(X+C*eBands[i], N, q1, spread, enc); - } else - for (j=C*eBands[i];j 0) { int spread = fold ? B : 0; alg_quant(X+C*eBands[i]+N, N, q2, spread, enc); @@ -710,9 +708,8 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t mid = (1./32768)*imid; side = (1./32768)*iside; #endif - for (c=0;ceBands; @@ -785,7 +782,7 @@ void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, int spread = fold ? B : 0; alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, dec); } else { - intra_fold(m, X+eBands[i], eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B); + intra_fold(m, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B); } for (j=eBands[i];jeBands; @@ -807,7 +804,7 @@ void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm SAVE_STACK; B = shortBlocks ? m->nbShortMdcts : 1; - ALLOC(_norm, C*eBands[m->nbEBands+1], celt_norm_t); + ALLOC(_norm, eBands[m->nbEBands+1], celt_norm_t); norm = _norm; balance = 0; @@ -953,23 +950,14 @@ void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm } remaining_bits -= curr_bits; } - - - /* If pitch isn't available, use intra-frame prediction */ - if (q1==0) - { - intra_fold(m, X+C*eBands[i], eBands[i+1]-eBands[i], norm, P+C*eBands[i], eBands[i], B); - deinterleave(P+C*eBands[i], C*N); - } deinterleave(X+C*eBands[i], C*N); if (q1 > 0) { int spread = fold ? B : 0; alg_unquant(X+C*eBands[i], N, q1, spread, dec); } else - for (j=C*eBands[i];j 0) { int spread = fold ? B : 0; @@ -988,9 +976,8 @@ void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm mid = (1./32768)*imid; side = (1./32768)*iside; #endif - for (c=0;cmode, X, P, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc); + quant_bands(st->mode, X, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc); #ifndef DISABLE_STEREO else - quant_bands_stereo(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc); + quant_bands_stereo(st->mode, X, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc); #endif quant_energy_finalise(st->mode, bandE, st->oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(&enc, 0), &enc); @@ -1205,7 +1200,6 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int VARDECL(celt_sig_t, freq); VARDECL(celt_sig_t, pitch_freq); VARDECL(celt_norm_t, X); - VARDECL(celt_norm_t, P); VARDECL(celt_ener_t, bandE); VARDECL(int, fine_quant); VARDECL(int, pulses); @@ -1236,7 +1230,6 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int ALLOC(freq, C*N, celt_sig_t); /**< Interleaved signal MDCTs */ ALLOC(X, C*N, celt_norm_t); /**< Interleaved normalised MDCTs */ - ALLOC(P, C*N, celt_norm_t); /**< Interleaved normalised pitch MDCTs*/ ALLOC(bandE, st->mode->nbEBands*C, celt_ener_t); if (data == NULL) @@ -1309,10 +1302,10 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int /* Decode fixed codebook and merge with pitch */ if (C==1) - unquant_bands(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, len*8, &dec); + unquant_bands(st->mode, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec); #ifndef DISABLE_STEREO else - unquant_bands_stereo(st->mode, X, P, bandE, pulses, shortBlocks, has_fold, len*8, &dec); + unquant_bands_stereo(st->mode, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec); #endif unquant_energy_finalise(st->mode, bandE, st->oldBandE, fine_quant, fine_priority, len*8-ec_dec_tell(&dec, 0), &dec); diff --git a/libcelt/modes.c b/libcelt/modes.c index 5fa893e0..4bc7d66f 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -124,8 +124,8 @@ static celt_int16_t *compute_ebands(celt_int32_t Fs, int frame_size, int nbShort celt_int16_t *eBands; int i, res, min_width, lin, low, high, nBark; - //if (min_bins < nbShortMdcts) - // min_bins = nbShortMdcts; + /*if (min_bins < nbShortMdcts) + min_bins = nbShortMdcts;*/ res = (Fs+frame_size)/(2*frame_size); min_width = min_bins*res; diff --git a/libcelt/vq.c b/libcelt/vq.c index d414dc3c..ec9b1005 100644 --- a/libcelt/vq.c +++ b/libcelt/vq.c @@ -40,6 +40,10 @@ #include "os_support.h" #include "rate.h" +#ifndef M_PI +#define M_PI 3.141592653 +#endif + static void exp_rotation(celt_norm_t *X, int len, int dir, int stride, int K) { int i, k, iter; @@ -339,11 +343,10 @@ celt_word16_t renormalise_vector(celt_norm_t *X, celt_word16_t value, int N, int return rE; } -static void fold(const CELTMode *m, int N, celt_norm_t *Y, celt_norm_t * restrict P, int N0, int B) +static void fold(const CELTMode *m, int N, const celt_norm_t * restrict Y, celt_norm_t * restrict P, int N0, int B) { int j; - const int C = CHANNELS(m); - int id = (N0*C) % (C*B); + int id = N0 % B; /* Here, we assume that id will never be greater than N0, i.e. that no band is wider than N0. In the unlikely case it happens, we set everything to zero */ @@ -357,23 +360,17 @@ static void fold(const CELTMode *m, int N, celt_norm_t *Y, celt_norm_t * restric //printf ("%d\n", offset); id += offset; }*/ - if (id+C*N>N0*C) - for (j=0;jN0) + for (j=0;j