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