diff --git a/celt/bands.c b/celt/bands.c index ee23091231dc0f66ac0f15e9f4cbe48341c1ef01..3308bc425bc8517437ba0e64d3af3cc8650bd410 100644 --- a/celt/bands.c +++ b/celt/bands.c @@ -193,12 +193,22 @@ void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, cel /* De-normalise the energy to produce the synthesis from the unit-energy bands */ void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X, - celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandLogE, int start, int end, int C, int M) + celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandLogE, int start, + int end, int C, int M, int downsample, int silence) { int i, c, N; + int bound; const opus_int16 *eBands = m->eBands; N = M*m->shortMdctSize; + bound = M*eBands[end]; + if (downsample!=1) + bound = IMIN(bound, N/downsample); celt_assert2(C<=2, "denormalise_bands() not implemented for >2 channels"); + if (silence) + { + bound = 0; + start = end = 0; + } c=0; do { celt_sig * OPUS_RESTRICT f; const celt_norm * OPUS_RESTRICT x; @@ -252,7 +262,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X, } while (++j<band_end); } celt_assert(start <= end); - OPUS_CLEAR(&freq[c*N+M*eBands[end]], N-M*eBands[end]); + OPUS_CLEAR(&freq[c*N+bound], N-bound); } while (++c<C); } diff --git a/celt/bands.h b/celt/bands.h index e6ad9c52438f80760b6bcd4554bcb2d36d5f4b52..924f0a175d8dd89eb1a4c56b58394e9e10627857 100644 --- a/celt/bands.h +++ b/celt/bands.h @@ -59,7 +59,8 @@ void normalise_bands(const CELTMode *m, const celt_sig * OPUS_RESTRICT freq, cel * @param bandE Square root of the energy for each band */ void denormalise_bands(const CELTMode *m, const celt_norm * OPUS_RESTRICT X, - celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandE, int start, int end, int C, int M); + celt_sig * OPUS_RESTRICT freq, const opus_val16 *bandE, int start, + int end, int C, int M, int downsample, int silence); #define SPREAD_NONE (0) #define SPREAD_LIGHT (1) diff --git a/celt/celt_decoder.c b/celt/celt_decoder.c index 61bf1da0262e004f5f976ac4ae07dedbffb3b6df..eefda8530a71967756a0230d434330696353436a 100644 --- a/celt/celt_decoder.c +++ b/celt/celt_decoder.c @@ -421,15 +421,9 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R } st->rng = seed; - denormalise_bands(mode, X, freq, plcLogE, start, effEnd, C, 1<<LM); + denormalise_bands(mode, X, freq, plcLogE, start, effEnd, C, 1<<LM, + downsample, 0); - c=0; do { - int bound = eBands[effEnd]<<LM; - if (downsample!=1) - bound = IMIN(bound, N/downsample); - for (i=bound;i<N;i++) - freq[c*N+i] = 0; - } while (++c<C); c=0; do { OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+(overlap>>1)); @@ -921,23 +915,16 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat { for (i=0;i<C*nbEBands;i++) oldBandE[i] = -QCONST16(28.f,DB_SHIFT); - for (i=0;i<C*N;i++) - freq[i] = 0; - } else { - /* Synthesis */ - denormalise_bands(mode, X, freq, oldBandE, start, effEnd, C, M); } + + /* Synthesis */ + denormalise_bands(mode, X, freq, oldBandE, start, effEnd, C, M, + st->downsample, silence); + c=0; do { OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap/2); } while (++c<CC); - c=0; do { - int bound = M*eBands[effEnd]; - if (st->downsample!=1) - bound = IMIN(bound, N/st->downsample); - OPUS_CLEAR(&freq[c*N+bound], N-bound); - } while (++c<C); - c=0; do { out_syn[c] = decode_mem[c]+DECODE_BUFFER_SIZE-N; } while (++c<CC); diff --git a/celt/celt_encoder.c b/celt/celt_encoder.c index ba07a3c38c05d17c8da693319a6609915a825e53..2841594f9a4c05e2745b4d101675eddb2362a734 100644 --- a/celt/celt_encoder.c +++ b/celt/celt_encoder.c @@ -1973,14 +1973,9 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, start, end, oldBandE, oldLogE, oldLogE2, pulses, st->rng); } - if (silence) - { - for (i=0;i<C*N;i++) - freq[i] = 0; - } else { - /* Synthesis */ - denormalise_bands(mode, X, freq, oldBandE, start, effEnd, C, M); - } + /* Synthesis */ + denormalise_bands(mode, X, freq, oldBandE, start, effEnd, C, M, + st->upsample, silence); c=0; do { OPUS_MOVE(st->syn_mem[c], st->syn_mem[c]+N, 2*MAX_PERIOD-N+overlap/2);