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 */
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 @@ void quant_bands(const CELTMode *m, int start, celt_norm * restrict X, const cel
int tell;
int N;
int q;
celt_word16 n;
const celt_int16 * const *BPbits;
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;
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);
}
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]);
}
for (j=eBands[i];j<eBands[i+1];j++)
norm[j] = MULT16_16_Q15(n,X[j]);
}
RESTORE_STACK;
}
#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 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
{
int tell;
int q1, q2;
celt_word16 n;
const celt_int16 * const *BPbits;
int b, qb;
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);
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 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
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 @@ void quant_bands_stereo(const CELTMode *m, int start, celt_norm *_X, const celt_
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;
}

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 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

View file

@ -561,6 +561,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
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 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
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 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig
/* 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 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int
/* 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);

View file

@ -257,7 +257,7 @@ static void normalise_residual(int * restrict iy, celt_norm * restrict X, int 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(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
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;
}

View file

@ -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)