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 : #include <math.h>
40 : #include "cnst.h"
41 : #include "prot.h"
42 : #include "wmc_auto.h"
43 :
44 : /*-------------------------------------------------------------------*
45 : * TCX_MDCT()
46 : *
47 : *
48 : *-------------------------------------------------------------------*/
49 :
50 4949569 : void TCX_MDCT(
51 : const float *x,
52 : float *y,
53 : const int16_t l,
54 : const int16_t m,
55 : const int16_t r,
56 : const int16_t element_mode )
57 : {
58 : int16_t i;
59 : float dctInBuffer[N_MAX];
60 :
61 : /* Init */
62 480367410 : for ( i = 0; i < m / 2; i++ )
63 : {
64 475417841 : dctInBuffer[m / 2 + r / 2 + i] = -1.0f * x[l + m / 2 - 1 - i];
65 : }
66 :
67 284406583 : for ( i = 0; i < l / 2; i++ )
68 : {
69 279457014 : dctInBuffer[m / 2 + r / 2 + m / 2 + i] = x[i] - x[l - 1 - i];
70 : }
71 :
72 480367410 : for ( i = 0; i < m / 2; i++ )
73 : {
74 475417841 : dctInBuffer[m / 2 + r / 2 - 1 - i] = -1.0f * x[l + m / 2 + i];
75 : }
76 :
77 313749713 : for ( i = 0; i < r / 2; i++ )
78 : {
79 308800144 : dctInBuffer[m / 2 + r / 2 - 1 - m / 2 - i] = -1.0f * x[l + m + i] - x[l + m + r - 1 - i];
80 : }
81 :
82 4949569 : edct( dctInBuffer, y, l / 2 + m + r / 2, element_mode );
83 :
84 4949569 : v_multc( y, (float) sqrt( (float) NORM_MDCT_FACTOR / ( l / 2 + m + r / 2 ) ), y, l / 2 + m + r / 2 );
85 :
86 4949569 : return;
87 : }
88 :
89 :
90 : /*-------------------------------------------------------------------*
91 : * TCX_MDST()
92 : *
93 : *
94 : *-------------------------------------------------------------------*/
95 :
96 3575400 : void TCX_MDST(
97 : const float *x,
98 : float *y,
99 : const int16_t l,
100 : const int16_t m,
101 : const int16_t r,
102 : const int16_t element_mode )
103 : {
104 : int16_t i;
105 : float dctInBuffer[N_MAX];
106 :
107 : /* Init */
108 782797975 : for ( i = 0; i < m / 2; i++ )
109 : {
110 779222575 : dctInBuffer[m / 2 + r / 2 + i] = -1.0f * x[l + m / 2 - 1 - i];
111 : }
112 548301180 : for ( i = 0; i < l / 2; i++ )
113 : {
114 544725780 : dctInBuffer[m / 2 + r / 2 + m / 2 + i] = -1.0f * x[i] - x[l - 1 - i];
115 : }
116 782797975 : for ( i = 0; i < m / 2; i++ )
117 : {
118 779222575 : dctInBuffer[m / 2 + r / 2 - 1 - i] = -1.0f * x[l + m / 2 + i];
119 : }
120 576716910 : for ( i = 0; i < r / 2; i++ )
121 : {
122 573141510 : dctInBuffer[m / 2 + r / 2 - 1 - m / 2 - i] = -1.0f * x[l + m + i] + x[l + m + r - 1 - i];
123 : }
124 :
125 3575400 : edst( dctInBuffer, y, l / 2 + m + r / 2, element_mode );
126 :
127 3575400 : v_multc( y, (float) sqrt( (float) NORM_MDCT_FACTOR / ( l / 2 + m + r / 2 ) ), y, l / 2 + m + r / 2 );
128 :
129 3575400 : return;
130 : }
131 :
132 :
133 : /*-------------------------------------------------------------------*
134 : * TCX_MDCT_Inverse()
135 : *
136 : *
137 : *-------------------------------------------------------------------*/
138 :
139 4742728 : void TCX_MDCT_Inverse(
140 : const float *x,
141 : float *y,
142 : const int16_t l,
143 : const int16_t m,
144 : const int16_t r,
145 : const int16_t element_mode )
146 : {
147 : int16_t i;
148 4742728 : const int16_t L2 = l >> 1, R2 = r >> 1;
149 : float f;
150 :
151 4742728 : edct( x, y + L2, L2 + m + R2, element_mode );
152 :
153 324715329 : for ( i = 0; i < R2; i++ )
154 : {
155 319972601 : y[l + m + R2 + i] = -1.0f * y[L2 + i]; /* fold out right end of DCT */
156 : }
157 :
158 4742728 : mvr2r( y + L2 + m + R2, y, L2 ); /* negate, fold out left end of DCT */
159 :
160 598596740 : for ( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ )
161 : {
162 593854012 : f = y[L2 + i];
163 593854012 : y[L2 + i] = -1.0f * y[l + m + R2 - 1 - i]; /* time-reverse mid of DCT */
164 593854012 : y[l + m + R2 - 1 - i] = -1.0f * f;
165 : }
166 :
167 4742728 : v_multc( y, (float) sqrt( (float) ( l / 2 + m + r / 2 ) / NORM_MDCT_FACTOR ), y, l + m + r );
168 :
169 4742728 : return;
170 : }
171 :
172 :
173 : /*-------------------------------------------------------------------*
174 : * TCX_MDST_Inverse()
175 : *
176 : *
177 : *-------------------------------------------------------------------*/
178 :
179 252 : void TCX_MDST_Inverse(
180 : const float *x,
181 : float *y,
182 : const int16_t l,
183 : const int16_t m,
184 : const int16_t r,
185 : const int16_t element_mode )
186 : {
187 : int16_t i;
188 252 : const int16_t L2 = l >> 1, R2 = r >> 1;
189 : float f;
190 :
191 252 : edst( x, y + L2, L2 + m + R2, element_mode );
192 :
193 252 : mvr2r( y + L2, y + l + m + R2, R2 ); /* negate, fold out right end of DST */
194 :
195 11172 : for ( i = 0; i < L2; i++ )
196 : {
197 10920 : y[i] = -1.0f * y[L2 + m + R2 + i]; /* fold out left end of DST */
198 : }
199 :
200 18180 : for ( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ )
201 : {
202 17928 : f = y[L2 + i];
203 17928 : y[L2 + i] = -1.0f * y[l + m + R2 - 1 - i]; /* time-reverse mid of DST */
204 17928 : y[l + m + R2 - 1 - i] = -1.0f * f;
205 : }
206 :
207 252 : v_multc( y, (float) sqrt( (float) ( l / 2 + m + r / 2 ) / NORM_MDCT_FACTOR ), y, l + m + r );
208 :
209 252 : return;
210 : }
211 :
212 :
213 : /*-------------------------------------------------------------------*
214 : * TCX_MDXT_Inverse()
215 : *
216 : *
217 : *-------------------------------------------------------------------*/
218 :
219 900 : void TCX_MDXT_Inverse(
220 : const float *x,
221 : float *y,
222 : const int16_t l,
223 : const int16_t m,
224 : const int16_t r,
225 : const uint16_t kernel_type )
226 : {
227 900 : const float signLeft = ( kernel_type >= MDCT_II ? -1.f : 1.f );
228 900 : const float signRight = ( kernel_type & 1 ? 1.f : -1.f );
229 : int16_t i;
230 900 : const int16_t L2 = l >> 1, R2 = r >> 1;
231 : float f;
232 :
233 900 : edxt( x, y + L2, L2 + m + R2, kernel_type, TRUE );
234 :
235 90106 : for ( i = 0; i < L2; i++ )
236 : {
237 89206 : y[i] = signLeft * y[L2 + m + R2 + i]; /* fold out the left end */
238 : }
239 :
240 90848 : for ( i = 0; i < R2; i++ )
241 : {
242 89948 : y[l + m + R2 + i] = signRight * y[L2 + i]; /* ...and right end */
243 : }
244 :
245 110844 : for ( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ )
246 : {
247 109944 : f = y[L2 + i];
248 109944 : y[L2 + i] = -1.0f * y[l + m + R2 - 1 - i]; /* time-reverse mid */
249 109944 : y[l + m + R2 - 1 - i] = -1.0f * f;
250 : }
251 :
252 900 : v_multc( y, (float) sqrt( (float) ( l / 2 + m + r / 2 ) / NORM_MDCT_FACTOR ), y, l + m + r );
253 :
254 900 : return;
255 : }
|