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