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 MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ 20 #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ 21 22 #include <stddef.h> 23 24 #include "modules/audio_coding/codecs/isac/main/source/structs.h" 25 #include "modules/third_party/fft/fft.h" 26 27 void WebRtcIsac_ResetBitstream(Bitstr* bit_stream); 28 29 int WebRtcIsac_EstimateBandwidth(BwEstimatorstr* bwest_str, 30 Bitstr* streamdata, 31 size_t packet_size, 32 uint16_t rtp_seq_number, 33 uint32_t send_ts, 34 uint32_t arr_ts, 35 enum IsacSamplingRate encoderSampRate, 36 enum IsacSamplingRate decoderSampRate); 37 38 int WebRtcIsac_DecodeLb(const TransformTables* transform_tables, 39 float* signal_out, 40 ISACLBDecStruct* ISACdec_obj, 41 int16_t* current_framesamples, 42 int16_t isRCUPayload); 43 44 int WebRtcIsac_DecodeRcuLb(float* signal_out, 45 ISACLBDecStruct* ISACdec_obj, 46 int16_t* current_framesamples); 47 48 int WebRtcIsac_EncodeLb(const TransformTables* transform_tables, 49 float* in, 50 ISACLBEncStruct* ISACencLB_obj, 51 int16_t codingMode, 52 int16_t bottleneckIndex); 53 54 int WebRtcIsac_EncodeStoredDataLb(const IsacSaveEncoderData* ISACSavedEnc_obj, 55 Bitstr* ISACBitStr_obj, 56 int BWnumber, 57 float scale); 58 59 int WebRtcIsac_EncodeStoredDataUb( 60 const ISACUBSaveEncDataStruct* ISACSavedEnc_obj, 61 Bitstr* bitStream, 62 int32_t jitterInfo, 63 float scale, 64 enum ISACBandwidth bandwidth); 65 66 int16_t WebRtcIsac_GetRedPayloadUb( 67 const ISACUBSaveEncDataStruct* ISACSavedEncObj, 68 Bitstr* bitStreamObj, 69 enum ISACBandwidth bandwidth); 70 71 /****************************************************************************** 72 * WebRtcIsac_RateAllocation() 73 * Internal function to perform a rate-allocation for upper and lower-band, 74 * given a total rate. 75 * 76 * Input: 77 * - inRateBitPerSec : a total bit-rate in bits/sec. 78 * 79 * Output: 80 * - rateLBBitPerSec : a bit-rate allocated to the lower-band 81 * in bits/sec. 82 * - rateUBBitPerSec : a bit-rate allocated to the upper-band 83 * in bits/sec. 84 * 85 * Return value : 0 if rate allocation has been successful. 86 * -1 if failed to allocate rates. 87 */ 88 89 int16_t WebRtcIsac_RateAllocation(int32_t inRateBitPerSec, 90 double* rateLBBitPerSec, 91 double* rateUBBitPerSec, 92 enum ISACBandwidth* bandwidthKHz); 93 94 /****************************************************************************** 95 * WebRtcIsac_DecodeUb16() 96 * 97 * Decode the upper-band if the codec is in 0-16 kHz mode. 98 * 99 * Input/Output: 100 * -ISACdec_obj : pointer to the upper-band decoder object. The 101 * bit-stream is stored inside the decoder object. 102 * 103 * Output: 104 * -signal_out : decoded audio, 480 samples 30 ms. 105 * 106 * Return value : >0 number of decoded bytes. 107 * <0 if an error occurred. 108 */ 109 int WebRtcIsac_DecodeUb16(const TransformTables* transform_tables, 110 float* signal_out, 111 ISACUBDecStruct* ISACdec_obj, 112 int16_t isRCUPayload); 113 114 /****************************************************************************** 115 * WebRtcIsac_DecodeUb12() 116 * 117 * Decode the upper-band if the codec is in 0-12 kHz mode. 118 * 119 * Input/Output: 120 * -ISACdec_obj : pointer to the upper-band decoder object. The 121 * bit-stream is stored inside the decoder object. 122 * 123 * Output: 124 * -signal_out : decoded audio, 480 samples 30 ms. 125 * 126 * Return value : >0 number of decoded bytes. 127 * <0 if an error occurred. 128 */ 129 int WebRtcIsac_DecodeUb12(const TransformTables* transform_tables, 130 float* signal_out, 131 ISACUBDecStruct* ISACdec_obj, 132 int16_t isRCUPayload); 133 134 /****************************************************************************** 135 * WebRtcIsac_EncodeUb16() 136 * 137 * Encode the upper-band if the codec is in 0-16 kHz mode. 138 * 139 * Input: 140 * -in : upper-band audio, 160 samples (10 ms). 141 * 142 * Input/Output: 143 * -ISACdec_obj : pointer to the upper-band encoder object. The 144 * bit-stream is stored inside the encoder object. 145 * 146 * Return value : >0 number of encoded bytes. 147 * <0 if an error occurred. 148 */ 149 int WebRtcIsac_EncodeUb16(const TransformTables* transform_tables, 150 float* in, 151 ISACUBEncStruct* ISACenc_obj, 152 int32_t jitterInfo); 153 154 /****************************************************************************** 155 * WebRtcIsac_EncodeUb12() 156 * 157 * Encode the upper-band if the codec is in 0-12 kHz mode. 158 * 159 * Input: 160 * -in : upper-band audio, 160 samples (10 ms). 161 * 162 * Input/Output: 163 * -ISACdec_obj : pointer to the upper-band encoder object. The 164 * bit-stream is stored inside the encoder object. 165 * 166 * Return value : >0 number of encoded bytes. 167 * <0 if an error occurred. 168 */ 169 int WebRtcIsac_EncodeUb12(const TransformTables* transform_tables, 170 float* in, 171 ISACUBEncStruct* ISACenc_obj, 172 int32_t jitterInfo); 173 174 /************************** initialization functions *************************/ 175 176 void WebRtcIsac_InitMasking(MaskFiltstr* maskdata); 177 178 void WebRtcIsac_InitPostFilterbank(PostFiltBankstr* postfiltdata); 179 180 /**************************** transform functions ****************************/ 181 182 void WebRtcIsac_InitTransform(TransformTables* tables); 183 184 void WebRtcIsac_Time2Spec(const TransformTables* tables, 185 double* inre1, 186 double* inre2, 187 int16_t* outre, 188 int16_t* outim, 189 FFTstr* fftstr_obj); 190 191 void WebRtcIsac_Spec2time(const TransformTables* tables, 192 double* inre, 193 double* inim, 194 double* outre1, 195 double* outre2, 196 FFTstr* fftstr_obj); 197 198 /***************************** filterbank functions **************************/ 199 200 void WebRtcIsac_FilterAndCombineFloat(float* InLP, 201 float* InHP, 202 float* Out, 203 PostFiltBankstr* postfiltdata); 204 205 /************************* normalized lattice filters ************************/ 206 207 void WebRtcIsac_NormLatticeFilterMa(int orderCoef, 208 float* stateF, 209 float* stateG, 210 float* lat_in, 211 double* filtcoeflo, 212 double* lat_out); 213 214 void WebRtcIsac_NormLatticeFilterAr(int orderCoef, 215 float* stateF, 216 float* stateG, 217 double* lat_in, 218 double* lo_filt_coef, 219 float* lat_out); 220 221 void WebRtcIsac_Dir2Lat(double* a, int orderCoef, float* sth, float* cth); 222 223 #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_CODEC_H_ */ 224