Avoid passing 'resynth' argument since resynth is either !encode

or it's always 1 if -DRESYNTH.
This commit is contained in:
Gregory Maxwell 2011-08-15 16:05:40 -04:00
parent 66c612ef43
commit d830d08923
5 changed files with 31 additions and 29 deletions

View file

@ -632,7 +632,7 @@ static int compute_qn(int N, int b, int offset, int pulse_cap, int stereo)
in two and transmit the energy difference with the two half-bands. It in two and transmit the energy difference with the two half-bands. It
can be called recursively so bands can end up being split in 8 parts. */ can be called recursively so bands can end up being split in 8 parts. */
static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_norm *Y, static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, celt_norm *Y,
int N, int b, int spread, int B, int intensity, int tf_change, celt_norm *lowband, int resynth, ec_ctx *ec, int N, int b, int spread, int B, int intensity, int tf_change, celt_norm *lowband, ec_ctx *ec,
opus_int32 *remaining_bits, int LM, celt_norm *lowband_out, const celt_ener *bandE, int level, opus_int32 *remaining_bits, int LM, celt_norm *lowband_out, const celt_ener *bandE, int level,
opus_uint32 *seed, opus_val16 gain, celt_norm *lowband_scratch, int fill) opus_uint32 *seed, opus_val16 gain, celt_norm *lowband_scratch, int fill)
{ {
@ -651,6 +651,11 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
opus_val16 mid=0, side=0; opus_val16 mid=0, side=0;
int longBlocks; int longBlocks;
unsigned cm=0; unsigned cm=0;
#ifdef RESYNTH
int resynth = 1;
#else
int resynth = !encode;
#endif
longBlocks = B0==1; longBlocks = B0==1;
@ -949,7 +954,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
sign = 1-2*sign; sign = 1-2*sign;
/* We use orig_fill here because we want to fold the side, but if /* We use orig_fill here because we want to fold the side, but if
itheta==16384, we'll have cleared the low bits of fill. */ itheta==16384, we'll have cleared the low bits of fill. */
cm = quant_band(encode, m, i, x2, NULL, N, mbits, spread, B, intensity, tf_change, lowband, resynth, ec, remaining_bits, LM, lowband_out, NULL, level, seed, gain, lowband_scratch, orig_fill); cm = quant_band(encode, m, i, x2, NULL, N, mbits, spread, B, intensity, tf_change, lowband, ec, remaining_bits, LM, lowband_out, NULL, level, seed, gain, lowband_scratch, orig_fill);
/* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse), /* We don't split N=2 bands, so cm is either 1 or 0 (for a fold-collapse),
and there's no need to worry about mixing with the other channel. */ and there's no need to worry about mixing with the other channel. */
y2[0] = -sign*x2[1]; y2[0] = -sign*x2[1];
@ -1005,7 +1010,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
/* In stereo mode, we do not apply a scaling to the mid because we need the normalized /* In stereo mode, we do not apply a scaling to the mid because we need the normalized
mid for folding later */ mid for folding later */
cm = quant_band(encode, m, i, X, NULL, N, mbits, spread, B, intensity, tf_change, cm = quant_band(encode, m, i, X, NULL, N, mbits, spread, B, intensity, tf_change,
lowband, resynth, ec, remaining_bits, LM, next_lowband_out1, lowband, ec, remaining_bits, LM, next_lowband_out1,
NULL, next_level, seed, stereo ? Q15ONE : MULT16_16_P15(gain,mid), lowband_scratch, fill); NULL, next_level, seed, stereo ? Q15ONE : MULT16_16_P15(gain,mid), lowband_scratch, fill);
rebalance = mbits - (rebalance-*remaining_bits); rebalance = mbits - (rebalance-*remaining_bits);
if (rebalance > 3<<BITRES && itheta!=0) if (rebalance > 3<<BITRES && itheta!=0)
@ -1014,13 +1019,13 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
/* For a stereo split, the high bits of fill are always zero, so no /* For a stereo split, the high bits of fill are always zero, so no
folding will be done to the side. */ folding will be done to the side. */
cm |= quant_band(encode, m, i, Y, NULL, N, sbits, spread, B, intensity, tf_change, cm |= quant_band(encode, m, i, Y, NULL, N, sbits, spread, B, intensity, tf_change,
next_lowband2, resynth, ec, remaining_bits, LM, NULL, next_lowband2, ec, remaining_bits, LM, NULL,
NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<<(B0>>1&stereo-1); NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<<(B0>>1&stereo-1);
} else { } else {
/* For a stereo split, the high bits of fill are always zero, so no /* For a stereo split, the high bits of fill are always zero, so no
folding will be done to the side. */ folding will be done to the side. */
cm = quant_band(encode, m, i, Y, NULL, N, sbits, spread, B, intensity, tf_change, cm = quant_band(encode, m, i, Y, NULL, N, sbits, spread, B, intensity, tf_change,
next_lowband2, resynth, ec, remaining_bits, LM, NULL, next_lowband2, ec, remaining_bits, LM, NULL,
NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<<(B0>>1&stereo-1); NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<<(B0>>1&stereo-1);
rebalance = sbits - (rebalance-*remaining_bits); rebalance = sbits - (rebalance-*remaining_bits);
if (rebalance > 3<<BITRES && itheta!=16384) if (rebalance > 3<<BITRES && itheta!=16384)
@ -1028,7 +1033,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
/* In stereo mode, we do not apply a scaling to the mid because we need the normalized /* In stereo mode, we do not apply a scaling to the mid because we need the normalized
mid for folding later */ mid for folding later */
cm |= quant_band(encode, m, i, X, NULL, N, mbits, spread, B, intensity, tf_change, cm |= quant_band(encode, m, i, X, NULL, N, mbits, spread, B, intensity, tf_change,
lowband, resynth, ec, remaining_bits, LM, next_lowband_out1, lowband, ec, remaining_bits, LM, next_lowband_out1,
NULL, next_level, seed, stereo ? Q15ONE : MULT16_16_P15(gain,mid), lowband_scratch, fill); NULL, next_level, seed, stereo ? Q15ONE : MULT16_16_P15(gain,mid), lowband_scratch, fill);
} }
} }
@ -1054,7 +1059,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
/* Finally do the actual quantization */ /* Finally do the actual quantization */
if (encode) if (encode)
cm = alg_quant(X, N, K, spread, B, resynth, ec, gain); cm = alg_quant(X, N, K, spread, B, ec, gain);
else else
cm = alg_unquant(X, N, K, spread, B, ec, gain); cm = alg_unquant(X, N, K, spread, B, ec, gain);
} else { } else {
@ -1160,7 +1165,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
void quant_all_bands(int encode, const CELTMode *m, int start, int end, void quant_all_bands(int encode, const CELTMode *m, int start, int end,
celt_norm *_X, celt_norm *_Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses, celt_norm *_X, celt_norm *_Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses,
int shortBlocks, int spread, int dual_stereo, int intensity, int *tf_res, int resynth, int shortBlocks, int spread, int dual_stereo, int intensity, int *tf_res,
opus_int32 total_bits, opus_int32 balance, ec_ctx *ec, int LM, int codedBands, opus_uint32 *seed) opus_int32 total_bits, opus_int32 balance, ec_ctx *ec, int LM, int codedBands, opus_uint32 *seed)
{ {
int i; int i;
@ -1174,6 +1179,11 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end,
int lowband_offset; int lowband_offset;
int update_lowband = 1; int update_lowband = 1;
int C = _Y != NULL ? 2 : 1; int C = _Y != NULL ? 2 : 1;
#ifdef RESYNTH
int resynth = 1;
#else
int resynth = !encode;
#endif
SAVE_STACK; SAVE_STACK;
M = 1<<LM; M = 1<<LM;
@ -1263,14 +1273,14 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end,
if (dual_stereo) if (dual_stereo)
{ {
x_cm = quant_band(encode, m, i, X, NULL, N, b/2, spread, B, intensity, tf_change, x_cm = quant_band(encode, m, i, X, NULL, N, b/2, spread, B, intensity, tf_change,
effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM, effective_lowband != -1 ? norm+effective_lowband : NULL, ec, &remaining_bits, LM,
norm+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, x_cm); norm+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, x_cm);
y_cm = quant_band(encode, m, i, Y, NULL, N, b/2, spread, B, intensity, tf_change, y_cm = quant_band(encode, m, i, Y, NULL, N, b/2, spread, B, intensity, tf_change,
effective_lowband != -1 ? norm2+effective_lowband : NULL, resynth, ec, &remaining_bits, LM, effective_lowband != -1 ? norm2+effective_lowband : NULL, ec, &remaining_bits, LM,
norm2+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, y_cm); norm2+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, y_cm);
} else { } else {
x_cm = quant_band(encode, m, i, X, Y, N, b, spread, B, intensity, tf_change, x_cm = quant_band(encode, m, i, X, Y, N, b, spread, B, intensity, tf_change,
effective_lowband != -1 ? norm+effective_lowband : NULL, resynth, ec, &remaining_bits, LM, effective_lowband != -1 ? norm+effective_lowband : NULL, ec, &remaining_bits, LM,
norm+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, x_cm|y_cm); norm+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, x_cm|y_cm);
y_cm = x_cm; y_cm = x_cm;
} }

View file

@ -83,7 +83,7 @@ void haar1(celt_norm *X, int N0, int stride);
*/ */
void quant_all_bands(int encode, const CELTMode *m, int start, int end, void quant_all_bands(int encode, const CELTMode *m, int start, int end,
celt_norm * X, celt_norm * Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses, celt_norm * X, celt_norm * Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses,
int time_domain, int fold, int dual_stereo, int intensity, int *tf_res, int resynth, int time_domain, int fold, int dual_stereo, int intensity, int *tf_res,
opus_int32 total_bits, opus_int32 balance, ec_ctx *ec, int M, int codedBands, opus_uint32 *seed); opus_int32 total_bits, opus_int32 balance, ec_ctx *ec, int M, int codedBands, opus_uint32 *seed);
void stereo_decision(const CELTMode *m, celt_norm * restrict X, int *stereo_mode, int len, int M); void stereo_decision(const CELTMode *m, celt_norm * restrict X, int *stereo_mode, int len, int M);

View file

@ -920,7 +920,6 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
opus_val16 *oldBandE, *oldLogE, *oldLogE2; opus_val16 *oldBandE, *oldLogE, *oldLogE2;
int shortBlocks=0; int shortBlocks=0;
int isTransient=0; int isTransient=0;
int resynth;
const int CC = CHANNELS(st->channels); const int CC = CHANNELS(st->channels);
const int C = CHANNELS(st->stream_channels); const int C = CHANNELS(st->stream_channels);
int LM, M; int LM, M;
@ -1231,12 +1230,6 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
RESTORE_STACK; RESTORE_STACK;
} }
#ifdef RESYNTH
resynth = 1;
#else
resynth = 0;
#endif
isTransient = 0; isTransient = 0;
shortBlocks = 0; shortBlocks = 0;
if (LM>0 && ec_tell(enc)+3<=total_bits) if (LM>0 && ec_tell(enc)+3<=total_bits)
@ -1534,7 +1527,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
/* Residual quantisation */ /* Residual quantisation */
ALLOC(collapse_masks, C*st->mode->nbEBands, unsigned char); ALLOC(collapse_masks, C*st->mode->nbEBands, unsigned char);
quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks, quant_all_bands(1, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks,
bandE, pulses, shortBlocks, st->spread_decision, dual_stereo, intensity, tf_res, resynth, bandE, pulses, shortBlocks, st->spread_decision, dual_stereo, intensity, tf_res,
nbCompressedBytes*(8<<BITRES)-anti_collapse_rsv, balance, enc, LM, codedBands, &st->rng); nbCompressedBytes*(8<<BITRES)-anti_collapse_rsv, balance, enc, LM, codedBands, &st->rng);
if (anti_collapse_rsv > 0) if (anti_collapse_rsv > 0)
@ -1555,7 +1548,6 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
#ifdef RESYNTH #ifdef RESYNTH
/* Re-synthesis of the coded audio if required */ /* Re-synthesis of the coded audio if required */
if (resynth)
{ {
celt_sig *out_mem[2]; celt_sig *out_mem[2];
celt_sig *overlap_mem[2]; celt_sig *overlap_mem[2];
@ -2510,7 +2502,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
/* Decode fixed codebook */ /* Decode fixed codebook */
ALLOC(collapse_masks, C*st->mode->nbEBands, unsigned char); ALLOC(collapse_masks, C*st->mode->nbEBands, unsigned char);
quant_all_bands(0, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks, quant_all_bands(0, st->mode, st->start, st->end, X, C==2 ? X+N : NULL, collapse_masks,
NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_res, 1, NULL, pulses, shortBlocks, spread_decision, dual_stereo, intensity, tf_res,
len*(8<<BITRES)-anti_collapse_rsv, balance, dec, LM, codedBands, &st->rng); len*(8<<BITRES)-anti_collapse_rsv, balance, dec, LM, codedBands, &st->rng);
if (anti_collapse_rsv > 0) if (anti_collapse_rsv > 0)

View file

@ -167,7 +167,7 @@ static unsigned extract_collapse_mask(int *iy, int N, int B)
} }
unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B,
int resynth, ec_enc *enc, opus_val16 gain) ec_enc *enc, opus_val16 gain)
{ {
VARDECL(celt_norm, y); VARDECL(celt_norm, y);
VARDECL(int, iy); VARDECL(int, iy);
@ -320,11 +320,11 @@ unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B,
} while (++j<N); } while (++j<N);
encode_pulses(iy, N, K, enc); encode_pulses(iy, N, K, enc);
if (resynth) #ifdef RESYNTH
{ normalise_residual(iy, X, N, yy, gain);
normalise_residual(iy, X, N, yy, gain); exp_rotation(X, N, -1, B, K, spread);
exp_rotation(X, N, -1, B, K, spread); #endif
}
collapse_mask = extract_collapse_mask(iy, N, B); collapse_mask = extract_collapse_mask(iy, N, B);
RESTORE_STACK; RESTORE_STACK;
return collapse_mask; return collapse_mask;

View file

@ -49,7 +49,7 @@
* @ret A mask indicating which blocks in the band received pulses * @ret A mask indicating which blocks in the band received pulses
*/ */
unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B, unsigned alg_quant(celt_norm *X, int N, int K, int spread, int B,
int resynth, ec_enc *enc, opus_val16 gain); ec_enc *enc, opus_val16 gain);
/** Algebraic pulse decoder /** Algebraic pulse decoder
* @param x Decoded normalised spectrum (returned) * @param x Decoded normalised spectrum (returned)