1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 /* 12 * codec.h 13 * 14 * This header file contains the calls to the internal encoder 15 * and decoder functions. 16 * 17 */ 18 19 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ 20 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ 21 22 #include "structs.h" 23 24 25 void WebRtcIsac_ResetBitstream(Bitstr* bit_stream); 26 27 int WebRtcIsac_EstimateBandwidth(BwEstimatorstr* bwest_str, Bitstr* streamdata, 28 WebRtc_Word32 packet_size, 29 WebRtc_UWord16 rtp_seq_number, 30 WebRtc_UWord32 send_ts, WebRtc_UWord32 arr_ts, 31 enum IsacSamplingRate encoderSampRate, 32 enum IsacSamplingRate decoderSampRate); 33 34 int WebRtcIsac_DecodeLb(float* signal_out, ISACLBDecStruct* ISACdec_obj, 35 WebRtc_Word16* current_framesamples, 36 WebRtc_Word16 isRCUPayload); 37 38 int WebRtcIsac_DecodeRcuLb(float* signal_out, ISACLBDecStruct* ISACdec_obj, 39 WebRtc_Word16* current_framesamples); 40 41 int WebRtcIsac_EncodeLb(float* in, ISACLBEncStruct* ISACencLB_obj, 42 WebRtc_Word16 codingMode, WebRtc_Word16 43 bottleneckIndex); 44 45 int WebRtcIsac_EncodeStoredDataLb(const ISAC_SaveEncData_t* ISACSavedEnc_obj, 46 Bitstr* ISACBitStr_obj, int BWnumber, 47 float scale); 48 49 int WebRtcIsac_EncodeStoredDataUb( 50 const ISACUBSaveEncDataStruct* ISACSavedEnc_obj, Bitstr* bitStream, 51 WebRtc_Word32 jitterInfo, float scale, enum ISACBandwidth bandwidth); 52 53 WebRtc_Word16 WebRtcIsac_GetRedPayloadUb( 54 const ISACUBSaveEncDataStruct* ISACSavedEncObj, Bitstr* bitStreamObj, 55 enum ISACBandwidth bandwidth); 56 57 /****************************************************************************** 58 * WebRtcIsac_RateAllocation() 59 * Internal function to perform a rate-allocation for upper and lower-band, 60 * given a total rate. 61 * 62 * Input: 63 * - inRateBitPerSec : a total bit-rate in bits/sec. 64 * 65 * Output: 66 * - rateLBBitPerSec : a bit-rate allocated to the lower-band 67 * in bits/sec. 68 * - rateUBBitPerSec : a bit-rate allocated to the upper-band 69 * in bits/sec. 70 * 71 * Return value : 0 if rate allocation has been successful. 72 * -1 if failed to allocate rates. 73 */ 74 75 WebRtc_Word16 WebRtcIsac_RateAllocation(WebRtc_Word32 inRateBitPerSec, 76 double* rateLBBitPerSec, 77 double* rateUBBitPerSec, 78 enum ISACBandwidth* bandwidthKHz); 79 80 81 /****************************************************************************** 82 * WebRtcIsac_DecodeUb16() 83 * 84 * Decode the upper-band if the codec is in 0-16 kHz mode. 85 * 86 * Input/Output: 87 * -ISACdec_obj : pointer to the upper-band decoder object. The 88 * bit-stream is stored inside the decoder object. 89 * 90 * Output: 91 * -signal_out : decoded audio, 480 samples 30 ms. 92 * 93 * Return value : >0 number of decoded bytes. 94 * <0 if an error occurred. 95 */ 96 int WebRtcIsac_DecodeUb16(float* signal_out, ISACUBDecStruct* ISACdec_obj, 97 WebRtc_Word16 isRCUPayload); 98 99 100 /****************************************************************************** 101 * WebRtcIsac_DecodeUb12() 102 * 103 * Decode the upper-band if the codec is in 0-12 kHz mode. 104 * 105 * Input/Output: 106 * -ISACdec_obj : pointer to the upper-band decoder object. The 107 * bit-stream is stored inside the decoder object. 108 * 109 * Output: 110 * -signal_out : decoded audio, 480 samples 30 ms. 111 * 112 * Return value : >0 number of decoded bytes. 113 * <0 if an error occurred. 114 */ 115 int WebRtcIsac_DecodeUb12(float* signal_out, ISACUBDecStruct* ISACdec_obj, 116 WebRtc_Word16 isRCUPayload); 117 118 119 /****************************************************************************** 120 * WebRtcIsac_EncodeUb16() 121 * 122 * Encode the upper-band if the codec is in 0-16 kHz mode. 123 * 124 * Input: 125 * -in : upper-band audio, 160 samples (10 ms). 126 * 127 * Input/Output: 128 * -ISACdec_obj : pointer to the upper-band encoder object. The 129 * bit-stream is stored inside the encoder object. 130 * 131 * Return value : >0 number of encoded bytes. 132 * <0 if an error occurred. 133 */ 134 int WebRtcIsac_EncodeUb16(float* in, ISACUBEncStruct* ISACenc_obj, 135 WebRtc_Word32 jitterInfo); 136 137 138 /****************************************************************************** 139 * WebRtcIsac_EncodeUb12() 140 * 141 * Encode the upper-band if the codec is in 0-12 kHz mode. 142 * 143 * Input: 144 * -in : upper-band audio, 160 samples (10 ms). 145 * 146 * Input/Output: 147 * -ISACdec_obj : pointer to the upper-band encoder object. The 148 * bit-stream is stored inside the encoder object. 149 * 150 * Return value : >0 number of encoded bytes. 151 * <0 if an error occurred. 152 */ 153 int WebRtcIsac_EncodeUb12(float* in, ISACUBEncStruct* ISACenc_obj, 154 WebRtc_Word32 jitterInfo); 155 156 /************************** initialization functions *************************/ 157 158 void WebRtcIsac_InitMasking(MaskFiltstr* maskdata); 159 160 void WebRtcIsac_InitPreFilterbank(PreFiltBankstr* prefiltdata); 161 162 void WebRtcIsac_InitPostFilterbank(PostFiltBankstr* postfiltdata); 163 164 void WebRtcIsac_InitPitchFilter(PitchFiltstr* pitchfiltdata); 165 166 void WebRtcIsac_InitPitchAnalysis(PitchAnalysisStruct* State); 167 168 169 /**************************** transform functions ****************************/ 170 171 void WebRtcIsac_InitTransform(); 172 173 void WebRtcIsac_Time2Spec(double* inre1, double* inre2, WebRtc_Word16* outre, 174 WebRtc_Word16* outim, FFTstr* fftstr_obj); 175 176 void WebRtcIsac_Spec2time(double* inre, double* inim, double* outre1, 177 double* outre2, FFTstr* fftstr_obj); 178 179 180 /******************************* filter functions ****************************/ 181 182 void WebRtcIsac_AllPoleFilter(double* InOut, double* Coef, int lengthInOut, 183 int orderCoef); 184 185 void WebRtcIsac_AllZeroFilter(double* In, double* Coef, int lengthInOut, 186 int orderCoef, double* Out); 187 188 void WebRtcIsac_ZeroPoleFilter(double* In, double* ZeroCoef, double* PoleCoef, 189 int lengthInOut, int orderCoef, double* Out); 190 191 192 /***************************** filterbank functions **************************/ 193 194 void WebRtcIsac_SplitAndFilterFloat(float* in, float* LP, float* HP, 195 double* LP_la, double* HP_la, 196 PreFiltBankstr* prefiltdata); 197 198 199 void WebRtcIsac_FilterAndCombineFloat(float* InLP, float* InHP, float* Out, 200 PostFiltBankstr* postfiltdata); 201 202 203 /************************* normalized lattice filters ************************/ 204 205 void WebRtcIsac_NormLatticeFilterMa(int orderCoef, float* stateF, float* stateG, 206 float* lat_in, double* filtcoeflo, 207 double* lat_out); 208 209 void WebRtcIsac_NormLatticeFilterAr(int orderCoef, float* stateF, float* stateG, 210 double* lat_in, double* lo_filt_coef, 211 float* lat_out); 212 213 void WebRtcIsac_Dir2Lat(double* a, int orderCoef, float* sth, float* cth); 214 215 void WebRtcIsac_AutoCorr(double* r, const double* x, int N, int order); 216 217 #endif /* WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ */ 218