• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * entropy_coding.h
13  *
14  * This header file declares all of the functions used to arithmetically
15  * encode the iSAC bistream
16  *
17  */
18 
19 #ifndef MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_
20 #define MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_
21 
22 #include "modules/audio_coding/codecs/isac/main/source/settings.h"
23 #include "modules/audio_coding/codecs/isac/main/source/structs.h"
24 
25 /******************************************************************************
26  * WebRtcIsac_DecodeSpec()
27  * Decode real and imaginary part of the DFT coefficients, given a bit-stream.
28  * The decoded DFT coefficient can be transformed to time domain by
29  * WebRtcIsac_Time2Spec().
30  *
31  * Input:
32  *  - streamdata            : pointer to a stucture containg the encoded
33  *                            data and theparameters needed for entropy
34  *                            coding.
35  *  - AvgPitchGain_Q12      : average pitch-gain of the frame. This is only
36  *                            relevant for 0-4 kHz band, and the input value is
37  *                            not used in other bands.
38  *  - band                  : specifies which band's DFT should be decoded.
39  *
40  * Output:
41  *   - *fr                  : pointer to a buffer where the real part of DFT
42  *                            coefficients are written to.
43  *   - *fi                  : pointer to a buffer where the imaginary part
44  *                            of DFT coefficients are written to.
45  *
46  * Return value             : < 0 if an error occures
47  *                              0 if succeeded.
48  */
49 int WebRtcIsac_DecodeSpec(Bitstr* streamdata,
50                           int16_t AvgPitchGain_Q12,
51                           enum ISACBand band,
52                           double* fr,
53                           double* fi);
54 
55 /******************************************************************************
56  * WebRtcIsac_EncodeSpec()
57  * Encode real and imaginary part of the DFT coefficients into the given
58  * bit-stream.
59  *
60  * Input:
61  *  - *fr                   : pointer to a buffer where the real part of DFT
62  *                            coefficients are written to.
63  *  - *fi                   : pointer to a buffer where the imaginary part
64  *                            of DFT coefficients are written to.
65  *  - AvgPitchGain_Q12      : average pitch-gain of the frame. This is only
66  *                            relevant for 0-4 kHz band, and the input value is
67  *                            not used in other bands.
68  *  - band                  : specifies which band's DFT should be decoded.
69  *
70  * Output:
71  *  - streamdata            : pointer to a stucture containg the encoded
72  *                            data and theparameters needed for entropy
73  *                            coding.
74  *
75  * Return value             : < 0 if an error occures
76  *                              0 if succeeded.
77  */
78 int WebRtcIsac_EncodeSpec(const int16_t* fr,
79                           const int16_t* fi,
80                           int16_t AvgPitchGain_Q12,
81                           enum ISACBand band,
82                           Bitstr* streamdata);
83 
84 /* decode & dequantize LPC Coef */
85 int WebRtcIsac_DecodeLpcCoef(Bitstr* streamdata, double* LPCCoef);
86 int WebRtcIsac_DecodeLpcCoefUB(Bitstr* streamdata,
87                                double* lpcVecs,
88                                double* percepFilterGains,
89                                int16_t bandwidth);
90 
91 int WebRtcIsac_DecodeLpc(Bitstr* streamdata,
92                          double* LPCCoef_lo,
93                          double* LPCCoef_hi);
94 
95 /* quantize & code LPC Coef */
96 void WebRtcIsac_EncodeLpcLb(double* LPCCoef_lo,
97                             double* LPCCoef_hi,
98                             Bitstr* streamdata,
99                             IsacSaveEncoderData* encData);
100 
101 void WebRtcIsac_EncodeLpcGainLb(double* LPCCoef_lo,
102                                 double* LPCCoef_hi,
103                                 Bitstr* streamdata,
104                                 IsacSaveEncoderData* encData);
105 
106 /******************************************************************************
107  * WebRtcIsac_EncodeLpcUB()
108  * Encode LPC parameters, given as A-polynomial, of upper-band. The encoding
109  * is performed in LAR domain.
110  * For the upper-band, we compute and encode LPC of some sub-frames, LPC of
111  * other sub-frames are computed by linear interpolation, in LAR domain. This
112  * function performs the interpolation and returns the LPC of all sub-frames.
113  *
114  * Inputs:
115  *  - lpcCoef               : a buffer containing A-polynomials of sub-frames
116  *                            (excluding first coefficient that is 1).
117  *  - bandwidth             : specifies if the codec is operating at 0-12 kHz
118  *                            or 0-16 kHz mode.
119  *
120  * Input/output:
121  *  - streamdata            : pointer to a structure containing the encoded
122  *                            data and the parameters needed for entropy
123  *                            coding.
124  *
125  * Output:
126  *  - interpolLPCCoeff      : Decoded and interpolated LPC (A-polynomial)
127  *                            of all sub-frames.
128  *                            If LP analysis is of order K, and there are N
129  *                            sub-frames then this is a buffer of size
130  *                            (k + 1) * N, each vector starts with the LPC gain
131  *                            of the corresponding sub-frame. The LPC gains
132  *                            are encoded and inserted after this function is
133  *                            called. The first A-coefficient which is 1 is not
134  *                            included.
135  *
136  * Return value             : 0 if encoding is successful,
137  *                           <0 if failed to encode.
138  */
139 int16_t WebRtcIsac_EncodeLpcUB(double* lpcCoeff,
140                                Bitstr* streamdata,
141                                double* interpolLPCCoeff,
142                                int16_t bandwidth,
143                                ISACUBSaveEncDataStruct* encData);
144 
145 /******************************************************************************
146  * WebRtcIsac_DecodeInterpolLpcUb()
147  * Decode LPC coefficients and interpolate to get the coefficients fo all
148  * sub-frmaes.
149  *
150  * Inputs:
151  *  - bandwidth             : spepecifies if the codec is in 0-12 kHz or
152  *                            0-16 kHz mode.
153  *
154  * Input/output:
155  *  - streamdata            : pointer to a stucture containg the encoded
156  *                            data and theparameters needed for entropy
157  *                            coding.
158  *
159  * Output:
160  *  - percepFilterParam     : Decoded and interpolated LPC (A-polynomial) of
161  *                            all sub-frames.
162  *                            If LP analysis is of order K, and there are N
163  *                            sub-frames then this is a buffer of size
164  *                            (k + 1) * N, each vector starts with the LPC gain
165  *                            of the corresponding sub-frame. The LPC gains
166  *                            are encoded and inserted after this function is
167  *                            called. The first A-coefficient which is 1 is not
168  *                            included.
169  *
170  * Return value             : 0 if encoding is successful,
171  *                           <0 if failed to encode.
172  */
173 int16_t WebRtcIsac_DecodeInterpolLpcUb(Bitstr* streamdata,
174                                        double* percepFilterParam,
175                                        int16_t bandwidth);
176 
177 /* Decode & dequantize RC */
178 int WebRtcIsac_DecodeRc(Bitstr* streamdata, int16_t* RCQ15);
179 
180 /* Quantize & code RC */
181 void WebRtcIsac_EncodeRc(int16_t* RCQ15, Bitstr* streamdata);
182 
183 /* Decode & dequantize squared Gain */
184 int WebRtcIsac_DecodeGain2(Bitstr* streamdata, int32_t* Gain2);
185 
186 /* Quantize & code squared Gain (input is squared gain) */
187 int WebRtcIsac_EncodeGain2(int32_t* gain2, Bitstr* streamdata);
188 
189 void WebRtcIsac_EncodePitchGain(int16_t* PitchGains_Q12,
190                                 Bitstr* streamdata,
191                                 IsacSaveEncoderData* encData);
192 
193 void WebRtcIsac_EncodePitchLag(double* PitchLags,
194                                int16_t* PitchGain_Q12,
195                                Bitstr* streamdata,
196                                IsacSaveEncoderData* encData);
197 
198 int WebRtcIsac_DecodePitchGain(Bitstr* streamdata, int16_t* PitchGain_Q12);
199 int WebRtcIsac_DecodePitchLag(Bitstr* streamdata,
200                               int16_t* PitchGain_Q12,
201                               double* PitchLag);
202 
203 int WebRtcIsac_DecodeFrameLen(Bitstr* streamdata, int16_t* framelength);
204 int WebRtcIsac_EncodeFrameLen(int16_t framelength, Bitstr* streamdata);
205 int WebRtcIsac_DecodeSendBW(Bitstr* streamdata, int16_t* BWno);
206 void WebRtcIsac_EncodeReceiveBw(int* BWno, Bitstr* streamdata);
207 
208 /* Step-down */
209 void WebRtcIsac_Poly2Rc(double* a, int N, double* RC);
210 
211 /* Step-up */
212 void WebRtcIsac_Rc2Poly(double* RC, int N, double* a);
213 
214 void WebRtcIsac_TranscodeLPCCoef(double* LPCCoef_lo,
215                                  double* LPCCoef_hi,
216                                  int* index_g);
217 
218 /******************************************************************************
219  * WebRtcIsac_EncodeLpcGainUb()
220  * Encode LPC gains of sub-Frames.
221  *
222  * Input/outputs:
223  *  - lpGains               : a buffer which contains 'SUBFRAME' number of
224  *                            LP gains to be encoded. The input values are
225  *                            overwritten by the quantized values.
226  *  - streamdata            : pointer to a stucture containg the encoded
227  *                            data and theparameters needed for entropy
228  *                            coding.
229  *
230  * Output:
231  *  - lpcGainIndex          : quantization indices for lpc gains, these will
232  *                            be stored to be used  for FEC.
233  */
234 void WebRtcIsac_EncodeLpcGainUb(double* lpGains,
235                                 Bitstr* streamdata,
236                                 int* lpcGainIndex);
237 
238 /******************************************************************************
239  * WebRtcIsac_EncodeLpcGainUb()
240  * Store LPC gains of sub-Frames in 'streamdata'.
241  *
242  * Input:
243  *  - lpGains               : a buffer which contains 'SUBFRAME' number of
244  *                            LP gains to be encoded.
245  * Input/outputs:
246  *  - streamdata            : pointer to a stucture containg the encoded
247  *                            data and theparameters needed for entropy
248  *                            coding.
249  *
250  */
251 void WebRtcIsac_StoreLpcGainUb(double* lpGains, Bitstr* streamdata);
252 
253 /******************************************************************************
254  * WebRtcIsac_DecodeLpcGainUb()
255  * Decode the LPC gain of sub-frames.
256  *
257  * Input/output:
258  *  - streamdata            : pointer to a stucture containg the encoded
259  *                            data and theparameters needed for entropy
260  *                            coding.
261  *
262  * Output:
263  *  - lpGains               : a buffer where decoded LPC gians will be stored.
264  *
265  * Return value             : 0 if succeeded.
266  *                           <0 if failed.
267  */
268 int16_t WebRtcIsac_DecodeLpcGainUb(double* lpGains, Bitstr* streamdata);
269 
270 /******************************************************************************
271  * WebRtcIsac_EncodeBandwidth()
272  * Encode if the bandwidth of encoded audio is 0-12 kHz or 0-16 kHz.
273  *
274  * Input:
275  *  - bandwidth             : an enumerator specifying if the codec in is
276  *                            0-12 kHz or 0-16 kHz mode.
277  *
278  * Input/output:
279  *  - streamdata            : pointer to a stucture containg the encoded
280  *                            data and theparameters needed for entropy
281  *                            coding.
282  *
283  * Return value             : 0 if succeeded.
284  *                           <0 if failed.
285  */
286 int16_t WebRtcIsac_EncodeBandwidth(enum ISACBandwidth bandwidth,
287                                    Bitstr* streamData);
288 
289 /******************************************************************************
290  * WebRtcIsac_DecodeBandwidth()
291  * Decode the bandwidth of the encoded audio, i.e. if the bandwidth is 0-12 kHz
292  * or 0-16 kHz.
293  *
294  * Input/output:
295  *  - streamdata            : pointer to a stucture containg the encoded
296  *                            data and theparameters needed for entropy
297  *                            coding.
298  *
299  * Output:
300  *  - bandwidth             : an enumerator specifying if the codec is in
301  *                            0-12 kHz or 0-16 kHz mode.
302  *
303  * Return value             : 0 if succeeded.
304  *                           <0 if failed.
305  */
306 int16_t WebRtcIsac_DecodeBandwidth(Bitstr* streamData,
307                                    enum ISACBandwidth* bandwidth);
308 
309 /******************************************************************************
310  * WebRtcIsac_EncodeJitterInfo()
311  * Decode the jitter information.
312  *
313  * Input/output:
314  *  - streamdata            : pointer to a stucture containg the encoded
315  *                            data and theparameters needed for entropy
316  *                            coding.
317  *
318  * Input:
319  *  - jitterInfo            : one bit of info specifying if the channel is
320  *                            in high/low jitter. Zero indicates low jitter
321  *                            and one indicates high jitter.
322  *
323  * Return value             : 0 if succeeded.
324  *                           <0 if failed.
325  */
326 int16_t WebRtcIsac_EncodeJitterInfo(int32_t jitterIndex, Bitstr* streamData);
327 
328 /******************************************************************************
329  * WebRtcIsac_DecodeJitterInfo()
330  * Decode the jitter information.
331  *
332  * Input/output:
333  *  - streamdata            : pointer to a stucture containg the encoded
334  *                            data and theparameters needed for entropy
335  *                            coding.
336  *
337  * Output:
338  *  - jitterInfo            : one bit of info specifying if the channel is
339  *                            in high/low jitter. Zero indicates low jitter
340  *                            and one indicates high jitter.
341  *
342  * Return value             : 0 if succeeded.
343  *                           <0 if failed.
344  */
345 int16_t WebRtcIsac_DecodeJitterInfo(Bitstr* streamData, int32_t* jitterInfo);
346 
347 #endif /* MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENTROPY_CODING_H_ */
348