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 "rom_com.h"
43 : #include "prot.h"
44 : #include "wmc_auto.h"
45 :
46 : /*-------------------------------------------------------------------*
47 : * Local function prototypes
48 : *-------------------------------------------------------------------*/
49 :
50 : static int16_t fcb_encode_pos( const int16_t pos_vector[], const int16_t pulse_num, const int16_t pos_num );
51 :
52 :
53 : /*-------------------------------------------------------------------*
54 : * re8_compute_base_index:
55 : *
56 : * Compute base index for RE8
57 : *-------------------------------------------------------------------*/
58 :
59 1748010 : void re8_compute_base_index(
60 : const int16_t *x, /* i : Elemen of Q2, Q3 or Q4 */
61 : const int16_t ka, /* i : Identifier of the absolute leader related to x */
62 : uint16_t *I /* o : index */
63 : )
64 : {
65 : int16_t i, j, k1, m;
66 : int16_t setor_8p[8], setor_8p_temp[8];
67 : int16_t sign_8p;
68 : int16_t code_index, code_level, code_area;
69 : uint16_t offset;
70 : const int16_t *a1, *a2;
71 :
72 1748010 : a1 = vals_a[ka];
73 1748010 : a2 = vals_q[ka];
74 :
75 : /* the sign process */
76 :
77 1748010 : sign_8p = 0;
78 1748010 : m = 0;
79 1748010 : code_index = 0;
80 1748010 : k1 = a2[0];
81 :
82 1748010 : if ( ( a2[1] == 2 ) && ( a1[0] ^ 1 ) && ( ka != 5 ) )
83 : {
84 5645772 : for ( i = 0; i < 8; i++ )
85 : {
86 5018464 : if ( x[i] != 0 )
87 : {
88 1726255 : sign_8p = sign_8p * 2;
89 1726255 : setor_8p_temp[m] = i;
90 1726255 : m++;
91 : }
92 5018464 : if ( x[i] < 0 )
93 : {
94 880822 : sign_8p += 1;
95 : }
96 : }
97 :
98 627308 : code_index = fcb_encode_pos( setor_8p_temp, 8, m );
99 627308 : code_index = ( code_index << k1 ) + sign_8p;
100 :
101 627308 : offset = Is[ka];
102 :
103 :
104 627308 : *I = offset + code_index;
105 : }
106 : else
107 : {
108 10086318 : for ( i = 0; i < 8; i++ )
109 : {
110 8965616 : setor_8p[i] = (int16_t) abs( x[i] );
111 :
112 8965616 : if ( x[i] < 0 )
113 : {
114 4244710 : sign_8p = sign_8p * 2 + 1;
115 4244710 : m++;
116 : }
117 8965616 : if ( x[i] > 0 )
118 : {
119 4074754 : sign_8p = sign_8p * 2;
120 4074754 : m++;
121 : }
122 : }
123 :
124 1120702 : if ( k1 != m )
125 : {
126 908528 : sign_8p = sign_8p >> 1;
127 : }
128 :
129 : /* code level by level */
130 :
131 1120702 : code_level = a2[1];
132 1120702 : code_area = 8;
133 :
134 1120702 : if ( a2[2] != 1 )
135 : {
136 1445915 : for ( j = 0; j < code_level - 1; j++ )
137 : {
138 560604 : m = 0;
139 :
140 4314270 : for ( i = 0; i < code_area; i++ )
141 : {
142 3753666 : if ( setor_8p[i] != a1[j] )
143 : {
144 1268263 : setor_8p_temp[m] = i;
145 1268263 : setor_8p[m] = setor_8p[i];
146 1268263 : m++;
147 : }
148 : }
149 560604 : code_index *= select_table22[m][code_area];
150 :
151 560604 : code_index += fcb_encode_pos( setor_8p_temp, code_area, m );
152 :
153 560604 : code_area = m;
154 : }
155 : }
156 : else
157 : {
158 2118519 : for ( i = 0; i < code_area; i++ )
159 : {
160 1883128 : if ( setor_8p[i] == a1[1] )
161 : {
162 235391 : code_index += i;
163 : }
164 : }
165 : }
166 :
167 1120702 : code_index = ( code_index << k1 ) + sign_8p;
168 :
169 1120702 : offset = Is[ka];
170 :
171 1120702 : *I = offset + code_index;
172 : }
173 :
174 1748010 : return;
175 : }
176 :
177 : /*-------------------------------------------------------------------*
178 : * fcb_encode_pos:
179 : *
180 : * Base function to compute base index for RE8
181 : *-------------------------------------------------------------------*/
182 :
183 : /*! r: Code index */
184 1187912 : static int16_t fcb_encode_pos(
185 : const int16_t pos_vector[], /* i : Position vectort */
186 : const int16_t pulse_num, /* i : Pulse number */
187 : const int16_t pos_num /* i : Position number */
188 : )
189 : {
190 : int16_t i, j;
191 : int16_t code_index;
192 : int16_t temp, temp1;
193 : const int16_t *select_table23;
194 :
195 1187912 : temp = pulse_num - 1;
196 :
197 1187912 : select_table23 = select_table22[pos_num];
198 :
199 1187912 : code_index = select_table23[pulse_num] - select_table23[pulse_num - pos_vector[0]];
200 :
201 2994518 : for ( i = 0, j = 1; i < pos_num - 1; i++, j++ )
202 : {
203 1806606 : temp1 = pos_num - j;
204 :
205 1806606 : select_table23 = select_table22[temp1];
206 :
207 1806606 : code_index += select_table23[temp - pos_vector[i]] - select_table23[pulse_num - pos_vector[j]];
208 : }
209 :
210 1187912 : return code_index;
211 : }
|