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>
7 * This file is part of FFmpeg.
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.
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.
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
24 #ifndef AVCODEC_OPUS_CELT_H
25 #define AVCODEC_OPUS_CELT_H
33 #include "libavutil/float_dsp.h"
34 #include "libavutil/libm.h"
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)
47 typedef struct CeltPVQ CeltPVQ;
53 CELT_SPREAD_AGGRESSIVE
65 typedef struct CeltBlock {
66 float energy[CELT_MAX_BANDS];
67 float lin_energy[CELT_MAX_BANDS];
68 float error_energy[CELT_MAX_BANDS];
69 float prev_energy[2][CELT_MAX_BANDS];
71 uint8_t collapse_masks[CELT_MAX_BANDS];
73 /* buffer for mdct output + postfilter */
74 DECLARE_ALIGNED(32, float, buf)[2048];
75 DECLARE_ALIGNED(32, float, coeffs)[CELT_MAX_FRAME_SIZE];
77 /* Used by the encoder */
78 DECLARE_ALIGNED(32, float, overlap)[120];
79 DECLARE_ALIGNED(32, float, samples)[CELT_MAX_FRAME_SIZE];
81 /* postfilter parameters */
83 float pf_gains_new[3];
87 float pf_gains_old[3];
93 // constant values that do not change during context lifetime
94 AVCodecContext *avctx;
95 MDCT15Context *imdct[4];
96 AVFloatDSPContext *dsp;
102 enum CeltBlockSize size;
111 int alloc_boost[CELT_MAX_BANDS];
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 */
117 int intensity_stereo;
121 enum CeltSpread spread;
127 int caps [CELT_MAX_BANDS];
128 int fine_bits [CELT_MAX_BANDS];
129 int fine_priority[CELT_MAX_BANDS];
130 int pulses [CELT_MAX_BANDS];
131 int tf_change [CELT_MAX_BANDS];
134 /* LCG for noise generation */
135 static av_always_inline uint32_t celt_rng(CeltFrame *f)
137 f->seed = 1664525 * f->seed + 1013904223;
141 static av_always_inline void celt_renormalize_vector(float *X, int N, float gain)
145 for (i = 0; i < N; i++)
149 for (i = 0; i < N; i++)
153 int ff_celt_init(AVCodecContext *avctx, CeltFrame **f, int output_channels);
155 void ff_celt_free(CeltFrame **f);
157 void ff_celt_flush(CeltFrame *f);
159 int ff_celt_decode_frame(CeltFrame *f, OpusRangeCoder *rc, float **output,
160 int coded_channels, int frame_size, int startband, int endband);
162 #endif /* AVCODEC_OPUS_CELT_H */