23 #ifndef AVCODEC_OPUS_H
24 #define AVCODEC_OPUS_H
37 #define MAX_FRAME_SIZE 1275
39 #define MAX_PACKET_DUR 5760
41 #define CELT_SHORT_BLOCKSIZE 120
42 #define CELT_OVERLAP CELT_SHORT_BLOCKSIZE
43 #define CELT_MAX_LOG_BLOCKS 3
44 #define CELT_MAX_FRAME_SIZE (CELT_SHORT_BLOCKSIZE * (1 << CELT_MAX_LOG_BLOCKS))
45 #define CELT_MAX_BANDS 21
46 #define CELT_VECTORS 11
47 #define CELT_ALLOC_STEPS 6
48 #define CELT_FINE_OFFSET 21
49 #define CELT_MAX_FINE_BITS 8
50 #define CELT_NORM_SCALE 16384
51 #define CELT_QTHETA_OFFSET 4
52 #define CELT_QTHETA_OFFSET_TWOPHASE 16
53 #define CELT_DEEMPH_COEFF 0.85000610f
54 #define CELT_POSTFILTER_MINPERIOD 15
55 #define CELT_ENERGY_SILENCE (-28.0f)
57 #define SILK_HISTORY 322
58 #define SILK_MAX_LPC 16
60 #define ROUND_MULL(a,b,s) (((MUL64(a, b) >> ((s) - 1)) + 1) >> 1)
61 #define ROUND_MUL16(a,b) ((MUL16(a, b) + 16384) >> 15)
62 #define opus_ilog(i) (av_log2(i) + !!(i))
64 #define OPUS_TS_HEADER 0x7FE0 // 0x3ff (11 bits)
65 #define OPUS_TS_MASK 0xFFE0 // top 11 bits
68 'O',
'p',
'u',
's',
'H',
'e',
'a',
'd',
69 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
70 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
188 while (rc->
range <= 1<<23) {
196 unsigned int low,
unsigned int high,
199 rc->
value -= scale * (total - high);
200 rc->
range = low ? scale * (high - low)
201 : rc->
range - scale * (total - high);
207 unsigned int k, scale, total, symbol, low, high;
211 scale = rc->
range / total;
212 symbol = rc->
value / scale + 1;
213 symbol = total -
FFMIN(symbol, total);
215 for (k = 0; cdf[k] <= symbol; k++);
217 low = k ? cdf[k-1] : 0;
226 unsigned int k, scale;
229 if (rc->
value >= scale) {
252 unsigned int i, total_bits, rcbuffer, range;
256 range = rc->
range >> (rcbuffer-16);
258 for (i = 0; i < 3; i++) {
260 range = range * range >> 15;
262 rcbuffer = rcbuffer << 1 | bit;
266 return total_bits - rcbuffer;
274 unsigned int value = 0;
295 unsigned int bits, k, scale, total;
298 total = (bits > 8) ? ((size - 1) >> (bits - 8)) + 1 :
size;
300 scale = rc->
range / total;
301 k = rc->
value / scale + 1;
302 k = total -
FFMIN(k, total);
307 return FFMIN(k, size - 1);
316 unsigned int scale, low = 0, center;
318 scale = rc->
range >> 15;
319 center = rc->
value / scale + 1;
320 center = (1 << 15) -
FFMIN(center, 1 << 15);
322 if (center >= symbol) {
325 symbol = 1 + ((32768 - 32 - symbol) * (16384-decay) >> 15);
327 while (symbol > 1 && center >= low + 2 * symbol) {
331 symbol = (((symbol - 2) * decay) >> 15) + 1;
340 if (center < low + symbol)
354 unsigned int k, scale, symbol, total = (k0+1)*3 + k0;
355 scale = rc->
range / total;
356 symbol = rc->
value / scale + 1;
357 symbol = total -
FFMIN(symbol, total);
359 k = (symbol < (k0+1)*3) ? symbol/3 : symbol - (k0+1)*2;
361 opus_rc_update(rc, scale, (k <= k0) ? 3*(k+0) : (k-1-k0) + 3*(k0+1),
362 (k <= k0) ? 3*(k+1) : (k-0-k0) + 3*(k0+1), total);
368 unsigned int k, scale, symbol, total, low, center;
370 total = ((qn>>1) + 1) * ((qn>>1) + 1);
371 scale = rc->
range / total;
372 center = rc->
value / scale + 1;
373 center = total -
FFMIN(center, total);
375 if (center < total >> 1) {
376 k = (
ff_sqrt(8 * center + 1) - 1) >> 1;
377 low = k * (k + 1) >> 1;
380 k = (2*(qn + 1) -
ff_sqrt(8*(total - center - 1) + 1)) >> 1;
381 low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1);
415 float **output,
int coded_channels,
int frame_size,
416 int startband,
int endband);