michael@0: /* Copyright (c) 2007-2008 CSIRO michael@0: Copyright (c) 2007-2009 Xiph.Org Foundation michael@0: Copyright (c) 2008 Gregory Maxwell michael@0: Written by Jean-Marc Valin and Gregory Maxwell */ michael@0: /** michael@0: @file celt.h michael@0: @brief Contains all the functions for encoding and decoding audio michael@0: */ michael@0: michael@0: /* michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions michael@0: are met: michael@0: michael@0: - Redistributions of source code must retain the above copyright michael@0: notice, this list of conditions and the following disclaimer. michael@0: michael@0: - Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER michael@0: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF michael@0: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING michael@0: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS michael@0: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifndef CELT_H michael@0: #define CELT_H michael@0: michael@0: #include "opus_types.h" michael@0: #include "opus_defines.h" michael@0: #include "opus_custom.h" michael@0: #include "entenc.h" michael@0: #include "entdec.h" michael@0: #include "arch.h" michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: #define CELTEncoder OpusCustomEncoder michael@0: #define CELTDecoder OpusCustomDecoder michael@0: #define CELTMode OpusCustomMode michael@0: michael@0: typedef struct { michael@0: int valid; michael@0: float tonality; michael@0: float tonality_slope; michael@0: float noisiness; michael@0: float activity; michael@0: float music_prob; michael@0: int bandwidth; michael@0: }AnalysisInfo; michael@0: michael@0: #define __celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (const CELTMode**)(ptr))) michael@0: michael@0: #define __celt_check_analysis_ptr(ptr) ((ptr) + ((ptr) - (const AnalysisInfo*)(ptr))) michael@0: michael@0: /* Encoder/decoder Requests */ michael@0: michael@0: /* Expose this option again when variable framesize actually works */ michael@0: #define OPUS_FRAMESIZE_VARIABLE 5010 /**< Optimize the frame size dynamically */ michael@0: michael@0: michael@0: #define CELT_SET_PREDICTION_REQUEST 10002 michael@0: /** Controls the use of interframe prediction. michael@0: 0=Independent frames michael@0: 1=Short term interframe prediction allowed michael@0: 2=Long term prediction allowed michael@0: */ michael@0: #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, __opus_check_int(x) michael@0: michael@0: #define CELT_SET_INPUT_CLIPPING_REQUEST 10004 michael@0: #define CELT_SET_INPUT_CLIPPING(x) CELT_SET_INPUT_CLIPPING_REQUEST, __opus_check_int(x) michael@0: michael@0: #define CELT_GET_AND_CLEAR_ERROR_REQUEST 10007 michael@0: #define CELT_GET_AND_CLEAR_ERROR(x) CELT_GET_AND_CLEAR_ERROR_REQUEST, __opus_check_int_ptr(x) michael@0: michael@0: #define CELT_SET_CHANNELS_REQUEST 10008 michael@0: #define CELT_SET_CHANNELS(x) CELT_SET_CHANNELS_REQUEST, __opus_check_int(x) michael@0: michael@0: michael@0: /* Internal */ michael@0: #define CELT_SET_START_BAND_REQUEST 10010 michael@0: #define CELT_SET_START_BAND(x) CELT_SET_START_BAND_REQUEST, __opus_check_int(x) michael@0: michael@0: #define CELT_SET_END_BAND_REQUEST 10012 michael@0: #define CELT_SET_END_BAND(x) CELT_SET_END_BAND_REQUEST, __opus_check_int(x) michael@0: michael@0: #define CELT_GET_MODE_REQUEST 10015 michael@0: /** Get the CELTMode used by an encoder or decoder */ michael@0: #define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, __celt_check_mode_ptr_ptr(x) michael@0: michael@0: #define CELT_SET_SIGNALLING_REQUEST 10016 michael@0: #define CELT_SET_SIGNALLING(x) CELT_SET_SIGNALLING_REQUEST, __opus_check_int(x) michael@0: michael@0: #define CELT_SET_TONALITY_REQUEST 10018 michael@0: #define CELT_SET_TONALITY(x) CELT_SET_TONALITY_REQUEST, __opus_check_int(x) michael@0: #define CELT_SET_TONALITY_SLOPE_REQUEST 10020 michael@0: #define CELT_SET_TONALITY_SLOPE(x) CELT_SET_TONALITY_SLOPE_REQUEST, __opus_check_int(x) michael@0: michael@0: #define CELT_SET_ANALYSIS_REQUEST 10022 michael@0: #define CELT_SET_ANALYSIS(x) CELT_SET_ANALYSIS_REQUEST, __celt_check_analysis_ptr(x) michael@0: michael@0: #define OPUS_SET_LFE_REQUEST 10024 michael@0: #define OPUS_SET_LFE(x) OPUS_SET_LFE_REQUEST, __opus_check_int(x) michael@0: michael@0: #define OPUS_SET_ENERGY_MASK_REQUEST 10026 michael@0: #define OPUS_SET_ENERGY_MASK(x) OPUS_SET_ENERGY_MASK_REQUEST, __opus_check_val16_ptr(x) michael@0: michael@0: /* Encoder stuff */ michael@0: michael@0: int celt_encoder_get_size(int channels); michael@0: michael@0: 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: michael@0: int celt_encoder_init(CELTEncoder *st, opus_int32 sampling_rate, int channels, michael@0: int arch); michael@0: michael@0: michael@0: michael@0: /* Decoder stuff */ michael@0: michael@0: int celt_decoder_get_size(int channels); michael@0: michael@0: michael@0: int celt_decoder_init(CELTDecoder *st, opus_int32 sampling_rate, int channels); michael@0: michael@0: 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: michael@0: #define celt_encoder_ctl opus_custom_encoder_ctl michael@0: #define celt_decoder_ctl opus_custom_decoder_ctl michael@0: michael@0: michael@0: #ifdef CUSTOM_MODES michael@0: #define OPUS_CUSTOM_NOSTATIC michael@0: #else michael@0: #define OPUS_CUSTOM_NOSTATIC static OPUS_INLINE michael@0: #endif michael@0: michael@0: static const unsigned char trim_icdf[11] = {126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0}; michael@0: /* Probs: NONE: 21.875%, LIGHT: 6.25%, NORMAL: 65.625%, AGGRESSIVE: 6.25% */ michael@0: static const unsigned char spread_icdf[4] = {25, 23, 2, 0}; michael@0: michael@0: static const unsigned char tapset_icdf[3]={2,1,0}; michael@0: michael@0: #ifdef CUSTOM_MODES michael@0: static const unsigned char toOpusTable[20] = { michael@0: 0xE0, 0xE8, 0xF0, 0xF8, michael@0: 0xC0, 0xC8, 0xD0, 0xD8, michael@0: 0xA0, 0xA8, 0xB0, 0xB8, michael@0: 0x00, 0x00, 0x00, 0x00, michael@0: 0x80, 0x88, 0x90, 0x98, michael@0: }; michael@0: michael@0: static const unsigned char fromOpusTable[16] = { michael@0: 0x80, 0x88, 0x90, 0x98, michael@0: 0x40, 0x48, 0x50, 0x58, michael@0: 0x20, 0x28, 0x30, 0x38, michael@0: 0x00, 0x08, 0x10, 0x18 michael@0: }; michael@0: michael@0: static OPUS_INLINE int toOpus(unsigned char c) michael@0: { michael@0: int ret=0; michael@0: if (c<0xA0) michael@0: ret = toOpusTable[c>>3]; michael@0: if (ret == 0) michael@0: return -1; michael@0: else michael@0: return ret|(c&0x7); michael@0: } michael@0: michael@0: static OPUS_INLINE int fromOpus(unsigned char c) michael@0: { michael@0: if (c<0x80) michael@0: return -1; michael@0: else michael@0: return fromOpusTable[(c>>3)-16] | (c&0x7); michael@0: } michael@0: #endif /* CUSTOM_MODES */ michael@0: michael@0: #define COMBFILTER_MAXPERIOD 1024 michael@0: #define COMBFILTER_MINPERIOD 15 michael@0: michael@0: extern const signed char tf_select_table[4][8]; michael@0: michael@0: int resampling_factor(opus_int32 rate); michael@0: michael@0: void celt_preemphasis(const opus_val16 * OPUS_RESTRICT pcmp, celt_sig * OPUS_RESTRICT inp, michael@0: int N, int CC, int upsample, const opus_val16 *coef, celt_sig *mem, int clip); michael@0: michael@0: void comb_filter(opus_val32 *y, opus_val32 *x, int T0, int T1, int N, michael@0: opus_val16 g0, opus_val16 g1, int tapset0, int tapset1, michael@0: const opus_val16 *window, int overlap); michael@0: michael@0: void init_caps(const CELTMode *m,int *cap,int LM,int C); michael@0: michael@0: #ifdef RESYNTH michael@0: 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: michael@0: void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X, michael@0: celt_sig * OPUS_RESTRICT out_mem[], int C, int LM); michael@0: #endif michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: #endif /* CELT_H */