37 float prev[2] = { 0 };
45 beta = 1.0f - (4915.0f/32768.0f);
55 if (i < f->start_band || i >= f->
end_band) {
61 if (available >= 15) {
63 int k =
FFMIN(i, 20) << 1;
65 }
else if (available >= 2) {
67 value = (x>>1) ^ -(x&1);
68 }
else if (available >= 1) {
73 prev[j] += beta *
value;
81 for (i = f->
start_band; i < f->end_band; i++) {
91 offset = (q2 + 0.5f) * (1 << (14 - f->
fine_bits[i])) / 16384.0f - 0.5f;
102 for (priority = 0; priority < 2; priority++) {
111 offset = (q2 - 0.5f) * (1 << (14 - f->
fine_bits[i] - 1)) / 16384.0f;
121 int i,
diff = 0, tf_select = 0, tf_changed = 0, tf_select_bit;
125 tf_select_bit = (f->
size != 0 && consumed+bits+1 <= f->
framebits);
127 for (i = f->
start_band; i < f->end_band; i++) {
128 if (consumed+bits+tf_select_bit <= f->framebits) {
141 for (i = f->
start_band; i < f->end_band; i++) {
162 int intensity_stereo_bit = 0;
163 int dual_stereo_bit = 0;
165 int remaining, bandbits;
166 int low, high, total, done;
187 for (i = f->
start_band; i < f->end_band; i++) {
188 int quanta, band_dynalloc;
193 quanta =
FFMIN(quanta << 3,
FFMAX(6 << 3, quanta));
194 band_dynalloc = dynalloc;
195 while (consumed + (band_dynalloc<<3) < totalbits && boost[i] < cap[i]) {
207 dynalloc =
FFMAX(2, dynalloc - 1);
211 if (consumed + (6 << 3) <= totalbits)
218 totalbits >= ((f->
size + 2) << 3))
223 if (totalbits >= 1 << 3)
225 totalbits -= skip_bit;
230 if (intensity_stereo_bit <= totalbits) {
231 totalbits -= intensity_stereo_bit;
232 if (totalbits >= 1 << 3) {
233 dual_stereo_bit = 1 << 3;
237 intensity_stereo_bit = 0;
240 for (i = f->
start_band; i < f->end_band; i++) {
241 int trim = alloctrim - 5 - f->
size;
244 int scale = duration + f->
channels - 1;
251 trim_offset[i] = trim * (band << scale) >> 6;
260 while (low <= high) {
261 int center = (low + high) >> 1;
269 bandbits =
FFMAX(0, bandbits + trim_offset[i]);
270 bandbits += boost[i];
272 if (bandbits >= threshold[i] || done) {
274 total +=
FFMIN(bandbits, cap[i]);
275 }
else if (bandbits >= f->
channels << 3)
279 if (total > totalbits)
286 for (i = f->
start_band; i < f->end_band; i++) {
294 bits1[i] =
FFMAX(0, bits1[i] + trim_offset[i]);
296 bits2[i] =
FFMAX(0, bits2[i] + trim_offset[i]);
298 bits1[i] += boost[i];
299 bits2[i] += boost[i];
303 bits2[i] =
FFMAX(0, bits2[i] - bits1[i]);
310 int center = (low + high) >> 1;
316 if (bandbits >= threshold[j] || done) {
318 total +=
FFMIN(bandbits, cap[j]);
319 }
else if (bandbits >= f->
channels << 3)
322 if (total > totalbits)
332 if (bandbits >= threshold[i] || done)
335 bandbits = (bandbits >= f->
channels << 3) ?
338 bandbits =
FFMIN(bandbits, cap[i]);
348 if (j == skip_start_band) {
350 totalbits += skip_bit;
355 remaining = totalbits - total;
363 if (allocation >=
FFMAX(threshold[j], (f->
channels + 1) <<3 )) {
368 allocation -= 1 << 3;
373 if (intensity_stereo_bit) {
374 total -= intensity_stereo_bit;
376 total += intensity_stereo_bit;
386 if (intensity_stereo_bit)
390 totalbits += dual_stereo_bit;
391 else if (dual_stereo_bit)
395 remaining = totalbits - total;
398 for (i = f->
start_band; i < f->coded_bands; i++) {
405 for (i = f->
start_band; i < f->coded_bands; i++) {
407 int prev_extra = extrabits;
408 f->
pulses[i] += extrabits;
416 int fine_bits, max_bits;
419 f->
pulses[i] -= extrabits;
430 if (f->
pulses[i] + offset < 2 * (dof << 3))
432 else if (f->
pulses[i] + offset < 3 * (dof << 3))
435 fine_bits = (f->
pulses[i] + offset + (dof << 2)) / (dof << 3);
439 max_bits =
FFMAX(max_bits, 0);
441 f->
fine_bits[i] = av_clip(fine_bits, 0, max_bits);
452 f->
pulses[i] -= extrabits;
465 extrabits -= fineextra;
482 for (i = f->
start_band; i < f->end_band; i++) {
499 float x0, x1, x2, x3, x4;
521 x0 = data[i - T1 + 2];
523 data[i] += (1.0 - w) * g00 * data[i - T0] +
524 (1.0 - w) * g01 * (data[i - T0 - 1] + data[i - T0 + 1]) +
525 (1.0 - w) * g02 * (data[i - T0 - 2] + data[i - T0 + 2]) +
527 w * g11 * (x1 + x3) +
540 float x0, x1, x2, x3, x4;
543 if (block->
pf_gains[0] == 0.0 || len <= 0)
555 for (i = 0; i <
len; i++) {
556 x0 = data[i - T + 2];
600 if (has_postfilter) {
602 int tapset, octave, period;
610 for (i = 0; i < 2; i++) {
615 block->
pf_gains_new[1] = gain * ff_celt_postfilter_taps[tapset][1];
616 block->
pf_gains_new[2] = gain * ff_celt_postfilter_taps[tapset][2];
630 for (i = f->
start_band; i < f->end_band; i++) {
635 float thresh, sqrt_1;
640 thresh =
exp2f(-1.0 - 0.125f * depth);
653 Ediff = block->
energy[i] -
FFMIN(prev[0], prev[1]);
654 Ediff =
FFMAX(0, Ediff);
658 r =
exp2f(1 - Ediff);
661 r =
FFMIN(thresh, r) * sqrt_1;
662 for (k = 0; k < 1 << f->
size; k++) {
667 xptr[(j << f->
size) + k] = (
celt_rng(f) & 0x8000) ? r : -r;
680 float lowband_scratch[8 * 22];
681 float norm[2 * 8 * 100];
685 int update_lowband = 1;
686 int lowband_offset = 0;
693 for (i = f->
start_band; i < f->end_band; i++) {
701 float *norm2 = norm + 8 * 100;
702 int effective_lowband = -1;
709 if (i <= f->coded_bands - 1) {
715 (update_lowband || lowband_offset == 0))
722 int foldstart, foldend;
727 foldstart = lowband_offset;
729 foldend = lowband_offset - 1;
733 for (j = foldstart; j < foldend; j++) {
743 norm[j] = (norm[j] + norm2[j]) / 2;
748 effective_lowband != -1 ? norm + (effective_lowband << f->
size) :
NULL, f->
size,
749 norm + band_offset, 0, 1.0f, lowband_scratch, cm[0]);
752 effective_lowband != -1 ? norm2 + (effective_lowband << f->
size) :
NULL, f->
size,
753 norm2 + band_offset, 0, 1.0f, lowband_scratch, cm[1]);
756 effective_lowband != -1 ? norm + (effective_lowband << f->
size) :
NULL, f->
size,
757 norm + band_offset, 0, 1.0f, lowband_scratch, cm[0]|cm[1]);
766 update_lowband = (b > band_size << 3);
772 int start_band,
int end_band)
774 int i, j, downmix = 0;
778 if (channels != 1 && channels != 2) {
783 if (start_band < 0 || start_band > end_band || end_band >
CELT_MAX_BANDS) {
785 start_band, end_band);
817 else if (consumed == 1)
873 for (i = 0; i < 2; i++) {
889 for (j = 0; j < f->
blocks; j++) {
906 const float tmp = block->
buf[1024 - frame_size + j] + m;
917 for (i = 0; i < 2; i++ ) {
950 for (i = 0; i < 2; i++) {
957 memset(block->
buf, 0,
sizeof(block->
buf));
992 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.
static float alpha(float a)
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...
const float ff_celt_postfilter_taps[3][3]
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.
const float * ff_celt_window
static void process_anticollapse(CeltFrame *f, CeltBlock *block, float *X)
int av_cold ff_celt_pvq_init(CeltPVQ **pvq)
av_cold int ff_mdct15_init(MDCT15Context **ps, int inverse, int N, double scale)
#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[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* imdct_half)(struct MDCT15Context *s, float *dst, const float *src, ptrdiff_t stride)
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
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)
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)
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
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 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.
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)
av_cold void ff_mdct15_uninit(MDCT15Context **ps)
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[]
void av_cold ff_celt_pvq_uninit(CeltPVQ **pvq)
static const uint8_t bits1[81]
static av_always_inline uint32_t opus_rc_tell_frac(const OpusRangeCoder *rc)