annotate src/opus-1.3/celt/celt.h @ 169:223a55898ab9 tip default

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