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                                 int32_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(float* signal_out, ISACLBDecStruct* ISACdec_obj,
35                        int16_t* current_framesamples,
36                        int16_t isRCUPayload);
37
38int WebRtcIsac_DecodeRcuLb(float* signal_out, ISACLBDecStruct* ISACdec_obj,
39                           int16_t* current_framesamples);
40
41int WebRtcIsac_EncodeLb(float* in, ISACLBEncStruct* ISACencLB_obj,
42                        int16_t codingMode, int16_t
43                        bottleneckIndex);
44
45int WebRtcIsac_EncodeStoredDataLb(const ISAC_SaveEncData_t* ISACSavedEnc_obj,
46                                  Bitstr* ISACBitStr_obj, int BWnumber,
47                                  float scale);
48
49int WebRtcIsac_EncodeStoredDataUb(
50    const ISACUBSaveEncDataStruct* ISACSavedEnc_obj, Bitstr* bitStream,
51    int32_t jitterInfo, float scale, enum ISACBandwidth bandwidth);
52
53int16_t 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
75int16_t WebRtcIsac_RateAllocation(int32_t 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 */
96int WebRtcIsac_DecodeUb16(float* signal_out, ISACUBDecStruct* ISACdec_obj,
97                          int16_t 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 */
115int WebRtcIsac_DecodeUb12(float* signal_out, ISACUBDecStruct* ISACdec_obj,
116                          int16_t 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 */
134int WebRtcIsac_EncodeUb16(float* in, ISACUBEncStruct* ISACenc_obj,
135                          int32_t 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 */
153int WebRtcIsac_EncodeUb12(float* in, ISACUBEncStruct* ISACenc_obj,
154                          int32_t jitterInfo);
155
156/************************** initialization functions *************************/
157
158void WebRtcIsac_InitMasking(MaskFiltstr* maskdata);
159
160void WebRtcIsac_InitPreFilterbank(PreFiltBankstr* prefiltdata);
161
162void WebRtcIsac_InitPostFilterbank(PostFiltBankstr* postfiltdata);
163
164void WebRtcIsac_InitPitchFilter(PitchFiltstr* pitchfiltdata);
165
166void WebRtcIsac_InitPitchAnalysis(PitchAnalysisStruct* State);
167
168
169/**************************** transform functions ****************************/
170
171void WebRtcIsac_InitTransform();
172
173void WebRtcIsac_Time2Spec(double* inre1, double* inre2, int16_t* outre,
174                          int16_t* outim, FFTstr* fftstr_obj);
175
176void WebRtcIsac_Spec2time(double* inre, double* inim, double* outre1,
177                          double* outre2, FFTstr* fftstr_obj);
178
179
180/******************************* filter functions ****************************/
181
182void WebRtcIsac_AllPoleFilter(double* InOut, double* Coef, int lengthInOut,
183                              int orderCoef);
184
185void WebRtcIsac_AllZeroFilter(double* In, double* Coef, int lengthInOut,
186                              int orderCoef, double* Out);
187
188void WebRtcIsac_ZeroPoleFilter(double* In, double* ZeroCoef, double* PoleCoef,
189                               int lengthInOut, int orderCoef, double* Out);
190
191
192/***************************** filterbank functions **************************/
193
194void WebRtcIsac_SplitAndFilterFloat(float* in, float* LP, float* HP,
195                                    double* LP_la, double* HP_la,
196                                    PreFiltBankstr* prefiltdata);
197
198
199void WebRtcIsac_FilterAndCombineFloat(float* InLP, float* InHP, float* Out,
200                                      PostFiltBankstr* postfiltdata);
201
202
203/************************* normalized lattice filters ************************/
204
205void WebRtcIsac_NormLatticeFilterMa(int orderCoef, float* stateF, float* stateG,
206                                    float* lat_in, double* filtcoeflo,
207                                    double* lat_out);
208
209void WebRtcIsac_NormLatticeFilterAr(int orderCoef, float* stateF, float* stateG,
210                                    double* lat_in, double* lo_filt_coef,
211                                    float* lat_out);
212
213void WebRtcIsac_Dir2Lat(double* a, int orderCoef, float* sth, float* cth);
214
215void 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