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,
198 while (rc->
range <= 1<<23) {
206 unsigned int low,
unsigned int high,
209 rc->
value -= scale * (total - high);
210 rc->
range = low ? scale * (high - low)
211 : rc->
range - scale * (total - high);
217 unsigned int k, scale, total, symbol, low, high;
221 scale = rc->
range / total;
222 symbol = rc->
value / scale + 1;
223 symbol = total -
FFMIN(symbol, total);
225 for (k = 0; cdf[k] <= symbol; k++);
227 low = k ? cdf[k-1] : 0;
236 unsigned int k, scale;
239 if (rc->
value >= scale) {
262 unsigned int i, total_bits, rcbuffer, range;
266 range = rc->
range >> (rcbuffer-16);
268 for (i = 0; i < 3; i++) {
270 range = range * range >> 15;
272 rcbuffer = rcbuffer << 1 | bit;
276 return total_bits - rcbuffer;
284 unsigned int value = 0;
292 value = av_mod_uintp2(rc->
rb.
cacheval, count);
305 unsigned int bits, k, scale, total;
308 total = (bits > 8) ? ((size - 1) >> (bits - 8)) + 1 :
size;
310 scale = rc->
range / total;
311 k = rc->
value / scale + 1;
312 k = total -
FFMIN(k, total);
317 return FFMIN(k, size - 1);
326 unsigned int scale, low = 0, center;
328 scale = rc->
range >> 15;
329 center = rc->
value / scale + 1;
330 center = (1 << 15) -
FFMIN(center, 1 << 15);
332 if (center >= symbol) {
335 symbol = 1 + ((32768 - 32 - symbol) * (16384-decay) >> 15);
337 while (symbol > 1 && center >= low + 2 * symbol) {
341 symbol = (((symbol - 2) * decay) >> 15) + 1;
350 if (center < low + symbol)
364 unsigned int k, scale, symbol, total = (k0+1)*3 + k0;
365 scale = rc->
range / total;
366 symbol = rc->
value / scale + 1;
367 symbol = total -
FFMIN(symbol, total);
369 k = (symbol < (k0+1)*3) ? symbol/3 : symbol - (k0+1)*2;
371 opus_rc_update(rc, scale, (k <= k0) ? 3*(k+0) : (k-1-k0) + 3*(k0+1),
372 (k <= k0) ? 3*(k+1) : (k-0-k0) + 3*(k0+1), total);
378 unsigned int k, scale, symbol, total, low, center;
380 total = ((qn>>1) + 1) * ((qn>>1) + 1);
381 scale = rc->
range / total;
382 center = rc->
value / scale + 1;
383 center = total -
FFMIN(center, total);
385 if (center < total >> 1) {
386 k = (
ff_sqrt(8 * center + 1) - 1) >> 1;
387 low = k * (k + 1) >> 1;
390 k = (2*(qn + 1) -
ff_sqrt(8*(total - center - 1) + 1)) >> 1;
391 low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1);
425 float **output,
int coded_channels,
int frame_size,
426 int startband,
int endband);
void ff_celt_flush(CeltContext *s)
AVAudioFifo ** sync_buffers
int frame_count
frame count
static av_always_inline unsigned int opus_rc_getsymbol(OpusRangeCoder *rc, const uint16_t *cdf)
float redundancy_buf[2][960]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_always_inline unsigned int opus_rc_p2model(OpusRangeCoder *rc, unsigned int bits)
int ff_opus_parse_packet(OpusPacket *pkt, const uint8_t *buf, int buf_size, int self_delimited)
Parse Opus packet info from raw packet data.
unsigned int total_read_bits
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
void ff_celt_free(CeltContext **s)
bitstream reader API header.
const float ff_celt_window2[120]
ChannelMap * channel_maps
libswresample public header
static const uint8_t opus_default_extradata[30]
int ff_opus_parse_extradata(AVCodecContext *avctx, OpusContext *s)
The libswresample context.
static av_always_inline unsigned int opus_rc_tell_frac(const OpusRangeCoder *rc)
reference-counted frame API
Context for an Audio FIFO Buffer.
static float distance(float x, float y, int band)
int ff_celt_init(AVCodecContext *avctx, CeltContext **s, int output_channels)
int frame_size[MAX_FRAMES]
frame sizes
int frame_duration
frame duration, in samples @ 48kHz
GLsizei GLboolean const GLfloat * value
int out_dummy_allocated_size
Libavcodec external API header.
static av_always_inline unsigned int opus_rc_stepmodel(OpusRangeCoder *rc, int k0)
void ff_silk_flush(SilkContext *s)
main external API structure.
static av_always_inline void opus_rc_update(OpusRangeCoder *rc, unsigned int scale, unsigned int low, unsigned int high, unsigned int total)
int ff_silk_init(AVCodecContext *avctx, SilkContext **ps, int output_channels)
int config
configuration: tells the audio mode, bandwidth, and frame duration
void ff_silk_free(SilkContext **ps)
int stereo
whether this packet is mono or stereo
int data_size
size of the useful data – packet size - padding
static av_always_inline unsigned int opus_rc_trimodel(OpusRangeCoder *rc, int qn)
static av_always_inline unsigned int opus_getrawbits(OpusRangeCoder *rc, unsigned int count)
CELT: read 1-25 raw bits at the end of the frame, backwards byte-wise.
static av_always_inline void opus_rc_normalize(OpusRangeCoder *rc)
int ff_silk_decode_superframe(SilkContext *s, OpusRangeCoder *rc, float *output[2], enum OpusBandwidth bandwidth, int coded_channels, int duration_ms)
Decode the LP layer of one Opus frame (which may correspond to several SILK frames).
static av_always_inline unsigned int opus_rc_unimodel(OpusRangeCoder *rc, unsigned int size)
CELT: read a uniform distribution.
int ff_celt_decode_frame(CeltContext *s, OpusRangeCoder *rc, float **output, int coded_channels, int frame_size, int startband, int endband)
OpusStreamContext * streams
int packet_size
packet size
OpusRangeCoder redundancy_rc
int frame_offset[MAX_FRAMES]
frame offsets
static av_always_inline unsigned int opus_rc_tell(const OpusRangeCoder *rc)
CELT: estimate bits of entropy that have thus far been consumed for the current CELT frame...
enum OpusBandwidth bandwidth
bandwidth
float * redundancy_output[2]
static av_always_inline int opus_rc_laplace(OpusRangeCoder *rc, unsigned int symbol, int decay)
int code
packet code: specifies the frame layout