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 "cnst.h"
44 : #include "prot.h"
45 : #include "rom_com.h"
46 : #include "prot.h" /* Function prototypes */
47 : #include "wmc_auto.h"
48 :
49 : /*--------------------------------------------------------------------------
50 : * logqnorm()
51 : *
52 : * Log quantization for norms of sub-vectors
53 : *--------------------------------------------------------------------------*/
54 :
55 415190 : void logqnorm(
56 : const float *x, /* i : coefficient vector */
57 : int16_t *k, /* o : index */
58 : const int16_t L, /* i : codebook length */
59 : const int16_t N, /* i : sub-vector size */
60 : const float *thren /* i : quantization thresholds */
61 : )
62 : {
63 : int16_t i, j, j1, j2;
64 : float temp, power;
65 :
66 :
67 415190 : temp = 0.0;
68 7461624 : for ( i = 0; i < N; i++ )
69 : {
70 7046434 : temp += ( x[i] * x[i] );
71 : }
72 :
73 : /* sqrt will be done later */
74 415190 : temp *= inv_tbl[N];
75 :
76 415190 : if ( thren[0] * thren[0] - temp <= 0 )
77 : {
78 0 : *k = 0;
79 : }
80 415190 : else if ( thren[L - 2] * thren[L - 2] - temp > 0 )
81 : {
82 1712 : *k = L - 1;
83 : }
84 : else
85 : {
86 413478 : power = (float) sqrt( temp );
87 :
88 413478 : j1 = 0;
89 413478 : j2 = L - 1;
90 2639708 : while ( ( j2 - j1 ) > 1 )
91 : {
92 2226230 : j = ( j1 + j2 ) >> 1;
93 2226230 : if ( power >= thren[j] )
94 : {
95 953070 : j2 = j;
96 : }
97 : else
98 : {
99 1273160 : j1 = j;
100 : }
101 : }
102 :
103 413478 : *k = j2;
104 : }
105 :
106 415190 : return;
107 : }
108 :
109 :
110 : /*--------------------------------------------------------------------------
111 : * logqnorm_2()
112 : *
113 : *
114 : *--------------------------------------------------------------------------*/
115 :
116 12072 : void logqnorm_2(
117 : const float *env_fl, /* o : index */
118 : const int16_t L, /* i : codebook length */
119 : const int16_t n_env_band, /* i : sub-vector size */
120 : const int16_t nb_sfm, /* i : sub-vector size */
121 : int16_t *ynrm, /* o : norm indices */
122 : int16_t *normqlg2, /* o : quantized norm values */
123 : const float *thren /* i : quantization thresholds */
124 : )
125 : {
126 : int16_t i, j, j1, j2;
127 : float temp, power;
128 :
129 202306 : for ( i = n_env_band; i < nb_sfm; i++ )
130 : {
131 190234 : temp = env_fl[i - n_env_band];
132 190234 : if ( thren[0] - temp <= 0 )
133 : {
134 0 : *ynrm = 0;
135 : }
136 190234 : else if ( thren[L - 2] - temp > 0 )
137 : {
138 23510 : *ynrm = L - 1;
139 : }
140 : else
141 : {
142 166724 : power = temp;
143 166724 : j1 = 0;
144 166724 : j2 = L - 1;
145 1064283 : while ( ( j2 - j1 ) > 1 )
146 : {
147 897559 : j = ( j1 + j2 ) >> 1;
148 897559 : if ( power >= thren[j] )
149 : {
150 347512 : j2 = j;
151 : }
152 : else
153 : {
154 550047 : j1 = j;
155 : }
156 : }
157 166724 : *ynrm = j2;
158 : }
159 190234 : *normqlg2 = dicnlg2[*ynrm];
160 190234 : normqlg2++;
161 190234 : ynrm++;
162 : }
163 :
164 12072 : return;
165 : }
166 :
167 : /*--------------------------------------------------------------------------
168 : * calc_norm()
169 : *
170 : * Calculate the norms for the spectral envelope
171 : *--------------------------------------------------------------------------*/
172 :
173 11492 : void calc_norm(
174 : const float *x, /* i : Input vector. */
175 : int16_t *norm, /* o : Quantization indices for norms */
176 : int16_t *normlg, /* o : Quantized norms in log2 */
177 : const int16_t start_band, /* i : Indice of band to start coding */
178 : const int16_t num_bands, /* i : Number of bands */
179 : const int16_t *band_len, /* i : Length of bands */
180 : const int16_t *band_start /* i : Start of bands */
181 : )
182 : {
183 : int16_t nrm;
184 : int16_t band;
185 :
186 11492 : set_s( norm, 0, start_band );
187 :
188 11492 : logqnorm( &x[band_start[start_band]], &nrm, 32, band_len[start_band], thren_HQ );
189 11492 : norm[start_band] = nrm;
190 11492 : normlg[start_band] = dicnlg2[nrm];
191 :
192 380769 : for ( band = start_band + 1; band < start_band + num_bands; band++ )
193 : {
194 369277 : logqnorm( &x[band_start[band]], &nrm, 40, band_len[band], thren_HQ );
195 369277 : norm[band] = nrm;
196 369277 : normlg[band] = dicnlg2[nrm];
197 : }
198 :
199 11492 : return;
200 : }
|