FFmpeg
Loading...
Searching...
No Matches
celt.h
Go to the documentation of this file.
1/*
2 * Opus decoder/encoder CELT 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 <stdint.h>
28
29#include "libavcodec/avcodec.h"
30
31#include "dsp.h"
32#include "rc.h"
33
34#include "libavutil/float_dsp.h"
35#include "libavutil/libm.h"
37#include "libavutil/tx.h"
38
39#define CELT_SHORT_BLOCKSIZE 120
40#define CELT_OVERLAP CELT_SHORT_BLOCKSIZE
41#define CELT_MAX_LOG_BLOCKS 3
42#define CELT_MAX_FRAME_SIZE (CELT_SHORT_BLOCKSIZE * (1 << CELT_MAX_LOG_BLOCKS))
43#define CELT_MAX_BANDS 21
44
45#define CELT_VECTORS 11
46#define CELT_ALLOC_STEPS 6
47#define CELT_FINE_OFFSET 21
48#define CELT_MAX_FINE_BITS 8
49#define CELT_NORM_SCALE 16384
50#define CELT_QTHETA_OFFSET 4
51#define CELT_QTHETA_OFFSET_TWOPHASE 16
52#define CELT_POSTFILTER_MINPERIOD 15
53#define CELT_ENERGY_SILENCE (-28.0f)
54
61
70
71typedef struct CeltBlock {
76
78
79 /* buffer for mdct output + postfilter */
80 DECLARE_ALIGNED(32, float, buf)[2048];
82
83 /* Used by the encoder */
86
87 /* postfilter parameters */
89 float pf_gains_new[3];
91 float pf_gains[3];
93 float pf_gains_old[3];
94
96} CeltBlock;
97
98typedef struct CeltFrame {
99 // constant values that do not change during context lifetime
105 struct CeltPVQ *pvq;
110
121 int blocks; /* number of iMDCT blocks in the frame, depends on transient */
122 int blocksize; /* size of each block */
123 int silence; /* Frame is filled with silence */
124 int anticollapse_needed; /* Whether to expect an anticollapse bit */
125 int anticollapse; /* Encoded anticollapse bit */
129 uint32_t seed;
131
132 /* Encoder PF coeffs */
136 float pf_gain;
137
138 /* Bit allocation */
147} CeltFrame;
148
149/* LCG for noise generation */
151{
152 f->seed = 1664525 * f->seed + 1013904223;
153 return f->seed;
154}
155
156static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
157{
158 int i;
159 float g = 1e-15f;
160 for (i = 0; i < N; i++)
161 g += X[i] * X[i];
162 g = gain / sqrtf(g);
163
164 for (i = 0; i < N; i++)
165 X[i] *= g;
166}
167
168int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels,
169 int apply_phase_inv);
170
171void ff_celt_free(CeltFrame **f);
172
174
175int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output,
176 int coded_channels, int frame_size, int startband, int endband);
177
178/* Encode or decode CELT bands */
180
181/* Encode or decode CELT bitallocation */
183
184#endif /* AVCODEC_OPUS_CELT_H */
#define N
Definition af_mcompand.c:54
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
static av_always_inline uint32_t celt_rng(CeltFrame *f)
Definition celt.h:150
void ff_celt_free(CeltFrame **f)
Definition dec_celt.c:530
static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
Definition celt.h:156
int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels, int apply_phase_inv)
Definition dec_celt.c:547
#define CELT_OVERLAP
Definition celt.h:40
CeltSpread
Definition celt.h:55
@ CELT_SPREAD_NORMAL
Definition celt.h:58
@ CELT_SPREAD_LIGHT
Definition celt.h:57
@ CELT_SPREAD_NONE
Definition celt.h:56
@ CELT_SPREAD_AGGRESSIVE
Definition celt.h:59
#define CELT_MAX_FRAME_SIZE
Definition celt.h:42
int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output, int coded_channels, int frame_size, int startband, int endband)
Definition dec_celt.c:323
void ff_celt_quant_bands(CeltFrame *f, OpusRangeCoder *rc)
Definition celt.c:28
#define CELT_MAX_BANDS
Definition celt.h:43
CeltBlockSize
Definition celt.h:62
@ CELT_BLOCK_120
Definition celt.h:63
@ CELT_BLOCK_NB
Definition celt.h:68
@ CELT_BLOCK_480
Definition celt.h:65
@ CELT_BLOCK_240
Definition celt.h:64
@ CELT_BLOCK_960
Definition celt.h:66
void ff_celt_flush(CeltFrame *f)
Definition dec_celt.c:499
void ff_celt_bitalloc(CeltFrame *f, OpusRangeCoder *rc, int encode)
Definition celt.c:137
static __device__ float sqrtf(float a)
static void encode(AVCodecContext *ctx, AVFrame *frame, AVPacket *pkt, FILE *output)
#define X
Definition f_ebur128.c:157
static const uint8_t frame_size[4]
Definition g723_1.h:222
#define av_always_inline
Definition attributes.h:72
Replacements for frequently missing libm functions.
#define FFALIGN(x, a)
Definition macros.h:78
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
main external API structure.
Definition avcodec.h:443
float energy[CELT_MAX_BANDS]
Definition celt.h:72
float pf_gains_new[3]
Definition celt.h:89
uint8_t collapse_masks[CELT_MAX_BANDS]
Definition celt.h:77
float pf_gains_old[3]
Definition celt.h:93
float prev_energy[2][CELT_MAX_BANDS]
Definition celt.h:75
float emph_coeff
Definition celt.h:95
float buf[2048]
Definition celt.h:80
float lin_energy[CELT_MAX_BANDS]
Definition celt.h:73
int pf_period_old
Definition celt.h:92
int pf_period_new
Definition celt.h:88
float error_energy[CELT_MAX_BANDS]
Definition celt.h:74
float overlap[FFALIGN(CELT_OVERLAP, 16)]
Definition celt.h:84
float pf_gains[3]
Definition celt.h:91
float samples[FFALIGN(CELT_MAX_FRAME_SIZE, 16)]
Definition celt.h:85
int pf_period
Definition celt.h:90
float coeffs[CELT_MAX_FRAME_SIZE]
Definition celt.h:81
int blocks
Definition celt.h:121
CeltBlock block[2]
Definition celt.h:104
float pf_gain
Definition celt.h:136
int alloc_trim
Definition celt.h:119
int skip_band_floor
Definition celt.h:117
int pf_tapset
Definition celt.h:135
int anticollapse
Definition celt.h:125
int pf_octave
Definition celt.h:133
int coded_bands
Definition celt.h:114
int pfilter
Definition celt.h:116
int silence
Definition celt.h:123
enum CeltBlockSize size
Definition celt.h:111
int framebits
Definition celt.h:139
int intensity_stereo
Definition celt.h:126
int remaining2
Definition celt.h:141
int start_band
Definition celt.h:112
int tf_select
Definition celt.h:118
AVCodecContext * avctx
Definition celt.h:100
int blocksize
Definition celt.h:122
int remaining
Definition celt.h:140
OpusDSP opusdsp
Definition celt.h:106
AVTXContext * tx[4]
Definition celt.h:101
int apply_phase_inv
Definition celt.h:109
int alloc_boost[CELT_MAX_BANDS]
Definition celt.h:120
AVFloatDSPContext * dsp
Definition celt.h:103
int end_band
Definition celt.h:113
int anticollapse_needed
Definition celt.h:124
int flushed
Definition celt.h:128
enum CeltSpread spread
Definition celt.h:130
struct CeltPVQ * pvq
Definition celt.h:105
int channels
Definition celt.h:107
int tf_change[CELT_MAX_BANDS]
Definition celt.h:146
uint32_t seed
Definition celt.h:129
av_tx_fn tx_fn[4]
Definition celt.h:102
int caps[CELT_MAX_BANDS]
Definition celt.h:142
int output_channels
Definition celt.h:108
int transient
Definition celt.h:115
int fine_bits[CELT_MAX_BANDS]
Definition celt.h:143
int pulses[CELT_MAX_BANDS]
Definition celt.h:145
int dual_stereo
Definition celt.h:127
int fine_priority[CELT_MAX_BANDS]
Definition celt.h:144
int pf_period
Definition celt.h:134
Definition pvq.h:37
Definition dsp.h:22
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition tx.h:151
const char * g
Definition vf_curves.c:128