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)) 123 float silk_buf[2][960];
124 float *silk_output[2];
126 float *celt_output[2];
128 float redundancy_buf[2][960];
129 float *redundancy_output[2];
189 while (rc->
range <= 1<<23) {
197 unsigned int low,
unsigned int high,
200 rc->
value -= scale * (total - high);
201 rc->
range = low ? scale * (high - low)
202 : rc->
range - scale * (total - high);
208 unsigned int k, scale, total, symbol, low, high;
212 scale = rc->
range / total;
213 symbol = rc->
value / scale + 1;
214 symbol = total -
FFMIN(symbol, total);
216 for (k = 0; cdf[k] <= symbol; k++);
218 low = k ? cdf[k-1] : 0;
227 unsigned int k, scale;
230 if (rc->
value >= scale) {
253 unsigned int i, total_bits, rcbuffer, range;
257 range = rc->
range >> (rcbuffer-16);
259 for (i = 0; i < 3; i++) {
261 range = range * range >> 15;
263 rcbuffer = rcbuffer << 1 | bit;
267 return total_bits - rcbuffer;
275 unsigned int value = 0;
296 unsigned int bits, k, scale, total;
299 total = (bits > 8) ? ((size - 1) >> (bits - 8)) + 1 :
size;
301 scale = rc->
range / total;
302 k = rc->
value / scale + 1;
303 k = total -
FFMIN(k, total);
308 return FFMIN(k, size - 1);
317 unsigned int scale, low = 0, center;
319 scale = rc->
range >> 15;
320 center = rc->
value / scale + 1;
321 center = (1 << 15) -
FFMIN(center, 1 << 15);
323 if (center >= symbol) {
326 symbol = 1 + ((32768 - 32 - symbol) * (16384-decay) >> 15);
328 while (symbol > 1 && center >= low + 2 * symbol) {
332 symbol = (((symbol - 2) * decay) >> 15) + 1;
341 if (center < low + symbol)
355 unsigned int k, scale, symbol, total = (k0+1)*3 + k0;
356 scale = rc->
range / total;
357 symbol = rc->
value / scale + 1;
358 symbol = total -
FFMIN(symbol, total);
360 k = (symbol < (k0+1)*3) ? symbol/3 : symbol - (k0+1)*2;
362 opus_rc_update(rc, scale, (k <= k0) ? 3*(k+0) : (k-1-k0) + 3*(k0+1),
363 (k <= k0) ? 3*(k+1) : (k-0-k0) + 3*(k0+1), total);
369 unsigned int k, scale, symbol, total, low, center;
371 total = ((qn>>1) + 1) * ((qn>>1) + 1);
372 scale = rc->
range / total;
373 center = rc->
value / scale + 1;
374 center = total -
FFMIN(center, total);
376 if (center < total >> 1) {
377 k = (
ff_sqrt(8 * center + 1) - 1) >> 1;
378 low = k * (k + 1) >> 1;
381 k = (2*(qn + 1) -
ff_sqrt(8*(total - center - 1) + 1)) >> 1;
382 low = total - ((qn + 1 - k) * (qn + 2 - k) >> 1);
416 float **output,
int coded_channels,
int frame_size,
417 int startband,
int endband);
AVAudioResampleContext * avr
void ff_celt_flush(CeltContext *s)
AVAudioFifo ** sync_buffers
int frame_count
configuration: tells the audio mode, bandwidth, and frame duration
static av_always_inline unsigned int opus_rc_getsymbol(OpusRangeCoder *rc, const uint16_t *cdf)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define DECLARE_ALIGNED(n, t, v)
static av_always_inline unsigned int opus_rc_p2model(OpusRangeCoder *rc, unsigned int bits)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
int vbr
whether this packet is mono or stereo
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
void ff_celt_free(CeltContext **s)
bitstream reader API header.
const float ff_celt_window2[120]
static const uint8_t frame_size[4]
ChannelMap * channel_maps
int ff_opus_parse_extradata(AVCodecContext *avctx, OpusContext *s)
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_duration
frame sizes
int out_dummy_allocated_size
Libavcodec external API header.
static av_always_inline unsigned int opus_rc_stepmodel(OpusRangeCoder *rc, int k0)
static av_const unsigned int ff_sqrt(unsigned int a)
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)
void ff_silk_free(SilkContext **ps)
int stereo
packet code: specifies the frame layout
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
OpusRangeCoder redundancy_rc
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...
static av_always_inline int opus_rc_laplace(OpusRangeCoder *rc, unsigned int symbol, int decay)
int code
size of the useful data – packet size - padding