Disabling resynthesis when not needed (need to remove folding for this to work)

This commit is contained in:
Jean-Marc Valin 2010-04-18 22:10:24 -04:00
parent b8a06ee00d
commit b8ba70c99b
5 changed files with 51 additions and 37 deletions

View file

@ -448,7 +448,7 @@ int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int
} }
/* Quantisation of the residual */ /* 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; int i, j, remaining_bits, balance;
const celt_int16 * restrict eBands = m->eBands; const celt_int16 * restrict eBands = m->eBands;
@ -467,7 +467,6 @@ void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const cel
int tell; int tell;
int N; int N;
int q; int q;
celt_word16 n;
const celt_int16 * const *BPbits; const celt_int16 * const *BPbits;
int curr_balance, curr_bits; int curr_balance, curr_bits;
@ -498,27 +497,32 @@ void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const cel
} }
balance += pulses[i] + tell; balance += pulses[i] + tell;
n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22));
if (q > 0) if (q > 0)
{ {
int spread = fold ? B : 0; int spread = fold ? B : 0;
if (encode) 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 else
alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc_dec); alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc_dec);
} else { } else {
if (resynth)
intra_fold(m, start, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B); intra_fold(m, start, eBands[i+1]-eBands[i], norm, X+eBands[i], eBands[i], B);
} }
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++) for (j=eBands[i];j<eBands[i+1];j++)
norm[j] = MULT16_16_Q15(n,X[j]); norm[j] = MULT16_16_Q15(n,X[j]);
} }
}
RESTORE_STACK; RESTORE_STACK;
} }
#ifndef DISABLE_STEREO #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; int i, j, remaining_bits, balance;
const celt_int16 * restrict eBands = m->eBands; const celt_int16 * restrict eBands = m->eBands;
@ -537,7 +541,6 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
{ {
int tell; int tell;
int q1, q2; int q1, q2;
celt_word16 n;
const celt_int16 * const *BPbits; const celt_int16 * const *BPbits;
int b, qb; int b, qb;
int N; int N;
@ -607,7 +610,6 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
iside = bitexact_cos(16384-itheta); iside = bitexact_cos(16384-itheta);
delta = (N-1)*(log2_frac(iside,BITRES+2)-log2_frac(imid,BITRES+2))>>2; 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 0
if (N==2) if (N==2)
{ {
@ -710,13 +712,14 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
if (q1 > 0) { if (q1 > 0) {
int spread = fold ? B : 0; int spread = fold ? B : 0;
alg_quant(X, N, q1, spread, enc); alg_quant(X, N, q1, spread, resynth, enc);
} else { } else {
if (resynth)
intra_fold(m, start, eBands[i+1]-eBands[i], norm, X, eBands[i], B); intra_fold(m, start, eBands[i+1]-eBands[i], norm, X, eBands[i], B);
} }
if (q2 > 0) { if (q2 > 0) {
int spread = fold ? B : 0; int spread = fold ? B : 0;
alg_quant(Y, N, q2, spread, enc); alg_quant(Y, N, q2, spread, resynth, enc);
} else } else
for (j=0;j<N;j++) for (j=0;j<N;j++)
Y[j] = 0; Y[j] = 0;
@ -724,6 +727,9 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
balance += pulses[i] + tell; balance += pulses[i] + tell;
if (resynth)
{
celt_word16 n;
#ifdef FIXED_POINT #ifdef FIXED_POINT
mid = imid; mid = imid;
side = iside; side = iside;
@ -731,6 +737,7 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
mid = (1.f/32768)*imid; mid = (1.f/32768)*imid;
side = (1.f/32768)*iside; side = (1.f/32768)*iside;
#endif #endif
n = celt_sqrt(SHL32(EXTEND32(eBands[i+1]-eBands[i]),22));
for (j=0;j<N;j++) for (j=0;j<N;j++)
norm[eBands[i]+j] = MULT16_16_Q15(n,X[j]); norm[eBands[i]+j] = MULT16_16_Q15(n,X[j]);
@ -743,6 +750,7 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
renormalise_vector(X, Q15ONE, N, 1); renormalise_vector(X, Q15ONE, N, 1);
renormalise_vector(Y, Q15ONE, N, 1); renormalise_vector(Y, Q15ONE, N, 1);
} }
}
RESTORE_STACK; RESTORE_STACK;
} }
#endif /* DISABLE_STEREO */ #endif /* DISABLE_STEREO */

View file

@ -85,9 +85,9 @@ int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int
* @param total_bits Total number of bits that can be used for the frame (including the ones already spent) * @param total_bits Total number of bits that can be used for the frame (including the ones already spent)
* @param enc Entropy encoder * @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 /** Decoding of the residual spectrum
* @param m Mode data * @param m Mode data

View file

@ -561,6 +561,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
int shortBlocks=0; int shortBlocks=0;
int transient_time; int transient_time;
int transient_shift; int transient_shift;
int resynth;
const int C = CHANNELS(st->channels); const int C = CHANNELS(st->channels);
int mdct_weight_shift = 0; int mdct_weight_shift = 0;
int mdct_weight_pos=0; int mdct_weight_pos=0;
@ -610,6 +611,8 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
transient_shift = 0; transient_shift = 0;
shortBlocks = 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)) if (st->mode->nbShortMdcts > 1 && transient_analysis(in, N+st->overlap, C, &transient_time, &transient_shift))
{ {
#ifndef FIXED_POINT #ifndef FIXED_POINT
@ -854,16 +857,16 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
/* Residual quantisation */ /* Residual quantisation */
if (C==1) 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 #ifndef DISABLE_STEREO
else 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 #endif
quant_energy_finalise(st->mode, start, bandE, st->oldBandE, error, fine_quant, fine_priority, nbCompressedBytes*8-ec_enc_tell(&enc, 0), &enc, C); 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 */ /* 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) if (st->pitch_available>0 && st->pitch_available<MAX_PERIOD)
st->pitch_available+=st->frame_size; st->pitch_available+=st->frame_size;
@ -1527,7 +1530,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int
/* Decode fixed codebook and merge with pitch */ /* Decode fixed codebook and merge with pitch */
if (C==1) 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 #ifndef DISABLE_STEREO
else else
unquant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec); unquant_bands_stereo(st->mode, start, X, bandE, pulses, shortBlocks, has_fold, len*8, &dec);

View file

@ -257,7 +257,7 @@ static void normalise_residual(int * restrict iy, celt_norm * restrict X, int N,
while (++i < N); 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(celt_norm, y);
VARDECL(int, iy); VARDECL(int, iy);
@ -414,9 +414,12 @@ void alg_quant(celt_norm *X, int N, int K, int spread, ec_enc *enc)
/* Recompute the gain in one pass to reduce the encoder-decoder mismatch /* Recompute the gain in one pass to reduce the encoder-decoder mismatch
due to the recursive computation used in quantisation. */ due to the recursive computation used in quantisation. */
if (resynth)
{
normalise_residual(iy, X, N, K, EXTRACT16(SHR32(yy,2*yshift))); normalise_residual(iy, X, N, K, EXTRACT16(SHR32(yy,2*yshift)));
if (spread) if (spread)
exp_rotation(X, N, -1, spread, K); exp_rotation(X, N, -1, spread, K);
}
RESTORE_STACK; RESTORE_STACK;
} }

View file

@ -51,7 +51,7 @@
* @param p Pitch vector (it is assumed that p+x is a unit vector) * @param p Pitch vector (it is assumed that p+x is a unit vector)
* @param enc Entropy encoder state * @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 /** Algebraic pulse decoder
* @param x Decoded normalised spectrum (returned) * @param x Decoded normalised spectrum (returned)