From e65978fea75e6583bbea527fe92e0ffbe025b24b Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 2 Dec 2010 13:46:48 -0500 Subject: [PATCH] Adding a dual stereo option. Left and right are coded independently. --- libcelt/bands.c | 32 +++++++++++++++++++++++++------- libcelt/bands.h | 2 +- libcelt/celt.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 9b5bc673..8dffcca8 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -902,13 +902,13 @@ static void quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_ void quant_all_bands(int encode, const CELTMode *m, int start, int end, celt_norm *_X, celt_norm *_Y, const celt_ener *bandE, int *pulses, - int shortBlocks, int fold, int intensity, int *tf_res, int resynth, + int shortBlocks, int fold, int dual_stereo, int intensity, int *tf_res, int resynth, int total_bits, void *ec, int LM, int codedBands) { int i, balance; celt_int32 remaining_bits; const celt_int16 * restrict eBands = m->eBands; - celt_norm * restrict norm; + celt_norm * restrict norm, * restrict norm2; VARDECL(celt_norm, _norm); VARDECL(celt_norm, lowband_scratch); int B; @@ -921,10 +921,10 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, M = 1<nbEBands], celt_norm); + ALLOC(_norm, C*M*eBands[m->nbEBands], celt_norm); ALLOC(lowband_scratch, M*(eBands[m->nbEBands]-eBands[m->nbEBands-1]), celt_norm); norm = _norm; - + norm2 = norm + M*eBands[m->nbEBands]; if (C==2) { int j; @@ -1015,10 +1015,28 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, if (effective_lowband < M*eBands[start]) effective_lowband = M*eBands[start]; } - quant_band(encode, m, i, X, Y, N, b, fold, B, intensity, tf_change, - effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM, - norm+M*eBands[i], bandE, 0, &seed, Q15ONE, lowband_scratch); + if (dual_stereo && i==intensity) + { + int j; + /* Switch off dual stereo to do intensity */ + dual_stereo = 0; + for (j=0;jeBands[i]<eBands[i+1]<eBands[13]<<(LM+1))+thetas, sumMS) + > MULT16_32_Q15(m->eBands[13]<<(LM+1), sumLR); +} + #ifdef FIXED_POINT int celt_encode_with_ec(CELTEncoder * restrict st, const celt_int16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc) { @@ -689,6 +720,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i int pitch_index=0; celt_word16 gain1 = 0; int intensity=0; + int dual_stereo=0; SAVE_STACK; if (nbCompressedBytes<0 || pcm==NULL) @@ -1001,6 +1033,11 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i ec_byte_shrink(&buf, nbCompressedBytes); } + if (C==2) + { + dual_stereo = stereo_analysis(st->mode, X, st->mode->nbEBands, LM, C, N); + ec_enc_bit_prob(enc, dual_stereo, 32768); + } if (C==2) { int effectiveRate; @@ -1055,7 +1092,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i /* Residual quantisation */ quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, - bandE, pulses, shortBlocks, has_fold, intensity, tf_res, resynth, + bandE, pulses, shortBlocks, has_fold, dual_stereo, intensity, tf_res, resynth, nbCompressedBytes*8, enc, LM, codedBands); quant_energy_finalise(st->mode, st->start, st->end, bandE, oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(enc, 0), enc, C); @@ -1619,6 +1656,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da int postfilter_pitch; celt_word16 postfilter_gain; int intensity=0; + int dual_stereo=0; SAVE_STACK; if (pcm==NULL) @@ -1747,7 +1785,10 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da } if (C==2) + { + dual_stereo = ec_dec_bit_prob(dec, 32768); intensity = ec_dec_uint(dec, 1+st->end-st->start); + } bits = len*8 - ec_dec_tell(dec, 0) - 1; codedBands = compute_allocation(st->mode, st->start, st->end, offsets, alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM); @@ -1756,7 +1797,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da /* Decode fixed codebook */ quant_all_bands(0, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, - NULL, pulses, shortBlocks, has_fold, intensity, tf_res, 1, + NULL, pulses, shortBlocks, has_fold, dual_stereo, intensity, tf_res, 1, len*8, dec, LM, codedBands); unquant_energy_finalise(st->mode, st->start, st->end, bandE, oldBandE,