Coverage Report

Created: 2025-12-31 07:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opus/celt/celt.h
Line
Count
Source
1
/* Copyright (c) 2007-2008 CSIRO
2
   Copyright (c) 2007-2009 Xiph.Org Foundation
3
   Copyright (c) 2008 Gregory Maxwell
4
   Written by Jean-Marc Valin and Gregory Maxwell */
5
/**
6
  @file celt.h
7
  @brief Contains all the functions for encoding and decoding audio
8
 */
9
10
/*
11
   Redistribution and use in source and binary forms, with or without
12
   modification, are permitted provided that the following conditions
13
   are met:
14
15
   - Redistributions of source code must retain the above copyright
16
   notice, this list of conditions and the following disclaimer.
17
18
   - Redistributions in binary form must reproduce the above copyright
19
   notice, this list of conditions and the following disclaimer in the
20
   documentation and/or other materials provided with the distribution.
21
22
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26
   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
*/
34
35
#ifndef CELT_H
36
#define CELT_H
37
38
#include "opus_types.h"
39
#include "opus_defines.h"
40
#include "opus_custom.h"
41
#include "entenc.h"
42
#include "entdec.h"
43
#include "arch.h"
44
#include "kiss_fft.h"
45
46
#ifdef ENABLE_QEXT
47
#define ARG_QEXT(arg) , arg
48
#else
49
#define ARG_QEXT(arg)
50
#endif
51
52
53
#ifdef ENABLE_DEEP_PLC
54
#include "lpcnet.h"
55
#endif
56
57
0
#define CELTEncoder OpusCustomEncoder
58
3.38M
#define CELTDecoder OpusCustomDecoder
59
0
#define CELTMode OpusCustomMode
60
61
#define QEXT_EXTENSION_ID 124
62
63
0
#define LEAK_BANDS 19
64
65
typedef struct {
66
   int valid;
67
   float tonality;
68
   float tonality_slope;
69
   float noisiness;
70
   float activity;
71
   float music_prob;
72
   float music_prob_min;
73
   float music_prob_max;
74
   int   bandwidth;
75
   float activity_probability;
76
   float max_pitch_ratio;
77
   /* Store as Q6 char to save space. */
78
   unsigned char leak_boost[LEAK_BANDS];
79
} AnalysisInfo;
80
81
typedef struct {
82
   int signalType;
83
   int offset;
84
} SILKInfo;
85
86
0
#define celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr)))
87
88
0
#define celt_check_analysis_ptr(ptr) ((ptr) + ((ptr) - (const AnalysisInfo*)(ptr)))
89
90
0
#define celt_check_silkinfo_ptr(ptr) ((ptr) + ((ptr) - (const SILKInfo*)(ptr)))
91
92
0
#define celt_check_glog_ptr(ptr) ((ptr) + ((ptr) - (celt_glog*)(ptr)))
93
94
/* Encoder/decoder Requests */
95
96
97
0
#define CELT_SET_PREDICTION_REQUEST    10002
98
/** Controls the use of interframe prediction.
99
    0=Independent frames
100
    1=Short term interframe prediction allowed
101
    2=Long term prediction allowed
102
 */
103
0
#define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, opus_check_int(x)
104
105
#define CELT_SET_INPUT_CLIPPING_REQUEST    10004
106
#define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, opus_check_int(x)
107
108
0
#define CELT_GET_AND_CLEAR_ERROR_REQUEST   10007
109
#define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, opus_check_int_ptr(x)
110
111
424k
#define CELT_SET_CHANNELS_REQUEST    10008
112
0
#define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, opus_check_int(x)
113
114
115
/* Internal */
116
455k
#define CELT_SET_START_BAND_REQUEST    10010
117
0
#define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, opus_check_int(x)
118
119
189k
#define CELT_SET_END_BAND_REQUEST    10012
120
0
#define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, opus_check_int(x)
121
122
424k
#define CELT_GET_MODE_REQUEST    10015
123
/** Get the CELTMode used by an encoder or decoder */
124
0
#define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, celt_check_mode_ptr_ptr(x)
125
126
121k
#define CELT_SET_SIGNALLING_REQUEST    10016
127
60.8k
#define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, opus_check_int(x)
128
129
#define CELT_SET_TONALITY_REQUEST    10018
130
#define CELT_SET_TONALITY(x) CELT_SET_TONALITY_REQUEST, opus_check_int(x)
131
#define CELT_SET_TONALITY_SLOPE_REQUEST    10020
132
#define CELT_SET_TONALITY_SLOPE(x) CELT_SET_TONALITY_SLOPE_REQUEST, opus_check_int(x)
133
134
0
#define CELT_SET_ANALYSIS_REQUEST    10022
135
0
#define CELT_SET_ANALYSIS(x) CELT_SET_ANALYSIS_REQUEST, celt_check_analysis_ptr(x)
136
137
0
#define OPUS_SET_LFE_REQUEST    10024
138
0
#define OPUS_SET_LFE(x) OPUS_SET_LFE_REQUEST, opus_check_int(x)
139
140
0
#define OPUS_SET_ENERGY_MASK_REQUEST    10026
141
0
#define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, celt_check_glog_ptr(x)
142
143
0
#define CELT_SET_SILK_INFO_REQUEST    10028
144
0
#define CELT_SET_SILK_INFO(x) CELT_SET_SILK_INFO_REQUEST, celt_check_silkinfo_ptr(x)
145
146
147
0
static OPUS_INLINE opus_int32 bits_to_bitrate(opus_int32 bits, opus_int32 Fs, opus_int32 frame_size) {
148
0
   return bits*(6*Fs/frame_size)/6;
149
0
}
Unexecuted instantiation: celt.c:bits_to_bitrate
Unexecuted instantiation: pitch_sse.c:bits_to_bitrate
Unexecuted instantiation: opus_multistream_decoder.c:bits_to_bitrate
Unexecuted instantiation: opus.c:bits_to_bitrate
Unexecuted instantiation: opus_decoder.c:bits_to_bitrate
Unexecuted instantiation: extensions.c:bits_to_bitrate
Unexecuted instantiation: opus_multistream.c:bits_to_bitrate
Unexecuted instantiation: celt_decoder.c:bits_to_bitrate
Unexecuted instantiation: modes.c:bits_to_bitrate
Unexecuted instantiation: pitch.c:bits_to_bitrate
Unexecuted instantiation: celt_lpc.c:bits_to_bitrate
Unexecuted instantiation: quant_bands.c:bits_to_bitrate
Unexecuted instantiation: rate.c:bits_to_bitrate
Unexecuted instantiation: vq.c:bits_to_bitrate
Unexecuted instantiation: x86cpu.c:bits_to_bitrate
Unexecuted instantiation: x86_celt_map.c:bits_to_bitrate
Unexecuted instantiation: vq_sse2.c:bits_to_bitrate
Unexecuted instantiation: pitch_avx.c:bits_to_bitrate
Unexecuted instantiation: bands.c:bits_to_bitrate
Unexecuted instantiation: opus_multistream_encoder.c:bits_to_bitrate
Unexecuted instantiation: repacketizer.c:bits_to_bitrate
Unexecuted instantiation: celt_encoder.c:bits_to_bitrate
Unexecuted instantiation: opus_encoder.c:bits_to_bitrate
Unexecuted instantiation: analysis.c:bits_to_bitrate
Unexecuted instantiation: pitch_analysis_core_FLP.c:bits_to_bitrate
Unexecuted instantiation: x86_silk_map.c:bits_to_bitrate
150
151
0
static OPUS_INLINE opus_int32 bitrate_to_bits(opus_int32 bitrate, opus_int32 Fs, opus_int32 frame_size) {
152
0
   return bitrate*6/(6*Fs/frame_size);
153
0
}
Unexecuted instantiation: celt.c:bitrate_to_bits
Unexecuted instantiation: pitch_sse.c:bitrate_to_bits
Unexecuted instantiation: opus_multistream_decoder.c:bitrate_to_bits
Unexecuted instantiation: opus.c:bitrate_to_bits
Unexecuted instantiation: opus_decoder.c:bitrate_to_bits
Unexecuted instantiation: extensions.c:bitrate_to_bits
Unexecuted instantiation: opus_multistream.c:bitrate_to_bits
Unexecuted instantiation: celt_decoder.c:bitrate_to_bits
Unexecuted instantiation: modes.c:bitrate_to_bits
Unexecuted instantiation: pitch.c:bitrate_to_bits
Unexecuted instantiation: celt_lpc.c:bitrate_to_bits
Unexecuted instantiation: quant_bands.c:bitrate_to_bits
Unexecuted instantiation: rate.c:bitrate_to_bits
Unexecuted instantiation: vq.c:bitrate_to_bits
Unexecuted instantiation: x86cpu.c:bitrate_to_bits
Unexecuted instantiation: x86_celt_map.c:bitrate_to_bits
Unexecuted instantiation: vq_sse2.c:bitrate_to_bits
Unexecuted instantiation: pitch_avx.c:bitrate_to_bits
Unexecuted instantiation: bands.c:bitrate_to_bits
Unexecuted instantiation: opus_multistream_encoder.c:bitrate_to_bits
Unexecuted instantiation: repacketizer.c:bitrate_to_bits
Unexecuted instantiation: celt_encoder.c:bitrate_to_bits
Unexecuted instantiation: opus_encoder.c:bitrate_to_bits
Unexecuted instantiation: analysis.c:bitrate_to_bits
Unexecuted instantiation: pitch_analysis_core_FLP.c:bitrate_to_bits
Unexecuted instantiation: x86_silk_map.c:bitrate_to_bits
154
155
/* Encoder stuff */
156
157
int celt_encoder_get_size(int channels);
158
159
int celt_encode_with_ec(OpusCustomEncoder * OPUS_RESTRICT st, const opus_res * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc);
160
161
int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels,
162
                      int arch);
163
164
165
166
/* Decoder stuff */
167
168
int celt_decoder_get_size(int channels);
169
170
171
int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels);
172
173
int celt_decode_with_ec_dred(CELTDecoder * OPUS_RESTRICT st, const unsigned char *data,
174
      int len, opus_res * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum
175
#ifdef ENABLE_DEEP_PLC
176
      ,LPCNetPLCState *lpcnet
177
#endif
178
      ARG_QEXT(const unsigned char *qext_payload) ARG_QEXT(int qext_payload_len)
179
      );
180
181
int celt_decode_with_ec(OpusCustomDecoder * OPUS_RESTRICT st, const unsigned char *data,
182
      int len, opus_res * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum);
183
184
0
#define celt_encoder_ctl opus_custom_encoder_ctl
185
2.73M
#define celt_decoder_ctl opus_custom_decoder_ctl
186
187
188
#if defined(CUSTOM_MODES) || defined(ENABLE_OPUS_CUSTOM_API)
189
#define OPUS_CUSTOM_NOSTATIC
190
#else
191
#define OPUS_CUSTOM_NOSTATIC static OPUS_INLINE
192
#endif
193
194
static const unsigned char trim_icdf[11] = {126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0};
195
/* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */
196
static const unsigned char spread_icdf[4] = {25, 23, 2, 0};
197
198
static const unsigned char tapset_icdf[3]={2,1,0};
199
200
#if defined(CUSTOM_MODES) || defined(ENABLE_OPUS_CUSTOM_API)
201
static const unsigned char toOpusTable[20] = {
202
      0xE0, 0xE8, 0xF0, 0xF8,
203
      0xC0, 0xC8, 0xD0, 0xD8,
204
      0xA0, 0xA8, 0xB0, 0xB8,
205
      0x00, 0x00, 0x00, 0x00,
206
      0x80, 0x88, 0x90, 0x98,
207
};
208
209
static const unsigned char fromOpusTable[16] = {
210
      0x80, 0x88, 0x90, 0x98,
211
      0x40, 0x48, 0x50, 0x58,
212
      0x20, 0x28, 0x30, 0x38,
213
      0x00, 0x08, 0x10, 0x18
214
};
215
216
static OPUS_INLINE int toOpus(unsigned char c)
217
{
218
   int ret=0;
219
   if (c<0xA0)
220
      ret = toOpusTable[c>>3];
221
   if (ret == 0)
222
      return -1;
223
   else
224
      return ret|(c&0x7);
225
}
226
227
static OPUS_INLINE int fromOpus(unsigned char c)
228
{
229
   if (c<0x80)
230
      return -1;
231
   else
232
      return fromOpusTable[(c>>3)-16] | (c&0x7);
233
}
234
#endif /* CUSTOM_MODES */
235
236
#define COMBFILTER_MAXPERIOD 1024
237
0
#define COMBFILTER_MINPERIOD 15
238
239
extern const signed char tf_select_table[4][8];
240
241
#if defined(ENABLE_HARDENING) || defined(ENABLE_ASSERTIONS)
242
void validate_celt_decoder(CELTDecoder *st);
243
237k
#define VALIDATE_CELT_DECODER(st) validate_celt_decoder(st)
244
#else
245
#define VALIDATE_CELT_DECODER(st)
246
#endif
247
248
int resampling_factor(opus_int32 rate);
249
250
void celt_preemphasis(const opus_res * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp,
251
                        int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip);
252
253
void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
254
      opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
255
      const celt_coef *window, int overlap, int arch);
256
257
void init_caps(const CELTMode *m,int *cap,int LM,int C);
258
259
#ifdef RESYNTH
260
void deemphasis(celt_sig *in[], opus_res *pcm, int N, int C, int downsample, const opus_val16 *coef, celt_sig *mem, int accum);
261
void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[],
262
      celt_glog *oldBandE, int start, int effEnd, int C, int CC, int isTransient,
263
      int LM, int downsample, int silence, int arch ARG_QEXT(const CELTMode *qext_mode) ARG_QEXT(const celt_glog *qext_bandLogE) ARG_QEXT(int qext_end));
264
#endif
265
266
#ifdef ENABLE_QEXT
267
#define QEXT_SCALE(x) ((qext_scale)*(x))
268
#define QEXT_SCALE2(x, qext_scale) ((qext_scale)*(x))
269
#else
270
7.24M
#define QEXT_SCALE(x) (x)
271
0
#define QEXT_SCALE2(x, qext_scale) (x)
272
#endif
273
274
#endif /* CELT_H */