ref: b8ba70c99be6e597bbfee3e18b949193f52ef075
parent: b8a06ee00d61a80b6509fc0fe8552842856d9aec
author: Jean-Marc Valin <[email protected]>
date: Sun Apr 18 18:10:24 EDT 2010
Disabling resynthesis when not needed (need to remove folding for this to work)
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -448,7 +448,7 @@
}
/* Quantisation of the residual */
-void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const celt_ener *bandE, int *pulses, int shortBlocks, int fold, int total_bits, int encode, void *enc_dec)
+void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const celt_ener *bandE, int *pulses, int shortBlocks, int fold, int resynth, int total_bits, int encode, void *enc_dec)
{
int i, j, remaining_bits, balance;
const celt_int16 * restrict eBands = m->eBands;
@@ -467,7 +467,6 @@
int tell;
int N;
int q;
- celt_word16 n;
const celt_int16 * const *BPbits;
int curr_balance, curr_bits;
@@ -498,20 +497,25 @@
}
balance += pulses[i] + tell;
- n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22));
if (q > 0)
{
int spread = fold ? B : 0;
if (encode)
- alg_quant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc_dec);
+ alg_quant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, resynth, enc_dec);
else
alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc_dec);
} else {
- intra_fold(m, start, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
+ if (resynth)
+ intra_fold(m, start, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
}
- for (j=eBands[i];j<eBands[i+1];j++)
- norm[j] = MULT16_16_Q15(n,X[j]);
+ if (resynth)
+ {
+ celt_word16 n;
+ n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22));
+ for (j=eBands[i];j<eBands[i+1];j++)
+ norm[j] = MULT16_16_Q15(n,X[j]);
+ }
}
RESTORE_STACK;
}
@@ -518,7 +522,7 @@
#ifndef DISABLE_STEREO
-void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ener *bandE, int *pulses, int shortBlocks, int fold, int total_bits, ec_enc *enc)
+void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_ener *bandE, int *pulses, int shortBlocks, int fold, int resynth, int total_bits, ec_enc *enc)
{
int i, j, remaining_bits, balance;
const celt_int16 * restrict eBands = m->eBands;
@@ -537,7 +541,6 @@
{
int tell;
int q1, q2;
- celt_word16 n;
const celt_int16 * const *BPbits;
int b, qb;
int N;
@@ -607,7 +610,6 @@
iside = bitexact_cos(16384-itheta);
delta = (N-1)*(log2_frac(iside,BITRES+2)-log2_frac(imid,BITRES+2))>>2;
}
- n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22));
#if 0
if (N==2)
{
@@ -710,13 +712,14 @@
if (q1 > 0) {
int spread = fold ? B : 0;
- alg_quant(X, N, q1, spread, enc);
+ alg_quant(X, N, q1, spread, resynth, enc);
} else {
- intra_fold(m, start, eBands[i+1]-eBands[i], norm, X, eBands[i], B);
+ if (resynth)
+ intra_fold(m, start, eBands[i+1]-eBands[i], norm, X, eBands[i], B);
}
if (q2 > 0) {
int spread = fold ? B : 0;
- alg_quant(Y, N, q2, spread, enc);
+ alg_quant(Y, N, q2, spread, resynth, enc);
} else
for (j=0;j<N;j++)
Y[j] = 0;
@@ -724,24 +727,29 @@
balance += pulses[i] + tell;
+ if (resynth)
+ {
+ celt_word16 n;
#ifdef FIXED_POINT
- mid = imid;
- side = iside;
+ mid = imid;
+ side = iside;
#else
- mid = (1.f/32768)*imid;
- side = (1.f/32768)*iside;
+ mid = (1.f/32768)*imid;
+ side = (1.f/32768)*iside;
#endif
- for (j=0;j<N;j++)
- norm[eBands[i]+j] = MULT16_16_Q15(n,X[j]);
+ n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22));
+ for (j=0;j<N;j++)
+ norm[eBands[i]+j] = MULT16_16_Q15(n,X[j]);
- for (j=0;j<N;j++)
- X[j] = MULT16_16_Q15(X[j], mid);
- for (j=0;j<N;j++)
- Y[j] = MULT16_16_Q15(Y[j], side);
+ for (j=0;j<N;j++)
+ X[j] = MULT16_16_Q15(X[j], mid);
+ for (j=0;j<N;j++)
+ Y[j] = MULT16_16_Q15(Y[j], side);
- stereo_band_mix(m, X, Y, bandE, 0, i, -1);
- renormalise_vector(X, Q15ONE, N, 1);
- renormalise_vector(Y, Q15ONE, N, 1);
+ stereo_band_mix(m, X, Y, bandE, 0, i, -1);
+ renormalise_vector(X, Q15ONE, N, 1);
+ renormalise_vector(Y, Q15ONE, N, 1);
+ }
}
RESTORE_STACK;
}
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -85,9 +85,9 @@
* @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
* @param enc Entropy encoder
*/
-void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const celt_ener *bandE, int *pulses, int time_domain, int fold, int total_bits, int encode, void *enc_dec);
+void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const celt_ener *bandE, int *pulses, int time_domain, int fold, int resynth, int total_bits, int encode, void *enc_dec);
-void quant_bands_stereo(const CELTMode *m, int start, celt_norm * restrict X, const celt_ener *bandE, int *pulses, int time_domain, int fold, int total_bits, ec_enc *enc);
+void quant_bands_stereo(const CELTMode *m, int start, celt_norm * restrict X, const celt_ener *bandE, int *pulses, int time_domain, int fold, int resynth, int total_bits, ec_enc *enc);
/** Decoding of the residual spectrum
* @param m Mode data
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -561,6 +561,7 @@
int shortBlocks=0;
int transient_time;
int transient_shift;
+ int resynth;
const int C = CHANNELS(st->channels);
int mdct_weight_shift = 0;
int mdct_weight_pos=0;
@@ -610,6 +611,8 @@
transient_shift = 0;
shortBlocks = 0;
+ resynth = st->pitch_available>0 || optional_synthesis!=NULL;
+
if (st->mode->nbShortMdcts > 1 && transient_analysis(in, N+st->overlap, C, &transient_time, &transient_shift))
{
#ifndef FIXED_POINT
@@ -854,16 +857,16 @@
/* Residual quantisation */
if (C==1)
- quant_bands(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, 1, &enc);
+ quant_bands(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, resynth, nbCompressedBytes*8, 1, &enc);
#ifndef DISABLE_STEREO
else
- quant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, nbCompressedBytes*8, &enc);
+ quant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, resynth, nbCompressedBytes*8, &enc);
#endif
quant_energy_finalise(st->mode, start, bandE, st->oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(&enc, 0), &enc, C);
/* Re-synthesis of the coded audio if required */
- if (st->pitch_available>0 || optional_synthesis!=NULL)
+ if (resynth)
{
if (st->pitch_available>0 && st->pitch_available<MAX_PERIOD)
st->pitch_available+=st->frame_size;
@@ -1527,7 +1530,7 @@
/* Decode fixed codebook and merge with pitch */
if (C==1)
- quant_bands(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, len*8, 0, &dec);
+ quant_bands(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, 1, len*8, 0, &dec);
#ifndef DISABLE_STEREO
else
unquant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec);
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -257,7 +257,7 @@
while (++i < N);
}
-void alg_quant(celt_norm *X, int N, int K, int spread, ec_enc *enc)
+void alg_quant(celt_norm *X, int N, int K, int spread, int resynth, ec_enc *enc)
{
VARDECL(celt_norm, y);
VARDECL(int, iy);
@@ -414,9 +414,12 @@
/* Recompute the gain in one pass to reduce the encoder-decoder mismatch
due to the recursive computation used in quantisation. */
- normalise_residual(iy, X, N, K, EXTRACT16(SHR32(yy,2*yshift)));
- if (spread)
- exp_rotation(X, N, -1, spread, K);
+ if (resynth)
+ {
+ normalise_residual(iy, X, N, K, EXTRACT16(SHR32(yy,2*yshift)));
+ if (spread)
+ exp_rotation(X, N, -1, spread, K);
+ }
RESTORE_STACK;
}
--- a/libcelt/vq.h
+++ b/libcelt/vq.h
@@ -51,7 +51,7 @@
* @param p Pitch vector (it is assumed that p+x is a unit vector)
* @param enc Entropy encoder state
*/
-void alg_quant(celt_norm *X, int N, int K, int spread, ec_enc *enc);
+void alg_quant(celt_norm *X, int N, int K, int spread, int resynth, ec_enc *enc);
/** Algebraic pulse decoder
* @param x Decoded normalised spectrum (returned)