diff options
author | Rostislav Pehlivanov <atomnuker@gmail.com> | 2017-12-04 11:55:45 +0300 |
---|---|---|
committer | Rostislav Pehlivanov <atomnuker@gmail.com> | 2017-12-04 13:51:19 +0300 |
commit | ce87e630fa009d0bf78cd7a7599e6efc221e6543 (patch) | |
tree | a0dab6973b6b5c9b0ff994b28fc51afcaac0152c /libavcodec/opus_celt.c | |
parent | 86fda8be3f3892c48474a319e0ef7509dc137e3e (diff) |
opus_celt: deduplicate band quantization/dequantization function
No point in having the same code twice to do exactly the same thing.
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Diffstat (limited to 'libavcodec/opus_celt.c')
-rw-r--r-- | libavcodec/opus_celt.c | 114 |
1 files changed, 6 insertions, 108 deletions
diff --git a/libavcodec/opus_celt.c b/libavcodec/opus_celt.c index 72b299a19c..ff74e2f067 100644 --- a/libavcodec/opus_celt.c +++ b/libavcodec/opus_celt.c @@ -676,110 +676,6 @@ static void process_anticollapse(CeltFrame *f, CeltBlock *block, float *X) } } -static void celt_decode_bands(CeltFrame *f, OpusRangeCoder *rc) -{ - float lowband_scratch[8 * 22]; - float norm[2 * 8 * 100]; - - int totalbits = (f->framebits << 3) - f->anticollapse_needed; - - int update_lowband = 1; - int lowband_offset = 0; - - int i, j; - - memset(f->block[0].coeffs, 0, sizeof(f->block[0].coeffs)); - memset(f->block[1].coeffs, 0, sizeof(f->block[0].coeffs)); - - for (i = f->start_band; i < f->end_band; i++) { - uint32_t cm[2] = { (1 << f->blocks) - 1, (1 << f->blocks) - 1 }; - int band_offset = ff_celt_freq_bands[i] << f->size; - int band_size = ff_celt_freq_range[i] << f->size; - float *X = f->block[0].coeffs + band_offset; - float *Y = (f->channels == 2) ? f->block[1].coeffs + band_offset : NULL; - - int consumed = opus_rc_tell_frac(rc); - float *norm2 = norm + 8 * 100; - int effective_lowband = -1; - int b = 0; - - /* Compute how many bits we want to allocate to this band */ - if (i != f->start_band) - f->remaining -= consumed; - f->remaining2 = totalbits - consumed - 1; - if (i <= f->coded_bands - 1) { - int curr_balance = f->remaining / FFMIN(3, f->coded_bands-i); - b = av_clip_uintp2(FFMIN(f->remaining2 + 1, f->pulses[i] + curr_balance), 14); - } - - if ((ff_celt_freq_bands[i] - ff_celt_freq_range[i] >= ff_celt_freq_bands[f->start_band] || - i == f->start_band + 1) && (update_lowband || lowband_offset == 0)) - lowband_offset = i; - - if (i == f->start_band + 1) { - /* Special Hybrid Folding (RFC 8251 section 9). Copy the first band into - the second to ensure the second band never has to use the LCG. */ - int offset = 8 * ff_celt_freq_bands[i]; - int count = 8 * (ff_celt_freq_range[i] - ff_celt_freq_range[i-1]); - - memcpy(&norm[offset], &norm[offset - count], count * sizeof(float)); - - if (f->channels == 2) - memcpy(&norm2[offset], &norm2[offset - count], count * sizeof(float)); - } - - /* Get a conservative estimate of the collapse_mask's for the bands we're - going to be folding from. */ - if (lowband_offset != 0 && (f->spread != CELT_SPREAD_AGGRESSIVE || - f->blocks > 1 || f->tf_change[i] < 0)) { - int foldstart, foldend; - - /* This ensures we never repeat spectral content within one band */ - effective_lowband = FFMAX(ff_celt_freq_bands[f->start_band], - ff_celt_freq_bands[lowband_offset] - ff_celt_freq_range[i]); - foldstart = lowband_offset; - while (ff_celt_freq_bands[--foldstart] > effective_lowband); - foldend = lowband_offset - 1; - while (++foldend < i && ff_celt_freq_bands[foldend] < effective_lowband + ff_celt_freq_range[i]); - - cm[0] = cm[1] = 0; - for (j = foldstart; j < foldend; j++) { - cm[0] |= f->block[0].collapse_masks[j]; - cm[1] |= f->block[f->channels - 1].collapse_masks[j]; - } - } - - if (f->dual_stereo && i == f->intensity_stereo) { - /* Switch off dual stereo to do intensity */ - f->dual_stereo = 0; - for (j = ff_celt_freq_bands[f->start_band] << f->size; j < band_offset; j++) - norm[j] = (norm[j] + norm2[j]) / 2; - } - - if (f->dual_stereo) { - cm[0] = f->pvq->decode_band(f->pvq, f, rc, i, X, NULL, band_size, b / 2, f->blocks, - effective_lowband != -1 ? norm + (effective_lowband << f->size) : NULL, f->size, - norm + band_offset, 0, 1.0f, lowband_scratch, cm[0]); - - cm[1] = f->pvq->decode_band(f->pvq, f, rc, i, Y, NULL, band_size, b/2, f->blocks, - effective_lowband != -1 ? norm2 + (effective_lowband << f->size) : NULL, f->size, - norm2 + band_offset, 0, 1.0f, lowband_scratch, cm[1]); - } else { - cm[0] = f->pvq->decode_band(f->pvq, f, rc, i, X, Y, band_size, b, f->blocks, - effective_lowband != -1 ? norm + (effective_lowband << f->size) : NULL, f->size, - norm + band_offset, 0, 1.0f, lowband_scratch, cm[0]|cm[1]); - cm[1] = cm[0]; - } - - f->block[0].collapse_masks[i] = (uint8_t)cm[0]; - f->block[f->channels - 1].collapse_masks[i] = (uint8_t)cm[1]; - f->remaining += f->pulses[i] + consumed; - - /* Update the folding position only as long as we have 1 bit/sample depth */ - update_lowband = (b > band_size << 3); - } -} - int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int channels, int frame_size, int start_band, int end_band) @@ -819,8 +715,10 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, if (!f->output_channels) f->output_channels = channels; - memset(f->block[0].collapse_masks, 0, sizeof(f->block[0].collapse_masks)); - memset(f->block[1].collapse_masks, 0, sizeof(f->block[1].collapse_masks)); + for (i = 0; i < f->channels; i++) { + memset(f->block[i].coeffs, 0, sizeof(f->block[i].coeffs)); + memset(f->block[i].collapse_masks, 0, sizeof(f->block[i].collapse_masks)); + } consumed = opus_rc_tell(rc); @@ -857,7 +755,7 @@ int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, celt_decode_tf_changes (f, rc); celt_decode_allocation (f, rc); celt_decode_fine_energy (f, rc); - celt_decode_bands (f, rc); + ff_celt_quant_bands (f, rc); if (f->anticollapse_needed) f->anticollapse = ff_opus_rc_get_raw(rc, 1); @@ -1021,7 +919,7 @@ int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, if ((ret = ff_mdct15_init(&frm->imdct[i], 1, i + 3, -1.0f/32768)) < 0) goto fail; - if ((ret = ff_celt_pvq_init(&frm->pvq)) < 0) + if ((ret = ff_celt_pvq_init(&frm->pvq, 0)) < 0) goto fail; frm->dsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT); |