FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
32 #include "mdct15.h"
33 #include "libavutil/float_dsp.h"
34 #include "libavutil/libm.h"
35 
36 #define CELT_VECTORS 11
37 #define CELT_ALLOC_STEPS 6
38 #define CELT_FINE_OFFSET 21
39 #define CELT_MAX_FINE_BITS 8
40 #define CELT_NORM_SCALE 16384
41 #define CELT_QTHETA_OFFSET 4
42 #define CELT_QTHETA_OFFSET_TWOPHASE 16
43 #define CELT_EMPH_COEFF 0.85000610f
44 #define CELT_POSTFILTER_MINPERIOD 15
45 #define CELT_ENERGY_SILENCE (-28.0f)
46 
47 typedef struct CeltPVQ CeltPVQ;
48 
49 enum CeltSpread {
54 };
55 
61 
63 };
64 
65 typedef struct CeltBlock {
70 
72 
73  /* buffer for mdct output + postfilter */
74  DECLARE_ALIGNED(32, float, buf)[2048];
76 
77  /* Used by the encoder */
80 
81  /* postfilter parameters */
83  float pf_gains_new[3];
84  int pf_period;
85  float pf_gains[3];
87  float pf_gains_old[3];
88 
89  float emph_coeff;
90 } CeltBlock;
91 
92 struct CeltFrame {
93  // constant values that do not change during context lifetime
99  int channels;
101 
104  int end_band;
106  int transient;
107  int pfilter;
112  int blocks; /* number of iMDCT blocks in the frame, depends on transient */
113  int blocksize; /* size of each block */
114  int silence; /* Frame is filled with silence */
115  int anticollapse_needed; /* Whether to expect an anticollapse bit */
116  int anticollapse; /* Encoded anticollapse bit */
119  int flushed;
120  uint32_t seed;
122 
123  /* Encoder PF coeffs */
127  float pf_gain;
128 
129  /* Bit allocation */
138 };
139 
140 /* LCG for noise generation */
142 {
143  f->seed = 1664525 * f->seed + 1013904223;
144  return f->seed;
145 }
146 
147 static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
148 {
149  int i;
150  float g = 1e-15f;
151  for (i = 0; i < N; i++)
152  g += X[i] * X[i];
153  g = gain / sqrtf(g);
154 
155  for (i = 0; i < N; i++)
156  X[i] *= g;
157 }
158 
159 int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels);
160 
161 void ff_celt_free(CeltFrame **f);
162 
163 void ff_celt_flush(CeltFrame *f);
164 
165 int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output,
166  int coded_channels, int frame_size, int startband, int endband);
167 
168 #endif /* AVCODEC_OPUS_CELT_H */
int channels
Definition: opus_celt.h:99
int anticollapse
Definition: opus_celt.h:116
int framebits
Definition: opus_celt.h:130
int remaining2
Definition: opus_celt.h:132
float coeffs[CELT_MAX_FRAME_SIZE]
Definition: opus_celt.h:75
const char * g
Definition: vf_curves.c:112
int output_channels
Definition: opus_celt.h:100
float pf_gains_new[3]
Definition: opus_celt.h:83
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:770
int pf_period
Definition: opus_celt.h:125
int pf_period_new
Definition: opus_celt.h:82
int fine_priority[CELT_MAX_BANDS]
Definition: opus_celt.h:135
CeltBlock block[2]
Definition: opus_celt.h:97
int flushed
Definition: opus_celt.h:119
uint8_t
#define CELT_OVERLAP
Definition: opus.h:42
int silence
Definition: opus_celt.h:114
#define N
Definition: vf_pp7.c:73
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:104
int dual_stereo
Definition: opus_celt.h:118
int coded_bands
Definition: opus_celt.h:105
float lin_energy[CELT_MAX_BANDS]
Definition: opus_celt.h:67
int skip_band_floor
Definition: opus_celt.h:108
#define FFALIGN(x, a)
Definition: macros.h:48
int end_band
Definition: opus_celt.h:104
float samples[FFALIGN(CELT_MAX_FRAME_SIZE, 16)]
Definition: opus_celt.h:79
float pf_gains[3]
Definition: opus_celt.h:85
int alloc_boost[CELT_MAX_BANDS]
Definition: opus_celt.h:111
int start_band
Definition: opus_celt.h:103
int tf_change[CELT_MAX_BANDS]
Definition: opus_celt.h:137
float emph_coeff
Definition: opus_celt.h:89
int pulses[CELT_MAX_BANDS]
Definition: opus_celt.h:136
int pfilter
Definition: opus_celt.h:107
int anticollapse_needed
Definition: opus_celt.h:115
int fine_bits[CELT_MAX_BANDS]
Definition: opus_celt.h:134
float pf_gain
Definition: opus_celt.h:127
AVCodecContext * avctx
Definition: opus_celt.h:94
uint32_t seed
Definition: opus_celt.h:120
int caps[CELT_MAX_BANDS]
Definition: opus_celt.h:133
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels)
Definition: opus_celt.c:987
void ff_celt_flush(CeltFrame *f)
Definition: opus_celt.c:943
int blocks
Definition: opus_celt.h:112
CeltBlockSize
Definition: opus_celt.h:56
float error_energy[CELT_MAX_BANDS]
Definition: opus_celt.h:68
int frame_size
Definition: mxfenc.c:1896
#define CELT_MAX_BANDS
Definition: opus.h:45
int pf_tapset
Definition: opus_celt.h:126
main external API structure.
Definition: avcodec.h:1761
int pf_period_old
Definition: opus_celt.h:86
AVFloatDSPContext * dsp
Definition: opus_celt.h:96
Replacements for frequently missing libm functions.
CeltPVQ * pvq
Definition: opus_celt.h:98
CeltSpread
Definition: opus_celt.h:49
static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
Definition: opus_celt.h:147
float pf_gains_old[3]
Definition: opus_celt.h:87
int remaining
Definition: opus_celt.h:131
float energy[CELT_MAX_BANDS]
Definition: opus_celt.h:66
static av_always_inline uint32_t celt_rng(CeltFrame *f)
Definition: opus_celt.h:141
void ff_celt_free(CeltFrame **f)
Definition: opus_celt.c:970
enum CeltSpread spread
Definition: opus_celt.h:121
int tf_select
Definition: opus_celt.h:109
int blocksize
Definition: opus_celt.h:113
#define CELT_MAX_FRAME_SIZE
Definition: opus.h:44
#define av_always_inline
Definition: attributes.h:39
enum CeltBlockSize size
Definition: opus_celt.h:102
int alloc_trim
Definition: opus_celt.h:110
MDCT15Context * imdct[4]
Definition: opus_celt.h:95
int pf_period
Definition: opus_celt.h:84
float prev_energy[2][CELT_MAX_BANDS]
Definition: opus_celt.h:69
uint8_t collapse_masks[CELT_MAX_BANDS]
Definition: opus_celt.h:71
int pf_octave
Definition: opus_celt.h:124
float overlap[FFALIGN(CELT_OVERLAP, 16)]
Definition: opus_celt.h:78
int intensity_stereo
Definition: opus_celt.h:117
float buf[2048]
Definition: opus_celt.h:74