45 beta = 1.0f - 4915.0f/32768.0f;
59 if (i < f->start_band || i >= f->
end_band) {
65 if (available >= 15) {
67 int k =
FFMIN(i, 20) << 1;
69 }
else if (available >= 2) {
71 value = (x>>1) ^ -(x&1);
72 }
else if (available >= 1) {
77 prev[j] += beta *
value;
85 for (i = f->
start_band; i < f->end_band; i++) {
95 offset = (q2 + 0.5f) * (1 << (14 - f->
fine_bits[i])) / 16384.0f - 0.5f;
106 for (priority = 0; priority < 2; priority++) {
115 offset = (q2 - 0.5f) * (1 << (14 - f->
fine_bits[i] - 1)) / 16384.0f;
125 int i,
diff = 0, tf_select = 0, tf_changed = 0, tf_select_bit;
129 tf_select_bit = (f->
size != 0 && consumed+bits+1 <= f->
framebits);
131 for (i = f->
start_band; i < f->end_band; i++) {
132 if (consumed+bits+tf_select_bit <= f->framebits) {
145 for (i = f->
start_band; i < f->end_band; i++) {
166 int intensity_stereo_bit = 0;
167 int dual_stereo_bit = 0;
169 int remaining, bandbits;
170 int low, high, total, done;
191 for (i = f->
start_band; i < f->end_band; i++) {
192 int quanta, band_dynalloc;
197 quanta =
FFMIN(quanta << 3,
FFMAX(6 << 3, quanta));
198 band_dynalloc = dynalloc;
199 while (consumed + (band_dynalloc<<3) < totalbits && boost[i] < cap[i]) {
211 dynalloc =
FFMAX(2, dynalloc - 1);
215 if (consumed + (6 << 3) <= totalbits)
222 totalbits >= ((f->
size + 2) << 3))
227 if (totalbits >= 1 << 3)
229 totalbits -= skip_bit;
234 if (intensity_stereo_bit <= totalbits) {
235 totalbits -= intensity_stereo_bit;
236 if (totalbits >= 1 << 3) {
237 dual_stereo_bit = 1 << 3;
241 intensity_stereo_bit = 0;
244 for (i = f->
start_band; i < f->end_band; i++) {
245 int trim = alloctrim - 5 - f->
size;
248 int scale = duration + f->
channels - 1;
255 trim_offset[i] = trim * (band << scale) >> 6;
264 while (low <= high) {
265 int center = (low + high) >> 1;
273 bandbits =
FFMAX(0, bandbits + trim_offset[i]);
274 bandbits += boost[i];
276 if (bandbits >= threshold[i] || done) {
278 total +=
FFMIN(bandbits, cap[i]);
279 }
else if (bandbits >= f->
channels << 3)
283 if (total > totalbits)
290 for (i = f->
start_band; i < f->end_band; i++) {
298 bits1[i] =
FFMAX(0, bits1[i] + trim_offset[i]);
300 bits2[i] =
FFMAX(0, bits2[i] + trim_offset[i]);
302 bits1[i] += boost[i];
303 bits2[i] += boost[i];
307 bits2[i] =
FFMAX(0, bits2[i] - bits1[i]);
314 int center = (low + high) >> 1;
320 if (bandbits >= threshold[j] || done) {
322 total +=
FFMIN(bandbits, cap[j]);
323 }
else if (bandbits >= f->
channels << 3)
326 if (total > totalbits)
336 if (bandbits >= threshold[i] || done)
339 bandbits = (bandbits >= f->
channels << 3) ?
342 bandbits =
FFMIN(bandbits, cap[i]);
352 if (j == skip_start_band) {
354 totalbits += skip_bit;
359 remaining = totalbits - total;
367 if (allocation >=
FFMAX(threshold[j], (f->
channels + 1) <<3 )) {
372 allocation -= 1 << 3;
377 if (intensity_stereo_bit) {
378 total -= intensity_stereo_bit;
380 total += intensity_stereo_bit;
390 if (intensity_stereo_bit)
394 totalbits += dual_stereo_bit;
395 else if (dual_stereo_bit)
399 remaining = totalbits - total;
402 for (i = f->
start_band; i < f->coded_bands; i++) {
409 for (i = f->
start_band; i < f->coded_bands; i++) {
411 int prev_extra = extrabits;
412 f->
pulses[i] += extrabits;
420 int fine_bits, max_bits;
423 f->
pulses[i] -= extrabits;
434 if (f->
pulses[i] + offset < 2 * (dof << 3))
436 else if (f->
pulses[i] + offset < 3 * (dof << 3))
439 fine_bits = (f->
pulses[i] + offset + (dof << 2)) / (dof << 3);
443 max_bits =
FFMAX(max_bits, 0);
445 f->
fine_bits[i] = av_clip(fine_bits, 0, max_bits);
456 f->
pulses[i] -= extrabits;
469 extrabits -= fineextra;
486 for (i = f->
start_band; i < f->end_band; i++) {
503 float x0, x1, x2, x3, x4;
525 x0 = data[i - T1 + 2];
527 data[i] += (1.0 - w) * g00 * data[i - T0] +
528 (1.0 - w) * g01 * (data[i - T0 - 1] + data[i - T0 + 1]) +
529 (1.0 - w) * g02 * (data[i - T0 - 2] + data[i - T0 + 2]) +
531 w * g11 * (x1 + x3) +
544 float x0, x1, x2, x3, x4;
547 if (block->
pf_gains[0] == 0.0 || len <= 0)
559 for (i = 0; i <
len; i++) {
560 x0 = data[i - T + 2];
597 static const float postfilter_taps[3][3] = {
598 { 0.3066406250f, 0.2170410156f, 0.1296386719f },
599 { 0.4638671875f, 0.2680664062f, 0.0 },
600 { 0.7998046875f, 0.1000976562f, 0.0 }
609 if (has_postfilter) {
611 int tapset, octave, period;
619 for (i = 0; i < 2; i++) {
623 block->
pf_gains_new[0] = gain * postfilter_taps[tapset][0];
624 block->
pf_gains_new[1] = gain * postfilter_taps[tapset][1];
625 block->
pf_gains_new[2] = gain * postfilter_taps[tapset][2];
639 for (i = f->
start_band; i < f->end_band; i++) {
644 float thresh, sqrt_1;
649 thresh =
exp2f(-1.0 - 0.125f * depth);
662 Ediff = block->
energy[i] -
FFMIN(prev[0], prev[1]);
663 Ediff =
FFMAX(0, Ediff);
670 r =
FFMIN(thresh, r) * sqrt_1;
671 for (k = 0; k < 1 << f->
size; k++) {
676 xptr[(j << f->
size) + k] = (
celt_rng(f) & 0x8000) ? r : -r;
689 float lowband_scratch[8 * 22];
690 float norm[2 * 8 * 100];
694 int update_lowband = 1;
695 int lowband_offset = 0;
702 for (i = f->
start_band; i < f->end_band; i++) {
709 float *norm2 = norm + 8 * 100;
710 int effective_lowband = -1;
718 if (i <= f->coded_bands - 1) {
725 (update_lowband || lowband_offset == 0))
732 int foldstart, foldend;
737 foldstart = lowband_offset;
739 foldend = lowband_offset - 1;
743 for (j = foldstart; j < foldend; j++) {
750 cm[0] = cm[1] = (1 << f->
blocks) - 1;
756 norm[j] = (norm[j] + norm2[j]) / 2;
761 effective_lowband != -1 ? norm + (effective_lowband << f->
size) :
NULL, f->
size,
762 norm + band_offset, 0, 1.0f, lowband_scratch, cm[0]);
765 effective_lowband != -1 ? norm2 + (effective_lowband << f->
size) :
NULL, f->
size,
766 norm2 + band_offset, 0, 1.0f, lowband_scratch, cm[1]);
769 effective_lowband != -1 ? norm + (effective_lowband << f->
size) :
NULL, f->
size,
770 norm + band_offset, 0, 1.0f, lowband_scratch, cm[0]|cm[1]);
779 update_lowband = (b > band_size << 3);
785 int start_band,
int end_band)
790 float imdct_scale = 1.0;
792 if (channels != 1 && channels != 2) {
797 if (start_band < 0 || start_band > end_band || end_band >
CELT_MAX_BANDS) {
799 start_band, end_band);
831 else if (consumed == 1)
887 for (i = 0; i < 2; i++) {
903 for (j = 0; j < f->
blocks; j++) {
917 float tmp = block->
buf[1024 - frame_size + j] + m;
919 output[i][j] = tmp / 32768.;
927 for (i = 0; i < 2; i++ ) {
960 for (i = 0; i < 2; i++) {
967 memset(block->
buf, 0,
sizeof(block->
buf));
1000 if (output_channels != 1 && output_channels != 2) {
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int channels, int frame_size, int start_band, int end_band)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
ptrdiff_t const GLvoid * data
static void celt_postfilter(CeltFrame *f, CeltBlock *block)
const uint8_t ff_celt_coarse_energy_dist[4][2][42]
const uint8_t ff_celt_log_freq_range[]
float coeffs[CELT_MAX_FRAME_SIZE]
const uint8_t ff_celt_freq_bands[]
uint32_t ff_opus_rc_dec_log(OpusRangeCoder *rc, uint32_t bits)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static void celt_postfilter_apply(CeltBlock *block, float *data, int len)
void(* vector_fmac_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float and add to destination vector.
static void celt_denormalize(CeltFrame *f, CeltBlock *block, float *data)
int fine_priority[CELT_MAX_BANDS]
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
static void process_anticollapse(CeltFrame *f, CeltBlock *block, float *X)
av_cold int ff_mdct15_init(MDCT15Context **ps, int inverse, int N, double scale)
Init an (i)MDCT of the length 2 * 15 * (2^N)
#define CELT_POSTFILTER_MINPERIOD
#define CELT_MAX_LOG_BLOCKS
static const uint8_t bits2[81]
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels)
const uint8_t ff_celt_log2_frac[]
static double alpha(void *priv, double x, double y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_celt_flush(CeltFrame *f)
int flags
AV_CODEC_FLAG_*.
static void celt_decode_allocation(CeltFrame *f, OpusRangeCoder *rc)
static void celt_decode_tf_changes(CeltFrame *f, OpusRangeCoder *rc)
int tf_change[CELT_MAX_BANDS]
int pulses[CELT_MAX_BANDS]
static const uint8_t offset[127][2]
int fine_bits[CELT_MAX_BANDS]
uint32_t ff_opus_rc_dec_cdf(OpusRangeCoder *rc, const uint16_t *cdf)
void(* imdct_half)(struct MDCT15Context *s, float *dst, const float *src, ptrdiff_t src_stride, float scale)
Calculate the middle half of the iMDCT.
const int8_t ff_celt_tf_select[4][2][2][2]
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define CELT_SHORT_BLOCKSIZE
static void celt_decode_bands(CeltFrame *f, OpusRangeCoder *rc)
GLsizei GLboolean const GLfloat * value
void ff_celt_free(CeltFrame **f)
int ff_opus_rc_dec_laplace(OpusRangeCoder *rc, uint32_t symbol, int decay)
const uint8_t ff_celt_freq_range[]
static void celt_decode_coarse_energy(CeltFrame *f, OpusRangeCoder *rc)
static void celt_postfilter_apply_transition(CeltBlock *block, float *data)
#define FF_ARRAY_ELEMS(a)
const float ff_celt_window[120]
const uint8_t ff_celt_static_caps[4][2][21]
static void celt_decode_fine_energy(CeltFrame *f, OpusRangeCoder *rc)
const uint16_t ff_celt_model_spread[]
main external API structure.
const float ff_celt_window2[120]
static av_always_inline uint32_t opus_rc_tell(const OpusRangeCoder *rc)
CELT: estimate bits of entropy that have thus far been consumed for the current CELT frame...
#define CELT_MAX_FINE_BITS
#define CELT_ENERGY_SILENCE
const uint8_t ff_celt_static_alloc[11][21]
uint32_t ff_opus_rc_get_raw(OpusRangeCoder *rc, uint32_t count)
CELT: read 1-25 raw bits at the end of the frame, backwards byte-wise.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
const uint16_t ff_celt_model_energy_small[]
const uint16_t ff_celt_model_alloc_trim[]
float energy[CELT_MAX_BANDS]
const float ff_celt_beta_coef[]
static av_always_inline uint32_t celt_rng(CeltFrame *f)
uint32_t ff_celt_decode_band(CeltFrame *f, OpusRangeCoder *rc, const int band, float *X, float *Y, int N, int b, uint32_t blocks, float *lowband, int duration, float *lowband_out, int level, float gain, float *lowband_scratch, int fill)
av_cold void ff_mdct15_uninit(MDCT15Context **ps)
Frees a context.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static void celt_decode_final_energy(CeltFrame *f, OpusRangeCoder *rc)
const float ff_celt_alpha_coef[]
static int16_t block1[64]
uint32_t ff_opus_rc_dec_uint(OpusRangeCoder *rc, uint32_t size)
CELT: read a uniform distribution.
const float ff_celt_mean_energy[]
static int parse_postfilter(CeltFrame *f, OpusRangeCoder *rc, int consumed)
float prev_energy[2][CELT_MAX_BANDS]
uint8_t collapse_masks[CELT_MAX_BANDS]
const uint16_t ff_celt_model_tapset[]
static const uint8_t bits1[81]
static av_always_inline uint32_t opus_rc_tell_frac(const OpusRangeCoder *rc)