webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
celt.h
Go to the documentation of this file.
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 */
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 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #define CELTEncoder OpusCustomEncoder
50 #define CELTDecoder OpusCustomDecoder
51 #define CELTMode OpusCustomMode
52 
53 typedef struct {
54  int valid;
55  float tonality;
57  float noisiness;
58  float activity;
59  float music_prob;
60  int bandwidth;
62 
63 #define __celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr)))
64 
65 #define __celt_check_analysis_ptr(ptr) ((ptr) + ((ptr) - (const AnalysisInfo*)(ptr)))
66 
67 /* Encoder/decoder Requests */
68 
69 /* Expose this option again when variable framesize actually works */
70 #define OPUS_FRAMESIZE_VARIABLE 5010
73 #define CELT_SET_PREDICTION_REQUEST 10002
74 
79 #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, __opus_check_int(x)
80 
81 #define CELT_SET_INPUT_CLIPPING_REQUEST 10004
82 #define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, __opus_check_int(x)
83 
84 #define CELT_GET_AND_CLEAR_ERROR_REQUEST 10007
85 #define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, __opus_check_int_ptr(x)
86 
87 #define CELT_SET_CHANNELS_REQUEST 10008
88 #define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, __opus_check_int(x)
89 
90 
91 /* Internal */
92 #define CELT_SET_START_BAND_REQUEST 10010
93 #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, __opus_check_int(x)
94 
95 #define CELT_SET_END_BAND_REQUEST 10012
96 #define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, __opus_check_int(x)
97 
98 #define CELT_GET_MODE_REQUEST 10015
99 
100 #define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, __celt_check_mode_ptr_ptr(x)
101 
102 #define CELT_SET_SIGNALLING_REQUEST 10016
103 #define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, __opus_check_int(x)
104 
105 #define CELT_SET_TONALITY_REQUEST 10018
106 #define CELT_SET_TONALITY(x) CELT_SET_TONALITY_REQUEST, __opus_check_int(x)
107 #define CELT_SET_TONALITY_SLOPE_REQUEST 10020
108 #define CELT_SET_TONALITY_SLOPE(x) CELT_SET_TONALITY_SLOPE_REQUEST, __opus_check_int(x)
109 
110 #define CELT_SET_ANALYSIS_REQUEST 10022
111 #define CELT_SET_ANALYSIS(x) CELT_SET_ANALYSIS_REQUEST, __celt_check_analysis_ptr(x)
112 
113 #define OPUS_SET_LFE_REQUEST 10024
114 #define OPUS_SET_LFE(x) OPUS_SET_LFE_REQUEST, __opus_check_int(x)
115 
116 #define OPUS_SET_ENERGY_MASK_REQUEST 10026
117 #define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, __opus_check_val16_ptr(x)
118 
119 /* Encoder stuff */
120 
121 int celt_encoder_get_size(int channels);
122 
123 int celt_encode_with_ec(OpusCustomEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc);
124 
125 int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels,
126  int arch);
127 
128 
129 
130 /* Decoder stuff */
131 
132 int celt_decoder_get_size(int channels);
133 
134 
135 int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels);
136 
137 int celt_decode_with_ec(OpusCustomDecoder * OPUS_RESTRICT st, const unsigned char *data,
138  int len, opus_val16 * OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum);
139 
140 #define celt_encoder_ctl opus_custom_encoder_ctl
141 #define celt_decoder_ctl opus_custom_decoder_ctl
142 
143 
144 #ifdef CUSTOM_MODES
145 #define OPUS_CUSTOM_NOSTATIC
146 #else
147 #define OPUS_CUSTOM_NOSTATIC static OPUS_INLINE
148 #endif
149 
150 static const unsigned char trim_icdf[11] = {126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0};
151 /* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */
152 static const unsigned char spread_icdf[4] = {25, 23, 2, 0};
153 
154 static const unsigned char tapset_icdf[3]={2,1,0};
155 
156 #ifdef CUSTOM_MODES
157 static const unsigned char toOpusTable[20] = {
158  0xE0, 0xE8, 0xF0, 0xF8,
159  0xC0, 0xC8, 0xD0, 0xD8,
160  0xA0, 0xA8, 0xB0, 0xB8,
161  0x00, 0x00, 0x00, 0x00,
162  0x80, 0x88, 0x90, 0x98,
163 };
164 
165 static const unsigned char fromOpusTable[16] = {
166  0x80, 0x88, 0x90, 0x98,
167  0x40, 0x48, 0x50, 0x58,
168  0x20, 0x28, 0x30, 0x38,
169  0x00, 0x08, 0x10, 0x18
170 };
171 
172 static OPUS_INLINE int toOpus(unsigned char c)
173 {
174  int ret=0;
175  if (c<0xA0)
176  ret = toOpusTable[c>>3];
177  if (ret == 0)
178  return -1;
179  else
180  return ret|(c&0x7);
181 }
182 
183 static OPUS_INLINE int fromOpus(unsigned char c)
184 {
185  if (c<0x80)
186  return -1;
187  else
188  return fromOpusTable[(c>>3)-16] | (c&0x7);
189 }
190 #endif /* CUSTOM_MODES */
191 
192 #define COMBFILTER_MAXPERIOD 1024
193 #define COMBFILTER_MINPERIOD 15
194 
195 extern const signed char tf_select_table[4][8];
196 
197 int resampling_factor(opus_int32 rate);
198 
199 void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp,
200  int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip);
201 
202 void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N,
203  opus_val16 g0, opus_val16 g1, int tapset0, int tapset1,
204  const opus_val16 *window, int overlap, int arch);
205 
206 #ifdef NON_STATIC_COMB_FILTER_CONST_C
207 void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N,
208  opus_val16 g10, opus_val16 g11, opus_val16 g12);
209 #endif
210 
211 #ifndef OVERRIDE_COMB_FILTER_CONST
212 # define comb_filter_const(y, x, T, N, g10, g11, g12, arch) \
213  ((void)(arch),comb_filter_const_c(y, x, T, N, g10, g11, g12))
214 #endif
215 
216 void init_caps(const CELTMode *m,int *cap,int LM,int C);
217 
218 #ifdef RESYNTH
219 void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int C, int downsample, const opus_val16 *coef, celt_sig *mem);
220 void celt_synthesis(const CELTMode *mode, celt_norm *X, celt_sig * out_syn[],
221  opus_val16 *oldBandE, int start, int effEnd, int C, int CC, int isTransient,
222  int LM, int downsample, int silence);
223 #endif
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif /* CELT_H */
void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, opus_val16 g0, opus_val16 g1, int tapset0, int tapset1, const opus_val16 *window, int overlap, int arch)
Definition: celt.c:183
Opus reference implementation types.
int c
Definition: cpp_unittests.cpp:275
float celt_sig
Definition: arch.h:151
int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels, int arch)
Definition: celt_encoder.c:205
float noisiness
Definition: celt.h:57
int resampling_factor(opus_int32 rate)
Definition: celt.c:62
const GLfloat * m
Definition: gl2ext.h:850
Definition: celt.h:53
#define CELTMode
Definition: celt.h:51
float tonality
Definition: celt.h:55
GLenum mode
Definition: gl2.h:461
Opus reference implementation constants.
#define CELTDecoder
Definition: celt.h:50
float tonality_slope
Definition: celt.h:56
float opus_val16
Definition: arch.h:148
GLuint start
Definition: gl2ext.h:323
int celt_encode_with_ec(OpusCustomEncoder *OPUS_RESTRICT st, const opus_val16 *pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc)
int celt_encoder_get_size(int channels)
Definition: celt_encoder.c:128
OPENSSL_EXPORT const ASN1_OBJECT int const unsigned char int len
Definition: x509.h:1053
int ret
Definition: test_unit_dft.c:69
TestSubObjConstructor T
Definition: TestTypedefs.idl:84
EGLSurface EGLint x
Definition: eglext.h:950
void init_caps(const CELTMode *m, int *cap, int LM, int C)
Definition: celt.c:255
int opus_int32
Definition: opus_types.h:146
float celt_norm
Definition: arch.h:152
#define X(sym)
Definition: alsasymboltable_linux.h:139
int celt_decode_with_ec(OpusCustomDecoder *OPUS_RESTRICT st, const unsigned char *data, int len, opus_val16 *OPUS_RESTRICT pcm, int frame_size, ec_dec *dec, int accum)
Decoder state.
Definition: celt_decoder.c:67
#define CELTEncoder
Definition: celt.h:49
Definition: entcode.h:62
EGLSurface EGLint EGLint y
Definition: eglext.h:950
#define N
Definition: gcc-loops.cpp:14
void celt_preemphasis(const opus_val16 *OPUS_RESTRICT pcmp, celt_sig *OPUS_RESTRICT inp, int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip)
Definition: celt_encoder.c:462
string arch
Definition: runtests.py:65
int bandwidth
Definition: celt.h:60
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:934
EGLStreamKHR EGLint EGLint EGLint const void * data
Definition: eglext.h:984
int valid
Definition: celt.h:54
Definition: type_traits_unittest.cc:77
float music_prob
Definition: celt.h:59
Opus-Custom reference implementation API.
int celt_decoder_get_size(int channels)
Definition: celt_decoder.c:103
Encoder state.
Definition: celt_encoder.c:58
Various architecture definitions for CELT.
float opus_val32
Definition: arch.h:149
const signed char tf_select_table[4][8]
Definition: celt.c:247
float activity
Definition: celt.h:58
int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels)
Definition: celt_decoder.c:135