annotate src/opus-1.3/celt/celt.h @ 79:91c729825bca pa_catalina

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