1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/celt/celt.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,218 @@ 1.4 +/* Copyright (c) 2007-2008 CSIRO 1.5 + Copyright (c) 2007-2009 Xiph.Org Foundation 1.6 + Copyright (c) 2008 Gregory Maxwell 1.7 + Written by Jean-Marc Valin and Gregory Maxwell */ 1.8 +/** 1.9 + @file celt.h 1.10 + @brief Contains all the functions for encoding and decoding audio 1.11 + */ 1.12 + 1.13 +/* 1.14 + Redistribution and use in source and binary forms, with or without 1.15 + modification, are permitted provided that the following conditions 1.16 + are met: 1.17 + 1.18 + - Redistributions of source code must retain the above copyright 1.19 + notice, this list of conditions and the following disclaimer. 1.20 + 1.21 + - Redistributions in binary form must reproduce the above copyright 1.22 + notice, this list of conditions and the following disclaimer in the 1.23 + documentation and/or other materials provided with the distribution. 1.24 + 1.25 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.26 + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.27 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.28 + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 1.29 + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.30 + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.31 + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.32 + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.33 + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.34 + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.35 + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.36 +*/ 1.37 + 1.38 +#ifndef CELT_H 1.39 +#define CELT_H 1.40 + 1.41 +#include "opus_types.h" 1.42 +#include "opus_defines.h" 1.43 +#include "opus_custom.h" 1.44 +#include "entenc.h" 1.45 +#include "entdec.h" 1.46 +#include "arch.h" 1.47 + 1.48 +#ifdef __cplusplus 1.49 +extern "C" { 1.50 +#endif 1.51 + 1.52 +#define CELTEncoder OpusCustomEncoder 1.53 +#define CELTDecoder OpusCustomDecoder 1.54 +#define CELTMode OpusCustomMode 1.55 + 1.56 +typedef struct { 1.57 + int valid; 1.58 + float tonality; 1.59 + float tonality_slope; 1.60 + float noisiness; 1.61 + float activity; 1.62 + float music_prob; 1.63 + int bandwidth; 1.64 +}AnalysisInfo; 1.65 + 1.66 +#define __celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr))) 1.67 + 1.68 +#define __celt_check_analysis_ptr(ptr) ((ptr) + ((ptr) - (const AnalysisInfo*)(ptr))) 1.69 + 1.70 +/* Encoder/decoder Requests */ 1.71 + 1.72 +/* Expose this option again when variable framesize actually works */ 1.73 +#define OPUS_FRAMESIZE_VARIABLE 5010 /**< Optimize the frame size dynamically */ 1.74 + 1.75 + 1.76 +#define CELT_SET_PREDICTION_REQUEST 10002 1.77 +/** Controls the use of interframe prediction. 1.78 + 0=Independent frames 1.79 + 1=Short term interframe prediction allowed 1.80 + 2=Long term prediction allowed 1.81 + */ 1.82 +#define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, __opus_check_int(x) 1.83 + 1.84 +#define CELT_SET_INPUT_CLIPPING_REQUEST 10004 1.85 +#define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, __opus_check_int(x) 1.86 + 1.87 +#define CELT_GET_AND_CLEAR_ERROR_REQUEST 10007 1.88 +#define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, __opus_check_int_ptr(x) 1.89 + 1.90 +#define CELT_SET_CHANNELS_REQUEST 10008 1.91 +#define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, __opus_check_int(x) 1.92 + 1.93 + 1.94 +/* Internal */ 1.95 +#define CELT_SET_START_BAND_REQUEST 10010 1.96 +#define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, __opus_check_int(x) 1.97 + 1.98 +#define CELT_SET_END_BAND_REQUEST 10012 1.99 +#define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, __opus_check_int(x) 1.100 + 1.101 +#define CELT_GET_MODE_REQUEST 10015 1.102 +/** Get the CELTMode used by an encoder or decoder */ 1.103 +#define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, __celt_check_mode_ptr_ptr(x) 1.104 + 1.105 +#define CELT_SET_SIGNALLING_REQUEST 10016 1.106 +#define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, __opus_check_int(x) 1.107 + 1.108 +#define CELT_SET_TONALITY_REQUEST 10018 1.109 +#define CELT_SET_TONALITY(x) CELT_SET_TONALITY_REQUEST, __opus_check_int(x) 1.110 +#define CELT_SET_TONALITY_SLOPE_REQUEST 10020 1.111 +#define CELT_SET_TONALITY_SLOPE(x) CELT_SET_TONALITY_SLOPE_REQUEST, __opus_check_int(x) 1.112 + 1.113 +#define CELT_SET_ANALYSIS_REQUEST 10022 1.114 +#define CELT_SET_ANALYSIS(x) CELT_SET_ANALYSIS_REQUEST, __celt_check_analysis_ptr(x) 1.115 + 1.116 +#define OPUS_SET_LFE_REQUEST 10024 1.117 +#define OPUS_SET_LFE(x) OPUS_SET_LFE_REQUEST, __opus_check_int(x) 1.118 + 1.119 +#define OPUS_SET_ENERGY_MASK_REQUEST 10026 1.120 +#define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, __opus_check_val16_ptr(x) 1.121 + 1.122 +/* Encoder stuff */ 1.123 + 1.124 +int celt_encoder_get_size(int channels); 1.125 + 1.126 +int celt_encode_with_ec(OpusCustomEncoder * OPUS_RESTRICT st, const opus_val16 * pcm, int frame_size, unsigned char *compressed, int nbCompressedBytes, ec_enc *enc); 1.127 + 1.128 +int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels, 1.129 + int arch); 1.130 + 1.131 + 1.132 + 1.133 +/* Decoder stuff */ 1.134 + 1.135 +int celt_decoder_get_size(int channels); 1.136 + 1.137 + 1.138 +int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels); 1.139 + 1.140 +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); 1.141 + 1.142 +#define celt_encoder_ctl opus_custom_encoder_ctl 1.143 +#define celt_decoder_ctl opus_custom_decoder_ctl 1.144 + 1.145 + 1.146 +#ifdef CUSTOM_MODES 1.147 +#define OPUS_CUSTOM_NOSTATIC 1.148 +#else 1.149 +#define OPUS_CUSTOM_NOSTATIC static OPUS_INLINE 1.150 +#endif 1.151 + 1.152 +static const unsigned char trim_icdf[11] = {126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0}; 1.153 +/* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */ 1.154 +static const unsigned char spread_icdf[4] = {25, 23, 2, 0}; 1.155 + 1.156 +static const unsigned char tapset_icdf[3]={2,1,0}; 1.157 + 1.158 +#ifdef CUSTOM_MODES 1.159 +static const unsigned char toOpusTable[20] = { 1.160 + 0xE0, 0xE8, 0xF0, 0xF8, 1.161 + 0xC0, 0xC8, 0xD0, 0xD8, 1.162 + 0xA0, 0xA8, 0xB0, 0xB8, 1.163 + 0x00, 0x00, 0x00, 0x00, 1.164 + 0x80, 0x88, 0x90, 0x98, 1.165 +}; 1.166 + 1.167 +static const unsigned char fromOpusTable[16] = { 1.168 + 0x80, 0x88, 0x90, 0x98, 1.169 + 0x40, 0x48, 0x50, 0x58, 1.170 + 0x20, 0x28, 0x30, 0x38, 1.171 + 0x00, 0x08, 0x10, 0x18 1.172 +}; 1.173 + 1.174 +static OPUS_INLINE int toOpus(unsigned char c) 1.175 +{ 1.176 + int ret=0; 1.177 + if (c<0xA0) 1.178 + ret = toOpusTable[c>>3]; 1.179 + if (ret == 0) 1.180 + return -1; 1.181 + else 1.182 + return ret|(c&0x7); 1.183 +} 1.184 + 1.185 +static OPUS_INLINE int fromOpus(unsigned char c) 1.186 +{ 1.187 + if (c<0x80) 1.188 + return -1; 1.189 + else 1.190 + return fromOpusTable[(c>>3)-16] | (c&0x7); 1.191 +} 1.192 +#endif /* CUSTOM_MODES */ 1.193 + 1.194 +#define COMBFILTER_MAXPERIOD 1024 1.195 +#define COMBFILTER_MINPERIOD 15 1.196 + 1.197 +extern const signed char tf_select_table[4][8]; 1.198 + 1.199 +int resampling_factor(opus_int32 rate); 1.200 + 1.201 +void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp, 1.202 + int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip); 1.203 + 1.204 +void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, 1.205 + opus_val16 g0, opus_val16 g1, int tapset0, int tapset1, 1.206 + const opus_val16 *window, int overlap); 1.207 + 1.208 +void init_caps(const CELTMode *m,int *cap,int LM,int C); 1.209 + 1.210 +#ifdef RESYNTH 1.211 +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); 1.212 + 1.213 +void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X, 1.214 + celt_sig * OPUS_RESTRICT out_mem[], int C, int LM); 1.215 +#endif 1.216 + 1.217 +#ifdef __cplusplus 1.218 +} 1.219 +#endif 1.220 + 1.221 +#endif /* CELT_H */