media/libopus/celt/celt.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial