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 : #include <assert.h>
34 : #include <stdint.h>
35 : #include "options.h"
36 : #include "cnst.h"
37 : #include "ivas_cnst.h"
38 : #include "prot.h"
39 : #include "ivas_prot.h"
40 : #ifdef DEBUGGING
41 : #include "debug.h"
42 : #endif
43 : #include "wmc_auto.h"
44 : #include "rom_com.h"
45 : #include "ivas_rom_com.h"
46 :
47 : /*---------------------------------------------------------------
48 : * interpTargetChannel()
49 : *
50 : * Target signal correction for shift variations.
51 : * The pointer passsed into this function is assumed to be chanR/chanL + currNCShift.
52 : * ---------------------------------------------------------------*/
53 :
54 : #define SPREAD_FACTOR1 ( 1.0f / INTERP_FACTOR1 )
55 :
56 42923 : static void interpTargetChannel(
57 : float *target,
58 : const int16_t prevShift,
59 : const int16_t currShift,
60 : const int16_t L_shift_adapt )
61 : {
62 : int16_t i, j, k, /*m,*/ d, N, signShift, lim1, lim2;
63 : const float *win;
64 : float *ptr1, *ptr2;
65 : float tempBuff1[INTERP_FACTOR1 * ( L_SHIFT_ADAPT_MAX + 2 * N_MAX_SHIFT_CHANGE + 2 )], tempBuff2[L_SHIFT_ADAPT_MAX - 1];
66 : float x[4], y[4], tempF, tempF1;
67 : float interp_factor2, factor;
68 : float spread_factor2;
69 : double tempD1, tempD2;
70 :
71 42923 : d = -( currShift - prevShift );
72 42923 : signShift = ( d >= 0 ) ? ( 1 ) : ( -1 );
73 :
74 42923 : if ( d == 0 )
75 : {
76 : /* this can happen in DFT->TD switching */
77 15336 : return;
78 : }
79 :
80 27587 : N = L_shift_adapt;
81 27587 : factor = ( (float) N ) / abs( d );
82 27587 : interp_factor2 = factor / INTERP_FACTOR1;
83 27587 : spread_factor2 = 1.0f / interp_factor2;
84 :
85 : /* start from (target - N - d + 1) : (extra lag = step1) :to: (target - 1 - d) : (extra lag = d) */
86 : /* sinc interp by a factor of 2 */
87 27587 : win = ica_sincInterp2 + SINC_ORDER1;
88 27587 : ptr1 = target;
89 27587 : ptr2 = tempBuff1 + ( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1;
90 :
91 31573103 : for ( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < ( N + N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i++ )
92 : {
93 31545516 : if ( i & 0x1 )
94 : {
95 15772758 : ptr2[i] = 0.0f;
96 : /* lim1 = ceil((i - SINC_ORDER1)*SPREAD_FACTOR1); */
97 : /* lim2 = floor((i + SINC_ORDER1)*SPREAD_FACTOR1); */
98 15772758 : tempF = ( i - SINC_ORDER1 ) * SPREAD_FACTOR1;
99 15772758 : lim1 = (int16_t) ( tempF );
100 15772758 : if ( lim1 < tempF )
101 : {
102 14862387 : lim1++;
103 : }
104 :
105 15772758 : tempF = ( i + SINC_ORDER1 ) * SPREAD_FACTOR1;
106 15772758 : lim2 = (int16_t) ( tempF );
107 15772758 : if ( lim2 > tempF )
108 : {
109 248283 : lim2--;
110 : }
111 :
112 394318950 : for ( j = lim1; j <= lim2; j++ )
113 : {
114 378546192 : ptr2[i] += win[j * INTERP_FACTOR1 - i] * ptr1[j];
115 : }
116 : }
117 : else
118 : {
119 15772758 : ptr2[i] = ptr1[(int16_t) ( i * SPREAD_FACTOR1 )];
120 : }
121 : }
122 :
123 : /* cubic spline interp */
124 27587 : ptr1 = ptr2;
125 27587 : ptr2 = tempBuff2;
126 :
127 27587 : tempD1 = ( 1.0f / ( 6 * interp_factor2 * interp_factor2 * interp_factor2 ) );
128 27587 : tempD2 = 3.0f * tempD1;
129 14614104 : for ( tempF1 = d * factor - signShift, k = 0; k < N - 1; k++, tempF1 += ( factor - signShift ) )
130 : {
131 14586517 : tempF = tempF1 * spread_factor2 - 1;
132 14586517 : lim1 = (int16_t) ( tempF );
133 14586517 : if ( lim1 > tempF )
134 : {
135 51819 : lim1--;
136 : }
137 :
138 14586517 : y[0] = ptr1[lim1];
139 14586517 : y[1] = ptr1[lim1 + 1];
140 14586517 : y[2] = ptr1[lim1 + 2];
141 14586517 : y[3] = ptr1[lim1 + 3];
142 :
143 14586517 : x[0] = lim1 * interp_factor2;
144 14586517 : x[1] = x[0] + interp_factor2;
145 14586517 : x[2] = x[1] + interp_factor2;
146 14586517 : x[3] = x[2] + interp_factor2;
147 :
148 14586517 : ptr2[k] = (float) ( ( y[3] * ( ( tempF1 - x[0] ) * ( tempF1 - x[1] ) * ( tempF1 - x[2] ) ) - y[0] * ( ( tempF1 - x[1] ) * ( tempF1 - x[2] ) * ( tempF1 - x[3] ) ) ) * tempD1 + ( y[1] * ( ( tempF1 - x[0] ) * ( tempF1 - x[2] ) * ( tempF1 - x[3] ) ) - y[2] * ( ( tempF1 - x[0] ) * ( tempF1 - x[1] ) * ( tempF1 - x[3] ) ) ) * tempD2 );
149 : }
150 :
151 27587 : ptr1 = target;
152 27587 : mvr2r( ptr2, ptr1, N - 1 );
153 :
154 27587 : return;
155 : }
156 :
157 :
158 : /*---------------------------------------------------------------
159 : * Function targetCh_AlignStereoDFT()
160 : *
161 : * Align target channel in DFT stereo to correct for shift variations
162 : * ---------------------------------------------------------------*/
163 :
164 13991 : static void targetCh_AlignStereoDFT(
165 : float *target,
166 : const int16_t prevShift,
167 : const int16_t currShift,
168 : const int16_t L_shift_adapt )
169 : {
170 : int16_t i;
171 : float winSlope, alpha;
172 : int16_t d;
173 :
174 : float fadeOutBuff[L_SHIFT_ADAPT_MAX];
175 : float fadeInBuff[L_SHIFT_ADAPT_MAX];
176 :
177 13991 : d = -( currShift - prevShift );
178 :
179 13991 : mvr2r( target + d, fadeOutBuff, L_shift_adapt );
180 13991 : mvr2r( target, fadeInBuff, L_shift_adapt );
181 :
182 13991 : if ( L_shift_adapt > 0 )
183 : {
184 13991 : alpha = 0;
185 13991 : winSlope = 1.0f / L_shift_adapt;
186 7249090 : for ( i = 0; i < L_shift_adapt; i++ )
187 : {
188 7235099 : target[i] = alpha * fadeInBuff[i] + ( 1 - alpha ) * fadeOutBuff[i];
189 7235099 : alpha += winSlope;
190 : }
191 : }
192 : else
193 : {
194 0 : mvr2r( fadeInBuff, target, L_shift_adapt );
195 : }
196 :
197 13991 : return;
198 : }
199 :
200 :
201 : /*---------------------------------------------------------------
202 : * adjustTargetSignal()
203 : *
204 : * Target signal correction for shift variations.
205 : * ---------------------------------------------------------------*/
206 :
207 56914 : void adjustTargetSignal(
208 : float *target,
209 : const int16_t prevShift,
210 : const int16_t currShift,
211 : const int16_t L_shift_adapt,
212 : const int16_t method )
213 : {
214 : /* inter-frame shift variation and target shifting */
215 :
216 56914 : if ( method == 0 )
217 : {
218 42923 : interpTargetChannel( target, prevShift, currShift, L_shift_adapt );
219 : }
220 : else
221 : {
222 13991 : targetCh_AlignStereoDFT( target, prevShift, currShift, L_shift_adapt );
223 : }
224 :
225 56914 : return;
226 : }
|