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 <assert.h>
38 : #include <stdint.h>
39 : #include "options.h"
40 : #include "prot_fx.h"
41 : #include "cnst.h"
42 : #include "rom_com.h"
43 : #include "wmc_auto.h"
44 :
45 : /*-------------------------------------------------------------------*
46 : * Local constants
47 : *-------------------------------------------------------------------*/
48 :
49 : #define kLagWinThGain1 19661 /* 0.6f in Q15 */
50 : #define kLagWinThGain2 9830 /* 0.3f in Q15 */
51 :
52 : /*-------------------------------------------------------------*
53 : * procedure lag_wind: *
54 : * ~~~~~~~~~ *
55 : * lag windowing of the autocorrelations *
56 : *-------------------------------------------------------------*/
57 :
58 2706472 : void lag_wind(
59 : Word16 r_h[], /* in/out: autocorrelations Q15(Q_r -16)*/
60 : Word16 r_l[], /* in/out: autocorrelations Q(r)-1*/
61 : Word16 m, /* input : order of LP filter Q0*/
62 : Word32 sr_core, /* input : sampling rate Q0*/
63 : Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG Q0*/
64 : )
65 : {
66 : Word16 i;
67 : Word32 tmp;
68 : const Word16 *wnd_h, *wnd_l;
69 :
70 :
71 2706472 : assert( 0 <= strength && strength <= NUM_LAGW_STRENGTHS );
72 2706472 : SWITCH( sr_core )
73 : {
74 0 : case 8000:
75 0 : assert( m <= 16 );
76 0 : assert( strength == LAGW_STRONG );
77 0 : wnd_h = lag_window_8k[0]; /*Q15(Q_r -16)*/
78 0 : wnd_l = lag_window_8k[1]; /*Q(r)-1*/
79 0 : BREAK;
80 2264200 : case 12800:
81 2264200 : assert( m <= 16 );
82 2264200 : wnd_h = lag_window_12k8[strength][0]; /*Q15(Q_r -16)*/
83 2264200 : wnd_l = lag_window_12k8[strength][1]; /*Q(r)-1*/
84 2264200 : BREAK;
85 332115 : case 16000:
86 332115 : assert( m <= 16 );
87 332115 : wnd_h = lag_window_16k[strength][0]; /*Q15(Q_r -16)*/
88 332115 : wnd_l = lag_window_16k[strength][1]; /*Q(r)-1*/
89 332115 : BREAK;
90 7269 : case 24000:
91 : case 25600:
92 7269 : assert( m <= 16 );
93 7269 : wnd_h = lag_window_25k6[strength][0]; /*Q15(Q_r -16)*/
94 7269 : wnd_l = lag_window_25k6[strength][1]; /*Q(r)-1*/
95 7269 : BREAK;
96 101762 : case 32000:
97 101762 : assert( m <= 16 );
98 101762 : wnd_h = lag_window_32k[strength][0]; /*Q15(Q_r -16)*/
99 101762 : wnd_l = lag_window_32k[strength][1]; /*Q(r)-1*/
100 101762 : BREAK;
101 1126 : case 48000:
102 1126 : assert( m <= 16 );
103 1126 : assert( strength == LAGW_STRONG );
104 1126 : wnd_h = lag_window_48k[0]; /*Q15(Q_r -16)*/
105 1126 : wnd_l = lag_window_48k[1]; /*Q(r)-1*/
106 1126 : BREAK;
107 0 : default:
108 0 : assert( !"Lag window not implemented for this sampling rate" );
109 : return;
110 : }
111 :
112 46010024 : FOR( i = 1; i <= m; i++ )
113 : {
114 43303552 : tmp = Mpy_32( r_h[i], r_l[i], wnd_h[( i - 1 )], wnd_l[( i - 1 )] ); /*Q31*/
115 43303552 : L_Extract( tmp, &r_h[i], &r_l[i] );
116 : }
117 2706472 : }
118 :
119 1263 : void lag_wind_32(
120 : Word32 r[], /* in/out: autocorrelations Qx*/
121 : Word16 m, /* input : order of LP filter Q0*/
122 : Word32 sr_core, /* input : sampling rate Q0*/
123 : Word16 strength /* input : LAGW_WEAK, LAGW_MEDIUM, or LAGW_STRONG Q0*/
124 : )
125 : {
126 : Word16 i;
127 : const Word32 *wnd; /*Q31*/
128 :
129 :
130 1263 : assert( 0 <= strength && strength <= NUM_LAGW_STRENGTHS );
131 1263 : SWITCH( sr_core )
132 : {
133 0 : case 8000:
134 0 : assert( m <= 16 );
135 0 : assert( strength == LAGW_STRONG );
136 0 : wnd = lag_window_8k_32; /*Q31*/
137 0 : BREAK;
138 0 : case 12800:
139 0 : assert( m <= 16 );
140 0 : wnd = lag_window_12k8_32[strength]; /*Q31*/
141 0 : BREAK;
142 54 : case 16000:
143 54 : assert( m <= 16 );
144 54 : wnd = lag_window_16k_32[strength]; /*Q31*/
145 54 : BREAK;
146 857 : case 24000:
147 : case 25600:
148 857 : assert( m <= 16 );
149 857 : wnd = lag_window_25k6_32[strength]; /*Q31*/
150 857 : BREAK;
151 352 : case 32000:
152 352 : assert( m <= 16 );
153 352 : wnd = lag_window_32k_32[strength]; /*Q31*/
154 352 : BREAK;
155 0 : case 48000:
156 0 : assert( m <= 16 );
157 0 : assert( strength == LAGW_STRONG );
158 0 : wnd = lag_window_48k_32; /*Q31*/
159 0 : BREAK;
160 0 : default:
161 0 : assert( !"Lag window not implemented for this sampling rate" );
162 : return;
163 : }
164 :
165 21471 : FOR( i = 1; i <= m; i++ )
166 : {
167 20208 : r[i] = Mpy_32_32( r[i], wnd[( i - 1 )] ); /*Qx*/
168 20208 : move32();
169 : }
170 1263 : }
171 :
172 :
173 2704225 : void adapt_lag_wind(
174 : Word16 r_h[], /* in/out: autocorrelations Q15*/
175 : Word16 r_l[], /* in/out: autocorrelations */
176 : Word16 m, /* input : order of LP filter Q0*/
177 : const Word16 Top, /* input : open loop pitch lag Q0*/
178 : const Word16 Tnc, /* input : open loop pitch gain Q15*/
179 : Word32 sr_core /* input : sampling rate Q0*/
180 : )
181 : {
182 : Word16 strength, pitch_lag;
183 : Word16 pitch_gain;
184 :
185 2704225 : pitch_lag = Top; /*Q0*/
186 2704225 : move16();
187 2704225 : pitch_gain = Tnc; /*Q15*/
188 2704225 : move16();
189 :
190 2704225 : IF( LT_16( pitch_lag, 80 ) )
191 : {
192 1648408 : strength = LAGW_STRONG;
193 1648408 : move16();
194 1648408 : if ( LE_16( pitch_gain, kLagWinThGain1 ) )
195 : {
196 624362 : strength = LAGW_MEDIUM;
197 624362 : move16();
198 : }
199 : }
200 1055817 : ELSE IF( LT_16( pitch_lag, 160 ) )
201 : {
202 824049 : strength = LAGW_MEDIUM;
203 824049 : move16();
204 824049 : if ( LE_16( pitch_gain, kLagWinThGain2 ) )
205 : {
206 15089 : strength = LAGW_WEAK;
207 15089 : move16();
208 : }
209 : }
210 : ELSE
211 : {
212 231768 : strength = LAGW_WEAK;
213 231768 : move16();
214 : }
215 :
216 2704225 : lag_wind( r_h, r_l, m, sr_core, strength );
217 2704225 : }
|