Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include <math.h>
43 : #include "prot.h"
44 : #include "cnst.h"
45 : #include "rom_com.h"
46 : #include "wmc_auto.h"
47 :
48 : /*--------------------------------------------------------------------------*
49 : * Mode2_gain_dec_mless
50 : *
51 : * Decoding of pitch and codebook gains without updating long term energies
52 : *-------------------------------------------------------------------------*/
53 :
54 9060 : static void Mode2_gain_dec_mless(
55 : const int16_t index, /* i : index of quantizer */
56 : const float code[], /* i : Innovative code vector */
57 : const int16_t lcode, /* i : Subframe size */
58 : float *gain_pit, /* o : Quantized pitch gain */
59 : float *gain_code, /* o : Quantized codebook gain */
60 : float mean_ener, /* i : mean_ener defined in open-loop (2 bits) */
61 : float *past_gpit, /* i/o: past gain of pitch */
62 : float *past_gcode, /* i/o: past energy of code */
63 : float *gain_inov, /* o : un-scaled innovation gain */
64 : const int16_t coder_type /* i : coder type for number of bits */
65 : )
66 : {
67 : int16_t i;
68 : float ener_code, gcode0;
69 : const Word16 *t_qua_gain;
70 :
71 9060 : ener_code = 0.0f;
72 :
73 9060 : if ( coder_type == 0 )
74 : {
75 0 : *gain_inov = 1.0f / (float) sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode );
76 : }
77 : else
78 : {
79 9060 : ener_code = 0.01f;
80 :
81 588900 : for ( i = 0; i < lcode; i++ )
82 : {
83 579840 : ener_code += code[i] * code[i];
84 : }
85 9060 : *gain_inov = (float) sqrt( (float) lcode / ener_code );
86 : }
87 :
88 : /*-----------------------------------------------------------------*
89 : * Select the gains quantization table
90 : *-----------------------------------------------------------------*/
91 :
92 9060 : if ( coder_type == 0 )
93 : {
94 0 : t_qua_gain = E_ROM_qua_gain5b_const;
95 : }
96 9060 : else if ( coder_type == 1 )
97 : {
98 390 : t_qua_gain = E_ROM_qua_gain6b_const;
99 : }
100 : else
101 : {
102 8670 : t_qua_gain = E_ROM_qua_gain7b_const;
103 : }
104 :
105 : /*-----------------------------------------------------------------*
106 : * decode pitch gain
107 : *-----------------------------------------------------------------*/
108 :
109 9060 : *gain_pit = (float) ( t_qua_gain[index * 2] ) / ( 1 << 14 );
110 :
111 : /*-----------------------------------------------------------------*
112 : * calculate the predicted gain code
113 : *-----------------------------------------------------------------*/
114 :
115 9060 : if ( coder_type == 0 )
116 : {
117 0 : ener_code = 10 * (float) log10( ( dotp( code, code, lcode ) + 0.01f ) / lcode );
118 0 : gcode0 = (float) pow( 10, 0.05 * ( mean_ener - ener_code ) );
119 : }
120 : else
121 : {
122 9060 : ener_code = (float) ( -10.0 * log10( (float) lcode / ener_code ) );
123 9060 : gcode0 = mean_ener - ener_code;
124 9060 : gcode0 = (float) pow( 10.0, gcode0 / 20.0 ); /* predicted gain */
125 : }
126 :
127 : /*-----------------------------------------------------------------*
128 : * decode normalized codebook gain
129 : *-----------------------------------------------------------------*/
130 :
131 9060 : *gain_code = (float) ( t_qua_gain[index * 2 + 1] ) / ( 1 << 11 ) * gcode0;
132 :
133 9060 : *past_gpit = *gain_pit;
134 9060 : *past_gcode = *gain_code / *gain_inov;
135 :
136 9060 : return;
137 : }
138 :
139 :
140 : /*---------------------------------------------------------------------*
141 : * gain_dec_uv
142 : *
143 : * Decoding of pitch and codebook gains for Unvoiced mode
144 : *---------------------------------------------------------------------*/
145 :
146 0 : static void gain_dec_uv(
147 : const int16_t index, /* i/o: Quantization index vector */
148 : const float *code, /* i : algebraic code excitation */
149 : const int16_t lcode, /* i : Subframe size */
150 : float *gain_pit, /* o : Quantized pitch gain */
151 : float *gain_code, /* o : Quantized codebook gain */
152 : float *past_gpit, /* i/o: past gain of pitch */
153 : float *past_gcode, /* i/o: past energy of code */
154 : float *gain_inov /* o : unscaled innovation gain */
155 : )
156 : {
157 : /*-----------------------------------------------------------------*
158 : * Innovation energy (without gain)
159 : *-----------------------------------------------------------------*/
160 :
161 0 : *gain_inov = 1.0f / (float) sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode );
162 :
163 : /*-----------------------------------------------------------------*
164 : * Decode pitch gain
165 : *-----------------------------------------------------------------*/
166 0 : *gain_pit = 0.0f;
167 :
168 : /*-----------------------------------------------------------------*
169 : * Decode codebook gain
170 : *-----------------------------------------------------------------*/
171 :
172 0 : *gain_code = (float) pow( 10.f, ( ( ( index * 1.9f ) - 30.f ) / 20.f ) );
173 :
174 : /*-----------------------------------------------------------------*
175 : * past gains for error concealment
176 : *-----------------------------------------------------------------*/
177 :
178 0 : *past_gpit = *gain_pit;
179 0 : *past_gcode = *gain_code;
180 0 : *gain_code *= *gain_inov;
181 :
182 0 : return;
183 : }
184 :
185 :
186 : /*---------------------------------------------------------------------*
187 : * gain_dec_gacelp_uv
188 : *
189 : * Decoding of pitch and codebook gains for Unvoiced mode
190 : *---------------------------------------------------------------------*/
191 :
192 24000 : void gain_dec_gacelp_uv(
193 : int16_t index, /* i/o: Quantization index vector */
194 : const float *code, /* i : algebraic code excitation */
195 : const float *code2, /* i : algebraic code excitation */
196 : const float mean_ener, /* i : mean energy */
197 : const int16_t lcode, /* i : Subframe size */
198 : float *gain_pit, /* o : Quantized pitch gain */
199 : float *gain_code, /* o : Quantized codebook gain */
200 : float *gain_code2, /* o : Quantized codebook gain */
201 : float *past_gpit, /* i/o: past gain of pitch */
202 : float *past_gcode, /* i/o: past energy of code */
203 : float *gain_inov /* o : unscaled innovation gain */
204 : )
205 : {
206 : float pred_nrg_frame, norm_code2;
207 : float gcode, gcode2;
208 : int16_t index2;
209 :
210 24000 : pred_nrg_frame = (float) pow( 10.0, mean_ener / 20.0 );
211 :
212 : /*-----------------------------------------------------------------*
213 : * Prediction gains
214 : *-----------------------------------------------------------------*/
215 :
216 24000 : *gain_inov = 1.0f / (float) sqrt( ( dotp( code, code, lcode ) + 0.01f ) / lcode );
217 24000 : gcode = pred_nrg_frame * ( *gain_inov );
218 :
219 24000 : norm_code2 = 1.0f / (float) sqrt( ( dotp( code2, code2, lcode ) + 0.01f ) / lcode );
220 24000 : gcode2 = pred_nrg_frame * ( norm_code2 );
221 :
222 : /*-----------------------------------------------------------------*
223 : * Decode pitch gain
224 : *-----------------------------------------------------------------*/
225 :
226 24000 : *gain_pit = 0.0f;
227 24000 : *past_gpit = *gain_pit;
228 :
229 : /*-----------------------------------------------------------------*
230 : * past gains for error concealment
231 : *-----------------------------------------------------------------*/
232 :
233 24000 : index2 = index >> 5;
234 24000 : index = index & 0x1F;
235 :
236 24000 : *gain_code = (float) pow( 10.f, ( ( ( index * 1.25f ) - 20.f ) / 20.f ) ) * gcode;
237 24000 : *gain_code2 = (float) ( index2 * 0.25f + 0.25f ) * ( *gain_code * ( gcode2 / gcode ) );
238 :
239 24000 : *past_gcode = *gain_code / *gain_inov; /*unscaled gain*/
240 :
241 24000 : return;
242 : }
243 :
244 :
245 : /*---------------------------------------------------------------------*
246 : * decode_acelp_gains
247 : *
248 : *
249 : *---------------------------------------------------------------------*/
250 :
251 9060 : void decode_acelp_gains(
252 : const float *code,
253 : const int16_t gains_mode,
254 : const float mean_ener_code,
255 : float *gain_pit,
256 : float *gain_code,
257 : int16_t **pt_indice,
258 : float *past_gpit,
259 : float *past_gcode,
260 : float *gain_inov,
261 : const int16_t L_subfr,
262 : float *code2,
263 : float *gain_code2 )
264 : {
265 9060 : int16_t index = 0;
266 :
267 9060 : index = **pt_indice;
268 9060 : ( *pt_indice )++;
269 :
270 9060 : if ( ( ( gains_mode > 0 ) && ( gains_mode < 4 ) ) )
271 : {
272 : /* EVS gains quantizer (5bits/subfr) */
273 9060 : Mode2_gain_dec_mless( index, code, L_subfr, gain_pit, gain_code, mean_ener_code, past_gpit, past_gcode, gain_inov, gains_mode - 1 );
274 : }
275 0 : else if ( gains_mode == 6 )
276 : {
277 : /* UV gains quantizer (6bits/subfr) */
278 0 : gain_dec_uv( index, code, L_subfr, gain_pit, gain_code, past_gpit, past_gcode, gain_inov );
279 : }
280 0 : else if ( gains_mode == 7 )
281 : {
282 : /* GACELP_UV gains quantizer (7=5-2bits/subfr) */
283 0 : gain_dec_gacelp_uv( index, code, code2, mean_ener_code, L_subfr, gain_pit, gain_code, gain_code2, past_gpit, past_gcode, gain_inov );
284 : }
285 : else
286 : {
287 0 : IVAS_ERROR( IVAS_ERR_INTERNAL, "invalid gains coding for acelp!" );
288 : }
289 :
290 9060 : return;
291 : }
|