FFmpeg
opus_celt.h
Go to the documentation of this file.
1 /*
2  * Opus decoder/demuxer common functions
3  * Copyright (c) 2012 Andrew D'Addesio
4  * Copyright (c) 2013-2014 Mozilla Corporation
5  * Copyright (c) 2016 Rostislav Pehlivanov <atomnuker@gmail.com>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #ifndef AVCODEC_OPUS_CELT_H
25 #define AVCODEC_OPUS_CELT_H
26 
27 #include <float.h>
28 
29 #include "opus.h"
30 #include "opus_pvq.h"
31 #include "opusdsp.h"
32 
33 #include "mdct15.h"
34 #include "libavutil/float_dsp.h"
35 #include "libavutil/libm.h"
36 #include "libavutil/mem_internal.h"
37 
38 #define CELT_VECTORS 11
39 #define CELT_ALLOC_STEPS 6
40 #define CELT_FINE_OFFSET 21
41 #define CELT_MAX_FINE_BITS 8
42 #define CELT_NORM_SCALE 16384
43 #define CELT_QTHETA_OFFSET 4
44 #define CELT_QTHETA_OFFSET_TWOPHASE 16
45 #define CELT_POSTFILTER_MINPERIOD 15
46 #define CELT_ENERGY_SILENCE (-28.0f)
47 
48 typedef struct CeltPVQ CeltPVQ;
49 
50 enum CeltSpread {
55 };
56 
62 
64 };
65 
66 typedef struct CeltBlock {
71 
73 
74  /* buffer for mdct output + postfilter */
75  DECLARE_ALIGNED(32, float, buf)[2048];
77 
78  /* Used by the encoder */
81 
82  /* postfilter parameters */
84  float pf_gains_new[3];
85  int pf_period;
86  float pf_gains[3];
88  float pf_gains_old[3];
89 
90  float emph_coeff;
91 } CeltBlock;
92 
93 struct CeltFrame {
94  // constant values that do not change during context lifetime
96  MDCT15Context *imdct[4];
101  int channels;
104 
107  int end_band;
109  int transient;
110  int pfilter;
114  int alloc_boost[CELT_MAX_BANDS];
115  int blocks; /* number of iMDCT blocks in the frame, depends on transient */
116  int blocksize; /* size of each block */
117  int silence; /* Frame is filled with silence */
118  int anticollapse_needed; /* Whether to expect an anticollapse bit */
119  int anticollapse; /* Encoded anticollapse bit */
122  int flushed;
123  uint32_t seed;
124  enum CeltSpread spread;
125 
126  /* Encoder PF coeffs */
130  float pf_gain;
131 
132  /* Bit allocation */
136  int caps [CELT_MAX_BANDS];
137  int fine_bits [CELT_MAX_BANDS];
138  int fine_priority[CELT_MAX_BANDS];
140  int tf_change [CELT_MAX_BANDS];
141 };
142 
143 /* LCG for noise generation */
145 {
146  f->seed = 1664525 * f->seed + 1013904223;
147  return f->seed;
148 }
149 
150 static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
151 {
152  int i;
153  float g = 1e-15f;
154  for (i = 0; i < N; i++)
155  g += X[i] * X[i];
156  g = gain / sqrtf(g);
157 
158  for (i = 0; i < N; i++)
159  X[i] *= g;
160 }
161 
162 int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels,
163  int apply_phase_inv);
164 
165 void ff_celt_free(CeltFrame **f);
166 
167 void ff_celt_flush(CeltFrame *f);
168 
170  int coded_channels, int frame_size, int startband, int endband);
171 
172 #endif /* AVCODEC_OPUS_CELT_H */
int channels
Definition: opus_celt.h:101
int anticollapse
Definition: opus_celt.h:119
int framebits
Definition: opus_celt.h:133
int remaining2
Definition: opus_celt.h:135
float coeffs[CELT_MAX_FRAME_SIZE]
Definition: opus_celt.h:76
const char * g
Definition: vf_curves.c:117
int output_channels
Definition: opus_celt.h:102
static const int8_t pulses[4]
Number of non-zero pulses in the MP-MLQ excitation.
Definition: g723_1.h:260
float pf_gains_new[3]
Definition: opus_celt.h:84
Definition: vf_addroi.c:26
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int coded_channels, int frame_size, int startband, int endband)
Definition: opus_celt.c:320
int pf_period
Definition: opus_celt.h:128
#define N
Definition: af_mcompand.c:54
int pf_period_new
Definition: opus_celt.h:83
int flushed
Definition: opus_celt.h:122
The exact code depends on how similar the blocks are and how related they are to the block
uint8_t
#define CELT_OVERLAP
Definition: opus.h:43
int silence
Definition: opus_celt.h:117
#define f(width, name)
Definition: cbs_vp9.c:255
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:117
int dual_stereo
Definition: opus_celt.h:121
ptrdiff_t size
Definition: opengl_enc.c:100
int coded_bands
Definition: opus_celt.h:108
float lin_energy[CELT_MAX_BANDS]
Definition: opus_celt.h:68
int skip_band_floor
Definition: opus_celt.h:111
#define FFALIGN(x, a)
Definition: macros.h:48
int end_band
Definition: opus_celt.h:107
float samples[FFALIGN(CELT_MAX_FRAME_SIZE, 16)]
Definition: opus_celt.h:80
float pf_gains[3]
Definition: opus_celt.h:86
int start_band
Definition: opus_celt.h:106
float emph_coeff
Definition: opus_celt.h:90
int pfilter
Definition: opus_celt.h:110
int apply_phase_inv
Definition: opus_celt.h:103
int anticollapse_needed
Definition: opus_celt.h:118
float pf_gain
Definition: opus_celt.h:130
AVCodecContext * avctx
Definition: opus_celt.h:95
uint32_t seed
Definition: opus_celt.h:123
void ff_celt_flush(CeltFrame *f)
Definition: opus_celt.c:490
int blocks
Definition: opus_celt.h:115
CeltBlockSize
Definition: opus_celt.h:57
float error_energy[CELT_MAX_BANDS]
Definition: opus_celt.h:69
int frame_size
Definition: mxfenc.c:2206
#define CELT_MAX_BANDS
Definition: opus.h:46
int pf_tapset
Definition: opus_celt.h:129
main external API structure.
Definition: avcodec.h:536
int pf_period_old
Definition: opus_celt.h:87
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, int apply_phase_inv)
Definition: opus_celt.c:538
AVFloatDSPContext * dsp
Definition: opus_celt.h:97
Replacements for frequently missing libm functions.
OpusDSP opusdsp
Definition: opus_celt.h:100
CeltPVQ * pvq
Definition: opus_celt.h:99
CeltSpread
Definition: opus_celt.h:50
static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
Definition: opus_celt.h:150
float pf_gains_old[3]
Definition: opus_celt.h:88
int remaining
Definition: opus_celt.h:134
float energy[CELT_MAX_BANDS]
Definition: opus_celt.h:67
static av_always_inline uint32_t celt_rng(CeltFrame *f)
Definition: opus_celt.h:144
void ff_celt_free(CeltFrame **f)
Definition: opus_celt.c:521
int tf_select
Definition: opus_celt.h:112
int blocksize
Definition: opus_celt.h:116
#define CELT_MAX_FRAME_SIZE
Definition: opus.h:45
#define av_always_inline
Definition: attributes.h:45
int alloc_trim
Definition: opus_celt.h:113
int pf_period
Definition: opus_celt.h:85
float prev_energy[2][CELT_MAX_BANDS]
Definition: opus_celt.h:70
uint8_t collapse_masks[CELT_MAX_BANDS]
Definition: opus_celt.h:72
int pf_octave
Definition: opus_celt.h:127
float overlap[FFALIGN(CELT_OVERLAP, 16)]
Definition: opus_celt.h:79
int i
Definition: input.c:407
int intensity_stereo
Definition: opus_celt.h:120
float buf[2048]
Definition: opus_celt.h:75