1 /*
2  *  Copyright (c) 2011 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  * encode_lpc_swb.h
13  *
14  * This file contains declaration of functions used to
15  * encode LPC parameters (Shape & gain) of the upper band.
16  *
17  */
18 
19 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_
20 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_
21 
22 #include "settings.h"
23 #include "structs.h"
24 #include "webrtc/typedefs.h"
25 
26 /******************************************************************************
27  * WebRtcIsac_RemoveLarMean()
28  *
29  * Remove the means from LAR coefficients.
30  *
31  * Input:
32  *      -lar                : pointer to lar vectors. LAR vectors are
33  *                            concatenated.
34  *      -bandwidth          : indicates if the given LAR vectors belong
35  *                            to SWB-12kHz or SWB-16kHz.
36  *
37  * Output:
38  *      -lar                : pointer to mean-removed LAR:s.
39  *
40  *
41  */
42 int16_t WebRtcIsac_RemoveLarMean(
43     double*     lar,
44     int16_t bandwidth);
45 
46 /******************************************************************************
47  * WebRtcIsac_DecorrelateIntraVec()
48  *
49  * Remove the correlation amonge the components of LAR vectors. If LAR vectors
50  * of one frame are put in a matrix where each column is a LAR vector of a
51  * sub-frame, then this is equivalent to multiplying the LAR matrix with
52  * a decorrelting mtrix from left.
53  *
54  * Input:
55  *      -inLar              : pointer to mean-removed LAR vecrtors.
56  *      -bandwidth          : indicates if the given LAR vectors belong
57  *                            to SWB-12kHz or SWB-16kHz.
58  *
59  * Output:
60  *      -out                : decorrelated LAR vectors.
61  */
62 int16_t WebRtcIsac_DecorrelateIntraVec(
63     const double* inLAR,
64     double*       out,
65     int16_t   bandwidth);
66 
67 
68 /******************************************************************************
69  * WebRtcIsac_DecorrelateInterVec()
70  *
71  * Remover the correlation among mean-removed LAR vectors. If LAR vectors
72  * of one frame are put in a matrix where each column is a LAR vector of a
73  * sub-frame, then this is equivalent to multiplying the LAR matrix with
74  * a decorrelting mtrix from right.
75  *
76  * Input:
77  *      -data               : pointer to matrix of LAR vectors. The matrix
78  *                            is stored column-wise.
79  *      -bandwidth          : indicates if the given LAR vectors belong
80  *                            to SWB-12kHz or SWB-16kHz.
81  *
82  * Output:
83  *      -out                : decorrelated LAR vectors.
84  */
85 int16_t WebRtcIsac_DecorrelateInterVec(
86     const double* data,
87     double*       out,
88     int16_t   bandwidth);
89 
90 
91 /******************************************************************************
92  * WebRtcIsac_QuantizeUncorrLar()
93  *
94  * Quantize the uncorrelated parameters.
95  *
96  * Input:
97  *      -data               : uncorrelated LAR vectors.
98  *      -bandwidth          : indicates if the given LAR vectors belong
99  *                            to SWB-12kHz or SWB-16kHz.
100  *
101  * Output:
102  *      -data               : quantized version of the input.
103  *      -idx                : pointer to quantization indices.
104  */
105 double WebRtcIsac_QuantizeUncorrLar(
106     double*     data,
107     int*        idx,
108     int16_t bandwidth);
109 
110 
111 /******************************************************************************
112  * WebRtcIsac_CorrelateIntraVec()
113  *
114  * This is the inverse of WebRtcIsac_DecorrelateIntraVec().
115  *
116  * Input:
117  *      -data               : uncorrelated parameters.
118  *      -bandwidth          : indicates if the given LAR vectors belong
119  *                            to SWB-12kHz or SWB-16kHz.
120  *
121  * Output:
122  *      -out                : correlated parametrs.
123  */
124 int16_t WebRtcIsac_CorrelateIntraVec(
125     const double* data,
126     double*       out,
127     int16_t   bandwidth);
128 
129 
130 /******************************************************************************
131  * WebRtcIsac_CorrelateInterVec()
132  *
133  * This is the inverse of WebRtcIsac_DecorrelateInterVec().
134  *
135  * Input:
136  *      -data
137  *      -bandwidth          : indicates if the given LAR vectors belong
138  *                            to SWB-12kHz or SWB-16kHz.
139  *
140  * Output:
141  *      -out                : correlated parametrs.
142  */
143 int16_t WebRtcIsac_CorrelateInterVec(
144     const double* data,
145     double*       out,
146     int16_t   bandwidth);
147 
148 
149 /******************************************************************************
150  * WebRtcIsac_AddLarMean()
151  *
152  * This is the inverse of WebRtcIsac_RemoveLarMean()
153  *
154  * Input:
155  *      -data               : pointer to mean-removed LAR:s.
156  *      -bandwidth          : indicates if the given LAR vectors belong
157  *                            to SWB-12kHz or SWB-16kHz.
158  *
159  * Output:
160  *      -data               : pointer to LARs.
161  */
162 int16_t WebRtcIsac_AddLarMean(
163     double*     data,
164     int16_t bandwidth);
165 
166 
167 /******************************************************************************
168  * WebRtcIsac_DequantizeLpcParam()
169  *
170  * Get the quantized value of uncorrelated LARs given the quantization indices.
171  *
172  * Input:
173  *      -idx                : pointer to quantiztion indices.
174  *      -bandwidth          : indicates if the given LAR vectors belong
175  *                            to SWB-12kHz or SWB-16kHz.
176  *
177  * Output:
178  *      -out                : pointer to quantized values.
179  */
180 int16_t WebRtcIsac_DequantizeLpcParam(
181     const int*  idx,
182     double*     out,
183     int16_t bandwidth);
184 
185 
186 /******************************************************************************
187  * WebRtcIsac_ToLogDomainRemoveMean()
188  *
189  * Transform the LPC gain to log domain then remove the mean value.
190  *
191  * Input:
192  *      -lpcGain            : pointer to LPC Gain, expecting 6 LPC gains
193  *
194  * Output:
195  *      -lpcGain            : mean-removed in log domain.
196  */
197 int16_t WebRtcIsac_ToLogDomainRemoveMean(
198     double* lpGains);
199 
200 
201 /******************************************************************************
202  * WebRtcIsac_DecorrelateLPGain()
203  *
204  * Decorrelate LPC gains. There are 6 LPC Gains per frame. This is like
205  * multiplying gain vector with decorrelating matrix.
206  *
207  * Input:
208  *      -data               : LPC gain in log-domain with mean removed.
209  *
210  * Output:
211  *      -out                : decorrelated parameters.
212  */
213 int16_t WebRtcIsac_DecorrelateLPGain(
214     const double* data,
215     double*       out);
216 
217 
218 /******************************************************************************
219  * WebRtcIsac_QuantizeLpcGain()
220  *
221  * Quantize the decorrelated log-domain gains.
222  *
223  * Input:
224  *      -lpcGain            : uncorrelated LPC gains.
225  *
226  * Output:
227  *      -idx                : quantization indices
228  *      -lpcGain            : quantized value of the inpt.
229  */
230 double WebRtcIsac_QuantizeLpcGain(
231     double* lpGains,
232     int*    idx);
233 
234 
235 /******************************************************************************
236  * WebRtcIsac_DequantizeLpcGain()
237  *
238  * Get the quantized values given the quantization indices.
239  *
240  * Input:
241  *      -idx                : pointer to quantization indices.
242  *
243  * Output:
244  *      -lpcGains           : quantized values of the given parametes.
245  */
246 int16_t WebRtcIsac_DequantizeLpcGain(
247     const int* idx,
248     double*    lpGains);
249 
250 
251 /******************************************************************************
252  * WebRtcIsac_CorrelateLpcGain()
253  *
254  * This is the inverse of WebRtcIsac_DecorrelateLPGain().
255  *
256  * Input:
257  *      -data               : decorrelated parameters.
258  *
259  * Output:
260  *      -out                : correlated parameters.
261  */
262 int16_t WebRtcIsac_CorrelateLpcGain(
263     const double* data,
264     double*       out);
265 
266 
267 /******************************************************************************
268  * WebRtcIsac_AddMeanToLinearDomain()
269  *
270  * This is the inverse of WebRtcIsac_ToLogDomainRemoveMean().
271  *
272  * Input:
273  *      -lpcGain            : LPC gain in log-domain & mean removed
274  *
275  * Output:
276  *      -lpcGain            : LPC gain in normal domain.
277  */
278 int16_t WebRtcIsac_AddMeanToLinearDomain(
279     double* lpcGains);
280 
281 
282 #endif  // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_MAIN_SOURCE_ENCODE_LPC_SWB_H_
283