diff --git a/libcelt/bands.c b/libcelt/bands.c index 201f6ed1..d3291935 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -737,7 +737,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c split = 1; LM -= 1; if (B==1) - fill |= fill<<1; + fill = fill&1|fill<<1; B = (B+1)>>1; } } @@ -749,6 +749,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c int mbits, sbits, delta; int qalloc; int offset; + int orig_fill; celt_int32 tell; /* Decide on the resolution to give to the split parameter theta */ @@ -869,6 +870,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c - tell; b -= qalloc; + orig_fill = fill; if (itheta == 0) { imid = 32767; @@ -928,7 +930,9 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c } } sign = 1-2*sign; - 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, fill); + /* 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. */ + 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); /* 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. */ y2[0] = -sign*x2[1]; @@ -986,7 +990,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c folding will be done to the side. */ cm |= quant_band(encode, m, i, Y, NULL, N, sbits, spread, B, intensity, tf_change, next_lowband2, resynth, ec, remaining_bits, LM, NULL, - NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<>B)<<(B0>>1&stereo-1); } } else { @@ -1018,12 +1022,17 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c int j; if (resynth) { + unsigned cm_mask; + /*B can be as large as 16, so this shift might overflow an int on a + 16-bit platform; use a long to get defined behavior.*/ + cm_mask = (unsigned)(1UL<>20; } - cm = (1<>B; stereo_merge(X, Y, mid, N); - } if (inv) { int j; @@ -1096,6 +1102,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c for (j=0;j=2 ? (1<1)) + if (lowband_offset != 0 && (spread!=SPREAD_AGGRESSIVE || B>1 || tf_change<0)) { int fold_start; int fold_end; int fold_i; + /* This ensures we never repeat spectral content within one band */ + effective_lowband = IMAX(M*eBands[start], M*eBands[lowband_offset]-N); fold_start = lowband_offset; while(M*eBands[--fold_start] > effective_lowband); fold_end = lowband_offset-1; @@ -1224,8 +1229,8 @@ void quant_all_bands(int encode, const CELTMode *m, int start, int end, norm+M*eBands[i], bandE, 0, seed, Q15ONE, lowband_scratch, x_cm|y_cm); y_cm = x_cm; } - collapse_masks[i*C+0] = (unsigned char)(x_cm&(1<mode->nbEBands, unsigned char); 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, - nbCompressedBytes*8, enc, LM, codedBands, &st->rng); + nbCompressedBytes*(8<rng); if (anti_collapse_rsv > 0) { @@ -2150,7 +2150,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da ALLOC(collapse_masks, st->mode->nbEBands, unsigned char); 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, - len*8, dec, LM, codedBands, &st->rng); + len*(8<rng); if (anti_collapse_rsv > 0) {