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 "prot.h"
41 : #include "rom_enc.h"
42 : #include "wmc_auto.h"
43 :
44 :
45 : /*-------------------------------------------------------------------*
46 : * fft16()
47 : *
48 : *
49 : *-------------------------------------------------------------------*/
50 :
51 969180 : static void fft16( float *r_samp, float *i_samp )
52 : {
53 : int16_t i, j, N, Nv2, nm1, k;
54 : float tmpr[16], tmpi[16];
55 : float r1, s1, r2, s2;
56 :
57 16476060 : for ( i = 0; i < 16; i++ )
58 : {
59 15506880 : tmpr[i] = r_samp[i] * M_inr[i] - i_samp[i] * M_ini[i];
60 15506880 : tmpi[i] = r_samp[i] * M_ini[i] + i_samp[i] * M_inr[i];
61 : }
62 :
63 8722620 : for ( i = 0; i < 8; i++ )
64 : {
65 7753440 : s1 = tmpr[i] - tmpr[8 + i];
66 7753440 : r1 = tmpi[i] - tmpi[8 + i];
67 :
68 7753440 : tmpr[i] = tmpr[i] + tmpr[8 + i];
69 7753440 : tmpi[i] = tmpi[i] + tmpi[8 + i];
70 :
71 7753440 : tmpr[i + 8] = s1 * M_r[i] - r1 * M_i[i];
72 7753440 : tmpi[i + 8] = s1 * M_i[i] + r1 * M_r[i];
73 : }
74 :
75 4845900 : for ( i = 0; i < 4; i++ )
76 : {
77 3876720 : s1 = tmpr[i] - tmpr[4 + i];
78 3876720 : r1 = tmpi[i] - tmpi[4 + i];
79 :
80 3876720 : tmpr[i] = tmpr[i] + tmpr[4 + i];
81 3876720 : tmpi[i] = tmpi[i] + tmpi[4 + i];
82 :
83 3876720 : tmpr[i + 4] = s1 * M_r[2 * i] - r1 * M_i[2 * i];
84 3876720 : tmpi[i + 4] = s1 * M_i[2 * i] + r1 * M_r[2 * i];
85 : }
86 4845900 : for ( i = 0; i < 4; i++ )
87 : {
88 3876720 : s1 = tmpr[i + 8] - tmpr[12 + i];
89 3876720 : r1 = tmpi[i + 8] - tmpi[12 + i];
90 :
91 3876720 : tmpr[i + 8] = tmpr[i + 8] + tmpr[12 + i];
92 3876720 : tmpi[i + 8] = tmpi[i + 8] + tmpi[12 + i];
93 :
94 3876720 : tmpr[i + 12] = s1 * M_r[2 * i] - r1 * M_i[2 * i];
95 3876720 : tmpi[i + 12] = s1 * M_i[2 * i] + r1 * M_r[2 * i];
96 : }
97 :
98 :
99 4845900 : for ( i = 0; i < 16; i = i + 4 )
100 : {
101 3876720 : s1 = tmpr[i] - tmpr[2 + i];
102 3876720 : r1 = tmpi[i] - tmpi[2 + i];
103 3876720 : s2 = tmpr[i + 1] - tmpr[3 + i];
104 3876720 : r2 = tmpi[i + 1] - tmpi[3 + i];
105 :
106 3876720 : tmpr[i] = tmpr[i] + tmpr[2 + i];
107 3876720 : tmpi[i] = tmpi[i] + tmpi[2 + i];
108 3876720 : tmpr[i + 1] = tmpr[i + 1] + tmpr[3 + i];
109 3876720 : tmpi[i + 1] = tmpi[i + 1] + tmpi[3 + i];
110 :
111 3876720 : tmpr[i + 2] = s1 * M_r[0] - r1 * M_i[0];
112 3876720 : tmpi[i + 2] = s1 * M_i[0] + r1 * M_r[0];
113 3876720 : tmpr[i + 3] = s2 * M_r[4] - r2 * M_i[4];
114 3876720 : tmpi[i + 3] = s2 * M_i[4] + r2 * M_r[4];
115 : }
116 :
117 8722620 : for ( i = 0; i < 16; i = i + 2 )
118 : {
119 7753440 : s1 = tmpr[i] - tmpr[1 + i];
120 7753440 : r1 = tmpi[i] - tmpi[1 + i];
121 :
122 7753440 : tmpr[i] = tmpr[i] + tmpr[1 + i];
123 7753440 : tmpi[i] = tmpi[i] + tmpi[1 + i];
124 :
125 7753440 : tmpr[i + 1] = s1 * M_r[0] - r1 * M_i[0];
126 7753440 : tmpi[i + 1] = s1 * M_i[0] + r1 * M_r[0];
127 : }
128 :
129 969180 : N = 16;
130 969180 : Nv2 = N >> 1;
131 969180 : nm1 = N - 1;
132 969180 : j = 0;
133 15506880 : for ( i = 0; i < nm1; i++ )
134 : {
135 14537700 : if ( i < j )
136 : {
137 5815080 : r_samp[j] = tmpr[i] * M_Wr[j] - tmpi[i] * M_Wi[j];
138 5815080 : i_samp[j] = tmpr[i] * M_Wi[j] + tmpi[i] * M_Wr[j];
139 5815080 : r_samp[i] = tmpr[j] * M_Wr[i] - tmpi[j] * M_Wi[i];
140 5815080 : i_samp[i] = tmpr[j] * M_Wi[i] + tmpi[j] * M_Wr[i];
141 : }
142 8722620 : else if ( i == j )
143 : {
144 2907540 : r_samp[i] = tmpr[i] * M_Wr[i] - tmpi[i] * M_Wi[i];
145 2907540 : i_samp[i] = tmpr[i] * M_Wi[i] + tmpi[i] * M_Wr[i];
146 : }
147 :
148 14537700 : k = Nv2;
149 25198680 : while ( k <= j )
150 : {
151 10660980 : j -= k;
152 10660980 : k >>= 1;
153 : }
154 14537700 : j += k;
155 : }
156 :
157 969180 : r_samp[15] = tmpr[15] * M_Wr[15] - tmpi[15] * M_Wi[15];
158 969180 : i_samp[15] = tmpr[15] * M_Wi[15] + tmpi[15] * M_Wr[15];
159 :
160 969180 : return;
161 : }
162 :
163 :
164 : /*-------------------------------------------------------------------*
165 : * subband_FFT()
166 : *
167 : *
168 : *-------------------------------------------------------------------*/
169 :
170 96918 : void subband_FFT(
171 : float Sr[16][60], /* i : real part of the cldfb */
172 : float Si[16][60], /* i : imag part of the cldfb */
173 : float *spec_amp /* o : spectral amplitude */
174 : )
175 : {
176 : int16_t i, j;
177 : float tmpr[16], tmpi[16];
178 : float ptmp[16], tmp1;
179 :
180 1066098 : for ( i = 0; i < 10; i++ )
181 : {
182 16476060 : for ( j = 0; j < 16; j++ )
183 : {
184 15506880 : tmpr[j] = Sr[j][i];
185 15506880 : tmpi[j] = Si[j][i];
186 : }
187 :
188 969180 : fft16( tmpr, tmpi );
189 :
190 16476060 : for ( j = 0; j < 16; j++ )
191 : {
192 15506880 : ptmp[j] = tmpr[j] * tmpr[j] + tmpi[j] * tmpi[j];
193 : }
194 969180 : if ( i % 2 == 0 )
195 : {
196 4361310 : for ( j = 0; j < 8; j++ )
197 : {
198 3876720 : tmp1 = ptmp[j] + ptmp[15 - j];
199 3876720 : spec_amp[i * 8 + j] = (float) sqrt( tmp1 );
200 : }
201 : }
202 : else
203 : {
204 4361310 : for ( j = 0; j < 8; j++ )
205 : {
206 3876720 : tmp1 = ptmp[j] + ptmp[15 - j];
207 3876720 : spec_amp[i * 8 + 7 - j] = (float) sqrt( tmp1 );
208 : }
209 : }
210 : }
211 :
212 96918 : return;
213 : }
|