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 <stdint.h>
34 : #include "options.h"
35 : #include <math.h>
36 : #include "prot_fx.h"
37 : #include "ivas_prot_rend_fx.h"
38 : #include "cnst.h"
39 : #include "ivas_cnst.h"
40 : #include "ivas_rom_rend.h"
41 : #include "ivas_rom_dec.h"
42 : #include "ivas_rom_com.h"
43 : #include "ivas_rom_binauralRenderer.h"
44 : #include "wmc_auto.h"
45 : #include "ivas_prot_fx.h"
46 : #include "ivas_rom_com_fx.h"
47 : #include "debug.h"
48 : #define NUM_TAPS_F0_6 ( Word16 )( 58 ) // (Word16) ceil( 0.6f * hBinRenConvModule->numTaps )
49 : #define NUM_TAPS_F0_5 ( Word16 )( 48 ) // (Word16) ceil( 0.5f * hBinRenConvModule->numTaps )
50 : #define NUM_TAPS_F0_4 ( Word16 )( 39 ) // (Word16) ceil( 0.4f * hBinRenConvModule->numTaps )
51 : #define NUM_TAPS_F0_3 ( Word16 )( 29 ) // (Word16) ceil( 0.3f * hBinRenConvModule->numTaps )
52 : /*-------------------------------------------------------------------------
53 : * ivas_binRenderer_filterModule_fx()
54 : *
55 : *
56 : *-------------------------------------------------------------------------*/
57 :
58 136305 : static void ivas_binRenderer_filterModule_fx(
59 : Word64 out_Conv_CLDFB_real[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : real part of Binaural signals Q29 */
60 : Word64 out_Conv_CLDFB_imag[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : imag part of Binaural signals Q29 */
61 : Word32 CLDFB_real[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : real part of LS signals Q_curr*/
62 : Word32 CLDFB_imag[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : imag part of LS signals Q_curr*/
63 : const Word16 numTimeSlots, /* i : number of time slots to process */
64 : BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: fastconv binaural renderer handle */
65 : Word16 Q_curr )
66 : {
67 : Word16 bandIdx, k, chIdx, tapIdx;
68 : Word32 *filterStatesLeftRealPtr_fx, *filterStatesLeftImagPtr_fx;
69 : Word16 Q_filterStates;
70 : const Word32 *filterTapsLeftRealPtr_fx, *filterTapsLeftImagPtr_fx, *filterTapsRightRealPtr_fx, *filterTapsRightImagPtr_fx;
71 : Word16 shift_q;
72 136305 : Q_filterStates = hBinRenderer->hBinRenConvModule->Q_filterStatesLeft;
73 136305 : move16();
74 :
75 6310355 : FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
76 : {
77 88510050 : FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ )
78 : {
79 82336000 : filterStatesLeftRealPtr_fx = (Word32 *) &( hBinRenderer->hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx][0] );
80 82336000 : filterStatesLeftImagPtr_fx = (Word32 *) &( hBinRenderer->hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx][0] );
81 :
82 82336000 : filterTapsLeftRealPtr_fx = hBinRenderer->hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx]; // Q29
83 82336000 : filterTapsLeftImagPtr_fx = hBinRenderer->hBinRenConvModule->filterTapsLeftImag_fx[bandIdx][chIdx]; // Q29
84 82336000 : filterTapsRightRealPtr_fx = hBinRenderer->hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx]; // Q29
85 82336000 : filterTapsRightImagPtr_fx = hBinRenderer->hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx]; // Q29
86 :
87 410464000 : FOR( k = 0; k < numTimeSlots; k++ )
88 : {
89 328128000 : Word64 outRealLeft_fx = 0, outRealRight_fx = 0, outImagLeft_fx = 0, outImagRight_fx = 0;
90 328128000 : move64();
91 328128000 : move64();
92 328128000 : move64();
93 328128000 : move64();
94 :
95 4698766400 : FOR( tapIdx = hBinRenderer->hBinRenConvModule->numTapsArray[bandIdx] - 1; tapIdx > 0; tapIdx-- )
96 : {
97 4370638400 : filterStatesLeftRealPtr_fx[tapIdx] = filterStatesLeftRealPtr_fx[tapIdx - 1];
98 4370638400 : move32();
99 4370638400 : filterStatesLeftImagPtr_fx[tapIdx] = filterStatesLeftImagPtr_fx[tapIdx - 1];
100 4370638400 : move32();
101 :
102 :
103 4370638400 : outRealLeft_fx = W_mac_32_32( outRealLeft_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsLeftRealPtr_fx[tapIdx] ); // Q30 + Q_filterStates
104 4370638400 : outRealLeft_fx = W_mac_32_32( outRealLeft_fx, L_negate( filterStatesLeftImagPtr_fx[tapIdx] ), filterTapsLeftImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates
105 :
106 4370638400 : outImagLeft_fx = W_mac_32_32( outImagLeft_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsLeftImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates
107 4370638400 : outImagLeft_fx = W_mac_32_32( outImagLeft_fx, filterStatesLeftImagPtr_fx[tapIdx], filterTapsLeftRealPtr_fx[tapIdx] ); // Q30 + Q_filterStates
108 :
109 4370638400 : outRealRight_fx = W_mac_32_32( outRealRight_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsRightRealPtr_fx[tapIdx] ); // Q30 + Q_filterStates
110 4370638400 : outRealRight_fx = W_mac_32_32( outRealRight_fx, L_negate( filterStatesLeftImagPtr_fx[tapIdx] ), filterTapsRightImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates
111 :
112 4370638400 : outImagRight_fx = W_mac_32_32( outImagRight_fx, filterStatesLeftRealPtr_fx[tapIdx], filterTapsRightImagPtr_fx[tapIdx] ); // Q30 + Q_filterStates
113 4370638400 : outImagRight_fx = W_mac_32_32( outImagRight_fx, filterStatesLeftImagPtr_fx[tapIdx], filterTapsRightRealPtr_fx[tapIdx] ); // Q30 + Q_filterStates
114 : }
115 :
116 328128000 : shift_q = add( sub( Q_filterStates, Q_curr ), 1 );
117 :
118 328128000 : IF( shift_q != 0 )
119 : {
120 328128000 : outRealLeft_fx = W_shr( outRealLeft_fx, shift_q ); // Q_curr
121 328128000 : outImagLeft_fx = W_shr( outImagLeft_fx, shift_q ); // Q_curr
122 328128000 : outRealRight_fx = W_shr( outRealRight_fx, shift_q ); // Q_curr
123 328128000 : outImagRight_fx = W_shr( outImagRight_fx, shift_q ); // Q_curr
124 328128000 : hBinRenderer->hBinRenConvModule->Q_filterStatesLeft = Q_curr;
125 328128000 : move16();
126 : }
127 :
128 328128000 : filterStatesLeftRealPtr_fx[0] = CLDFB_real[chIdx][k][bandIdx];
129 328128000 : move32();
130 328128000 : filterStatesLeftImagPtr_fx[0] = CLDFB_imag[chIdx][k][bandIdx];
131 328128000 : move32();
132 :
133 :
134 : /* Left Real and Imag */
135 : // Q29 + Q_curr
136 :
137 328128000 : Word32 temp1 = L_shr( filterStatesLeftRealPtr_fx[0], 1 );
138 328128000 : Word32 temp2 = L_shr( filterStatesLeftImagPtr_fx[0], 1 );
139 :
140 :
141 328128000 : outRealLeft_fx = W_mac_32_32( outRealLeft_fx, temp1, filterTapsLeftRealPtr_fx[0] );
142 328128000 : outRealLeft_fx = W_mac_32_32( outRealLeft_fx, L_negate( temp2 ), filterTapsLeftImagPtr_fx[0] );
143 328128000 : out_Conv_CLDFB_real[0][k][bandIdx] = W_add( out_Conv_CLDFB_real[0][k][bandIdx], outRealLeft_fx ); // Q29
144 328128000 : move64();
145 :
146 328128000 : outImagLeft_fx = W_mac_32_32( outImagLeft_fx, temp1, filterTapsLeftImagPtr_fx[0] );
147 328128000 : outImagLeft_fx = W_mac_32_32( outImagLeft_fx, temp2, filterTapsLeftRealPtr_fx[0] );
148 328128000 : out_Conv_CLDFB_imag[0][k][bandIdx] = W_add( out_Conv_CLDFB_imag[0][k][bandIdx], outImagLeft_fx ); // Q29
149 328128000 : move64();
150 :
151 : /* Right Real and Imag */
152 328128000 : outRealRight_fx = W_mac_32_32( outRealRight_fx, temp1, filterTapsRightRealPtr_fx[0] );
153 328128000 : outRealRight_fx = W_mac_32_32( outRealRight_fx, L_negate( temp2 ), filterTapsRightImagPtr_fx[0] );
154 328128000 : out_Conv_CLDFB_real[1][k][bandIdx] = W_add( out_Conv_CLDFB_real[1][k][bandIdx], outRealRight_fx ); // Q29
155 328128000 : move64();
156 :
157 328128000 : outImagRight_fx = W_mac_32_32( outImagRight_fx, temp1, filterTapsRightImagPtr_fx[0] );
158 328128000 : outImagRight_fx = W_mac_32_32( outImagRight_fx, temp2, filterTapsRightRealPtr_fx[0] );
159 328128000 : out_Conv_CLDFB_imag[1][k][bandIdx] = W_add( out_Conv_CLDFB_imag[1][k][bandIdx], outImagRight_fx ); // Q29
160 328128000 : move64();
161 : }
162 : }
163 : }
164 :
165 136305 : return;
166 : }
167 :
168 : /*-------------------------------------------------------------------------
169 : * ivas_binRenderer_convModuleOpen()
170 : *
171 : * Open convolution module handle of fastconv binaural renderer
172 : *-------------------------------------------------------------------------*/
173 271 : static ivas_error ivas_binRenderer_convModuleOpen(
174 : BINAURAL_RENDERER_HANDLE hBinRenderer,
175 : const Word16 renderer_type,
176 : const Word16 isLoudspeaker,
177 : const AUDIO_CONFIG input_config,
178 : const HRTFS_FASTCONV_HANDLE hHrtf )
179 : {
180 : Word16 bandIdx, chIdx;
181 :
182 : BINRENDERER_CONV_MODULE_HANDLE_FX hBinRenConvModule;
183 :
184 : /*-----------------------------------------------------------------*
185 : * prepare library opening
186 : *-----------------------------------------------------------------*/
187 :
188 271 : IF( ( hBinRenConvModule = (BINRENDERER_CONV_MODULE_HANDLE_FX) malloc( sizeof( BINRENDERER_CONV_MODULE_FX ) ) ) == NULL )
189 : {
190 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
191 : }
192 :
193 271 : IF( !isLoudspeaker )
194 : {
195 140 : hBinRenderer->nInChannels = audioCfg2channels( input_config );
196 140 : move16();
197 : }
198 : ELSE
199 : {
200 : /* Note: needs to be revisited if multiple LFE support is required */
201 131 : hBinRenderer->nInChannels = sub( audioCfg2channels( input_config ), isLoudspeaker );
202 131 : move16();
203 : }
204 :
205 271 : IF( EQ_16( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
206 : {
207 69 : hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX;
208 69 : move16();
209 :
210 : /* Use variable order filtering */
211 69 : bandIdx = 0;
212 69 : move16();
213 414 : FOR( ; bandIdx < 5; bandIdx++ )
214 : {
215 345 : hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps;
216 345 : move16();
217 : }
218 414 : FOR( ; bandIdx < 10; bandIdx++ )
219 : {
220 345 : hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_6;
221 345 : move16();
222 : }
223 759 : FOR( ; bandIdx < 20; bandIdx++ )
224 : {
225 690 : hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_5;
226 690 : move16();
227 : }
228 759 : FOR( ; bandIdx < 30; bandIdx++ )
229 : {
230 690 : hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_4;
231 690 : move16();
232 : }
233 1319 : FOR( ; bandIdx < hBinRenderer->conv_band; bandIdx++ )
234 : {
235 1250 : hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_3;
236 1250 : move16();
237 : }
238 : }
239 : ELSE
240 : {
241 202 : IF( EQ_16( hBinRenderer->ivas_format, SBA_FORMAT ) )
242 : {
243 140 : hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA;
244 140 : move16();
245 : }
246 : ELSE
247 : {
248 62 : hBinRenConvModule->numTaps = BINAURAL_NTAPS;
249 62 : move16();
250 : }
251 :
252 : /* Use fixed order filtering */
253 202 : bandIdx = 0;
254 202 : move16();
255 8312 : FOR( ; bandIdx < hBinRenderer->conv_band; bandIdx++ )
256 : {
257 8110 : hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps;
258 8110 : move16();
259 : }
260 : }
261 :
262 : /* allocate memory for filter states */
263 271 : IF( ( hBinRenConvModule->filterTapsLeftReal_fx = (Word32 ***) malloc( hBinRenderer->conv_band * sizeof( Word32 ** ) ) ) == NULL )
264 : {
265 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
266 : }
267 :
268 271 : IF( ( hBinRenConvModule->filterTapsLeftImag_fx = (Word32 ***) malloc( hBinRenderer->conv_band * sizeof( Word32 ** ) ) ) == NULL )
269 : {
270 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
271 : }
272 :
273 271 : IF( ( hBinRenConvModule->filterTapsRightReal_fx = (Word32 ***) malloc( hBinRenderer->conv_band * sizeof( Word32 ** ) ) ) == NULL )
274 : {
275 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
276 : }
277 :
278 271 : IF( ( hBinRenConvModule->filterTapsRightImag_fx = (Word32 ***) malloc( hBinRenderer->conv_band * sizeof( Word32 ** ) ) ) == NULL )
279 : {
280 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
281 : }
282 :
283 11671 : FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
284 : {
285 11400 : IF( ( hBinRenConvModule->filterTapsLeftReal_fx[bandIdx] = (Word32 **) malloc( hBinRenderer->nInChannels * sizeof( Word32 * ) ) ) == NULL )
286 : {
287 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
288 : }
289 :
290 11400 : IF( ( hBinRenConvModule->filterTapsLeftImag_fx[bandIdx] = (Word32 **) malloc( hBinRenderer->nInChannels * sizeof( Word32 * ) ) ) == NULL )
291 : {
292 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
293 : }
294 :
295 11400 : IF( ( hBinRenConvModule->filterTapsRightReal_fx[bandIdx] = (Word32 **) malloc( hBinRenderer->nInChannels * sizeof( Word32 * ) ) ) == NULL )
296 : {
297 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
298 : }
299 :
300 11400 : IF( ( hBinRenConvModule->filterTapsRightImag_fx[bandIdx] = (Word32 **) malloc( hBinRenderer->nInChannels * sizeof( Word32 * ) ) ) == NULL )
301 : {
302 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
303 : }
304 : }
305 :
306 :
307 271 : IF( ( hBinRenConvModule->filterStatesLeftReal_fx = (Word32 ***) malloc( hBinRenderer->conv_band * sizeof( Word32 ** ) ) ) == NULL )
308 : {
309 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
310 : }
311 :
312 271 : IF( ( hBinRenConvModule->filterStatesLeftImag_fx = (Word32 ***) malloc( hBinRenderer->conv_band * sizeof( Word32 ** ) ) ) == NULL )
313 : {
314 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
315 : }
316 :
317 :
318 11671 : FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
319 : {
320 11400 : IF( ( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx] = (Word32 **) malloc( hBinRenderer->nInChannels * sizeof( Word32 * ) ) ) == NULL )
321 : {
322 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
323 : }
324 :
325 11400 : IF( ( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx] = (Word32 **) malloc( hBinRenderer->nInChannels * sizeof( Word32 * ) ) ) == NULL )
326 : {
327 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
328 : }
329 :
330 :
331 146130 : FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ )
332 : {
333 134730 : IF( ( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx] = (Word32 *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( Word32 ) ) ) == NULL )
334 : {
335 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
336 : }
337 :
338 134730 : IF( ( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx] = (Word32 *) malloc( hBinRenConvModule->numTapsArray[bandIdx] * sizeof( Word32 ) ) ) == NULL )
339 : {
340 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n" ) );
341 : }
342 : }
343 : }
344 : /* set memories */
345 11671 : FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
346 : {
347 146130 : FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ )
348 : {
349 134730 : Word16 tmp = 0;
350 134730 : move16();
351 :
352 134730 : IF( isLoudspeaker )
353 : {
354 28650 : IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_5_1 ) )
355 : {
356 19650 : tmp = channelIndex_CICP6[chIdx];
357 19650 : move16();
358 : }
359 9000 : ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_7_1 ) )
360 : {
361 0 : tmp = channelIndex_CICP12[chIdx];
362 0 : move16();
363 : }
364 9000 : ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_5_1_2 ) )
365 : {
366 420 : tmp = channelIndex_CICP14[chIdx];
367 420 : move16();
368 : }
369 8580 : ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_5_1_4 ) )
370 : {
371 0 : tmp = channelIndex_CICP16[chIdx];
372 0 : move16();
373 : }
374 8580 : ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_7_1_4 ) )
375 : {
376 8580 : tmp = channelIndex_CICP19[chIdx];
377 8580 : move16();
378 : }
379 : }
380 :
381 134730 : IF( EQ_16( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
382 : {
383 : /* set the memories to zero */
384 19150 : set32_fx( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] );
385 19150 : set32_fx( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] );
386 19150 : hBinRenConvModule->Q_filterStatesLeft = 31;
387 19150 : move16();
388 19150 : IF( isLoudspeaker )
389 : {
390 19150 : hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftBRIRReal_fx[bandIdx][tmp];
391 19150 : hBinRenConvModule->filterTapsLeftImag_fx[bandIdx][chIdx] = hHrtf->leftBRIRImag_fx[bandIdx][tmp];
392 19150 : hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightBRIRReal_fx[bandIdx][tmp];
393 19150 : hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightBRIRImag_fx[bandIdx][tmp];
394 : }
395 : }
396 : ELSE
397 : {
398 : /* set the memories to zero */
399 115580 : set32_fx( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTaps );
400 115580 : set32_fx( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTaps );
401 115580 : hBinRenConvModule->Q_filterStatesLeft = 31;
402 115580 : move16();
403 115580 : IF( isLoudspeaker )
404 : {
405 9500 : hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_fx[bandIdx][tmp];
406 9500 : hBinRenConvModule->filterTapsLeftImag_fx[bandIdx][chIdx] = hHrtf->leftHRIRImag_fx[bandIdx][tmp];
407 9500 : hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightHRIRReal_fx[bandIdx][tmp];
408 9500 : hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightHRIRImag_fx[bandIdx][tmp];
409 : }
410 : ELSE
411 : {
412 106080 : IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_HOA3 ) )
413 : {
414 : /* HOA3 filter coefficients */
415 106080 : hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA3_fx[bandIdx][chIdx];
416 106080 : hBinRenConvModule->filterTapsLeftImag_fx[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA3_fx[bandIdx][chIdx];
417 106080 : hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA3_fx[bandIdx][chIdx];
418 106080 : hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA3_fx[bandIdx][chIdx];
419 : }
420 0 : ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_HOA2 ) )
421 : {
422 : /* HOA2 filter coefficients */
423 0 : hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA2_fx[bandIdx][chIdx];
424 0 : hBinRenConvModule->filterTapsLeftImag_fx[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA2_fx[bandIdx][chIdx];
425 0 : hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA2_fx[bandIdx][chIdx];
426 0 : hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA2_fx[bandIdx][chIdx];
427 : }
428 0 : ELSE IF( EQ_16( input_config, IVAS_AUDIO_CONFIG_FOA ) )
429 : {
430 : /* FOA filter coefficients */
431 0 : hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_FOA_fx[bandIdx][chIdx];
432 0 : hBinRenConvModule->filterTapsLeftImag_fx[bandIdx][chIdx] = hHrtf->leftHRIRImag_FOA_fx[bandIdx][chIdx];
433 0 : hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightHRIRReal_FOA_fx[bandIdx][chIdx];
434 0 : hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightHRIRImag_FOA_fx[bandIdx][chIdx];
435 : }
436 : ELSE
437 : {
438 0 : return IVAS_ERR_INVALID_INPUT_FORMAT;
439 : }
440 : }
441 : }
442 : }
443 : }
444 :
445 :
446 271 : hBinRenderer->hBinRenConvModule = hBinRenConvModule;
447 :
448 271 : return IVAS_ERR_OK;
449 : }
450 :
451 : /*-------------------------------------------------------------------------*
452 : * ivas_init_binaural_hrtf()
453 : *
454 : * initialize memory for HrtfFastConv structure elements
455 : *-------------------------------------------------------------------------*/
456 61 : void ivas_init_binaural_hrtf_fx(
457 : HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */
458 : )
459 : {
460 : Word16 i;
461 :
462 61 : HrtfFastConv->leftHRIRReal_HOA3_fx = NULL;
463 61 : HrtfFastConv->leftHRIRImag_HOA3_fx = NULL;
464 61 : HrtfFastConv->rightHRIRReal_HOA3_fx = NULL;
465 61 : HrtfFastConv->rightHRIRImag_HOA3_fx = NULL;
466 61 : HrtfFastConv->FASTCONV_HOA3_latency_s_fx = 0;
467 61 : move32();
468 :
469 61 : HrtfFastConv->leftHRIRReal_fx = NULL;
470 61 : HrtfFastConv->leftHRIRImag_fx = NULL;
471 61 : HrtfFastConv->rightHRIRReal_fx = NULL;
472 61 : HrtfFastConv->rightHRIRImag_fx = NULL;
473 61 : HrtfFastConv->FASTCONV_HRIR_latency_s_fx = 0;
474 61 : move32();
475 :
476 61 : HrtfFastConv->leftBRIRReal_fx = NULL;
477 61 : HrtfFastConv->leftBRIRImag_fx = NULL;
478 61 : HrtfFastConv->rightBRIRReal_fx = NULL;
479 61 : HrtfFastConv->rightBRIRImag_fx = NULL;
480 61 : HrtfFastConv->FASTCONV_BRIR_latency_s_fx = 0;
481 61 : move32();
482 :
483 61 : HrtfFastConv->leftHRIRReal_HOA2_fx = NULL;
484 61 : HrtfFastConv->leftHRIRImag_HOA2_fx = NULL;
485 61 : HrtfFastConv->rightHRIRReal_HOA2_fx = NULL;
486 61 : HrtfFastConv->rightHRIRImag_HOA2_fx = NULL;
487 61 : HrtfFastConv->FASTCONV_HOA2_latency_s_fx = 0;
488 61 : move32();
489 :
490 61 : HrtfFastConv->leftHRIRReal_FOA_fx = NULL;
491 61 : HrtfFastConv->leftHRIRImag_FOA_fx = NULL;
492 61 : HrtfFastConv->rightHRIRReal_FOA_fx = NULL;
493 61 : HrtfFastConv->rightHRIRImag_FOA_fx = NULL;
494 61 : HrtfFastConv->FASTCONV_FOA_latency_s_fx = 0;
495 61 : move32();
496 :
497 61 : HrtfFastConv->allocate_init_flag = 0;
498 61 : move16();
499 :
500 3721 : FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ )
501 : {
502 3660 : HrtfFastConv->fastconvReverberationTimes_fx[i] = 0;
503 3660 : move32();
504 3660 : HrtfFastConv->fastconvReverberationEneCorrections_fx[i] = 0;
505 3660 : move32();
506 : }
507 :
508 61 : return;
509 : }
510 :
511 : /*-------------------------------------------------------------------------*
512 : * ivas_alloc_pppMem()
513 : *
514 : * Allocate memory for tripple pointer elements
515 : *-------------------------------------------------------------------------*/
516 728 : static ivas_error ivas_alloc_pppMem_fx(
517 : Word32 ****pppMem, /*Qx*/
518 : const Word16 dim1,
519 : const Word16 dim2,
520 : const Word16 dim3,
521 : const Word16 allocate_init_flag )
522 : {
523 : Word16 i, j;
524 728 : Word32 ***localMem = NULL;
525 :
526 728 : IF( ( localMem = (Word32 ***) malloc( dim1 * sizeof( Word32 ** ) ) ) == NULL )
527 : {
528 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" );
529 : }
530 :
531 37128 : FOR( i = 0; i < dim1; i++ ){
532 36400 : IF( ( localMem[i] = (Word32 **) malloc( dim2 * sizeof( Word32 * ) ) ) == NULL ){
533 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" );
534 : }
535 36400 : IF( allocate_init_flag == 0 )
536 : {
537 294400 : FOR( j = 0; j < dim2; j++ )
538 : {
539 271400 : IF( ( localMem[i][j] = (Word32 *) malloc( dim3 * sizeof( Word32 ) ) ) == NULL )
540 : {
541 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF memory" );
542 : }
543 : }
544 : }
545 : }
546 :
547 728 : *pppMem = localMem;
548 :
549 728 : return IVAS_ERR_OK;
550 : }
551 :
552 : /*-------------------------------------------------------------------------*
553 : * ivas_allocate_binaural_hrtf()
554 : *
555 : * Allocate memory for HrtfFastConv structure elements
556 : *-------------------------------------------------------------------------*/
557 153 : ivas_error ivas_allocate_binaural_hrtf_fx(
558 : HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */
559 : const AUDIO_CONFIG input_config, /* i : input audio configuration */
560 : const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */
561 : const RENDERER_TYPE renderer_type, /* i : renderer type */
562 : const Word16 allocate_init_flag /* i : Memory allocation flag */
563 : )
564 : {
565 153 : test();
566 153 : IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) )
567 : {
568 52 : test();
569 52 : test();
570 52 : test();
571 52 : IF( ( HrtfFastConv->leftHRIRReal_HOA3_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA3_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA3_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA3_fx != NULL ) )
572 : {
573 0 : return IVAS_ERR_OK;
574 : }
575 : ELSE
576 : {
577 52 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
578 : {
579 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA3" );
580 : }
581 52 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
582 : {
583 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA3" );
584 : }
585 52 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
586 : {
587 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA3" );
588 : }
589 52 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
590 : {
591 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA3" );
592 : }
593 : }
594 : }
595 :
596 153 : test();
597 153 : IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) )
598 : {
599 23 : test();
600 23 : test();
601 23 : test();
602 23 : IF( ( HrtfFastConv->leftHRIRReal_HOA2_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA2_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA2_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA2_fx != NULL ) )
603 : {
604 0 : return IVAS_ERR_OK;
605 : }
606 : ELSE
607 : {
608 23 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
609 : {
610 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA2" );
611 : }
612 23 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
613 : {
614 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA2" );
615 : }
616 23 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
617 : {
618 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA2" );
619 : }
620 23 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
621 : {
622 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA2" );
623 : }
624 : }
625 : }
626 :
627 153 : test();
628 153 : IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_FOA ) )
629 : {
630 23 : test();
631 23 : test();
632 23 : test();
633 23 : IF( ( HrtfFastConv->leftHRIRReal_FOA_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_FOA_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_FOA_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_FOA_fx != NULL ) )
634 : {
635 0 : return IVAS_ERR_OK;
636 : }
637 : ELSE
638 : {
639 23 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
640 : {
641 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_FOA" );
642 : }
643 23 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
644 : {
645 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_FOA" );
646 : }
647 23 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
648 : {
649 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_FOA" );
650 : }
651 23 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) )
652 : {
653 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_FOA" );
654 : }
655 : }
656 : }
657 :
658 153 : test();
659 153 : IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) )
660 : {
661 140 : test();
662 140 : test();
663 140 : test();
664 140 : IF( ( HrtfFastConv->leftHRIRReal_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_fx != NULL ) )
665 : {
666 92 : return IVAS_ERR_OK;
667 : }
668 : ELSE
669 : {
670 48 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) )
671 : {
672 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal" );
673 : }
674 48 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) )
675 : {
676 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag" );
677 : }
678 48 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) )
679 : {
680 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal" );
681 : }
682 48 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) )
683 : {
684 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag" );
685 : }
686 : }
687 : }
688 :
689 61 : test();
690 61 : IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) )
691 : {
692 36 : test();
693 36 : test();
694 36 : test();
695 36 : IF( ( HrtfFastConv->leftBRIRReal_fx != NULL ) && ( HrtfFastConv->leftBRIRImag_fx != NULL ) && ( HrtfFastConv->rightBRIRReal_fx != NULL ) && ( HrtfFastConv->rightBRIRImag_fx != NULL ) )
696 : {
697 0 : return IVAS_ERR_OK;
698 : }
699 : ELSE
700 : {
701 36 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) )
702 : {
703 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRReal" );
704 : }
705 36 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) )
706 : {
707 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRImag" );
708 : }
709 36 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) )
710 : {
711 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRReal" );
712 : }
713 36 : IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) )
714 : {
715 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRImag" );
716 : }
717 : }
718 : }
719 :
720 61 : return IVAS_ERR_OK;
721 : }
722 :
723 : /*-------------------------------------------------------------------------*
724 : * ivas_binaural_HRTF_open()
725 : *
726 : *
727 : *-------------------------------------------------------------------------*/
728 271 : static ivas_error ivas_binaural_hrtf_open_fx(
729 : HRTFS_FASTCONV_HANDLE *hHrtfFastConv, /* i : fastconv HRTF handle */
730 : const AUDIO_CONFIG input_config, /* i : output configuration */
731 : const RENDERER_TYPE renderer_type /* i : renderer type */
732 : )
733 : {
734 : Word16 i, j;
735 : ivas_error error;
736 :
737 271 : test();
738 271 : IF( hHrtfFastConv != NULL && *hHrtfFastConv != NULL )
739 : {
740 : /* Tables already loaded from file */
741 233 : return IVAS_ERR_OK;
742 : }
743 : ELSE
744 : {
745 : /* Initialise tables from ROM */
746 : HRTFS_FASTCONV *HrtfFastConv;
747 :
748 38 : IF( ( HrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) ) ) == NULL )
749 : {
750 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for FastConv HRTF tables" );
751 : }
752 :
753 38 : ivas_init_binaural_hrtf_fx( HrtfFastConv );
754 :
755 38 : test();
756 38 : IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) )
757 : {
758 25 : HrtfFastConv->FASTCONV_HRIR_latency_s_fx = FASTCONV_HRIR_latency_s_fx;
759 25 : move32();
760 : }
761 38 : if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) )
762 : {
763 0 : HrtfFastConv->FASTCONV_HOA2_latency_s_fx = FASTCONV_HOA2_latency_s_fx;
764 0 : move32();
765 : }
766 38 : if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) )
767 : {
768 29 : HrtfFastConv->FASTCONV_HOA3_latency_s_fx = FASTCONV_HOA3_latency_s_fx;
769 29 : move32();
770 : }
771 38 : if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) )
772 : {
773 0 : HrtfFastConv->FASTCONV_FOA_latency_s_fx = FASTCONV_FOA_latency_s_fx;
774 0 : move32();
775 : }
776 38 : test();
777 38 : IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
778 : {
779 13 : HrtfFastConv->FASTCONV_BRIR_latency_s_fx = FASTCONV_BRIR_latency_s_fx;
780 13 : move32();
781 : }
782 :
783 38 : HrtfFastConv->allocate_init_flag = 1;
784 38 : move16();
785 :
786 38 : IF( NE_32( ( error = ivas_allocate_binaural_hrtf_fx( HrtfFastConv, input_config, BINAURAL_INPUT_AUDIO_CONFIG_INVALID, renderer_type, HrtfFastConv->allocate_init_flag ) ), IVAS_ERR_OK ) )
787 : {
788 0 : return error;
789 : }
790 1938 : FOR( i = 0; i < BINAURAL_CONVBANDS; i++ )
791 : {
792 1900 : IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) )
793 : {
794 20000 : FOR( j = 0; j < HRTF_LS_CHANNELS; j++ )
795 : {
796 18750 : HrtfFastConv->leftHRIRReal_fx[i][j] = leftHRIRReal_fx[i][j];
797 18750 : HrtfFastConv->leftHRIRImag_fx[i][j] = leftHRIRImag_fx[i][j];
798 18750 : HrtfFastConv->rightHRIRReal_fx[i][j] = rightHRIRReal_fx[i][j];
799 18750 : HrtfFastConv->rightHRIRImag_fx[i][j] = rightHRIRImag_fx[i][j];
800 : }
801 : }
802 650 : ELSE IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
803 : {
804 10400 : FOR( j = 0; j < HRTF_LS_CHANNELS; j++ )
805 : {
806 9750 : HrtfFastConv->leftBRIRReal_fx[i][j] = leftBRIRReal_fx[i][j];
807 9750 : HrtfFastConv->leftBRIRImag_fx[i][j] = leftBRIRImag_fx[i][j];
808 9750 : HrtfFastConv->rightBRIRReal_fx[i][j] = rightBRIRReal_fx[i][j];
809 9750 : HrtfFastConv->rightBRIRImag_fx[i][j] = rightBRIRImag_fx[i][j];
810 : }
811 : }
812 1900 : IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) )
813 : {
814 24650 : FOR( j = 0; j < HOA3_CHANNELS; j++ )
815 : {
816 23200 : HrtfFastConv->leftHRIRReal_HOA3_fx[i][j] = leftHRIRReal_HOA3_fx[i][j];
817 23200 : HrtfFastConv->leftHRIRImag_HOA3_fx[i][j] = leftHRIRImag_HOA3_fx[i][j];
818 23200 : HrtfFastConv->rightHRIRReal_HOA3_fx[i][j] = rightHRIRReal_HOA3_fx[i][j];
819 23200 : HrtfFastConv->rightHRIRImag_HOA3_fx[i][j] = rightHRIRImag_HOA3_fx[i][j];
820 : }
821 : }
822 1900 : IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) )
823 : {
824 0 : FOR( j = 0; j < HOA2_CHANNELS; j++ )
825 : {
826 0 : HrtfFastConv->leftHRIRReal_HOA2_fx[i][j] = leftHRIRReal_HOA2_fx[i][j];
827 0 : HrtfFastConv->leftHRIRImag_HOA2_fx[i][j] = leftHRIRImag_HOA2_fx[i][j];
828 0 : HrtfFastConv->rightHRIRReal_HOA2_fx[i][j] = rightHRIRReal_HOA2_fx[i][j];
829 0 : HrtfFastConv->rightHRIRImag_HOA2_fx[i][j] = rightHRIRImag_HOA2_fx[i][j];
830 : }
831 : }
832 1900 : IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) )
833 : {
834 0 : FOR( j = 0; j < FOA_CHANNELS; j++ )
835 : {
836 0 : HrtfFastConv->leftHRIRReal_FOA_fx[i][j] = leftHRIRReal_FOA_fx[i][j];
837 0 : HrtfFastConv->leftHRIRImag_FOA_fx[i][j] = leftHRIRImag_FOA_fx[i][j];
838 0 : HrtfFastConv->rightHRIRReal_FOA_fx[i][j] = rightHRIRReal_FOA_fx[i][j];
839 0 : HrtfFastConv->rightHRIRImag_FOA_fx[i][j] = rightHRIRImag_FOA_fx[i][j];
840 : }
841 : }
842 : }
843 38 : Copy32( fastconvReverberationTimes_fx, HrtfFastConv->fastconvReverberationTimes_fx, CLDFB_NO_CHANNELS_MAX );
844 38 : Copy32( fastconvReverberationEneCorrections_fx, HrtfFastConv->fastconvReverberationEneCorrections_fx, CLDFB_NO_CHANNELS_MAX );
845 :
846 38 : *hHrtfFastConv = HrtfFastConv;
847 : }
848 :
849 38 : return IVAS_ERR_OK;
850 : }
851 : /*-------------------------------------------------------------------------*
852 : * ivas_binaural_obtain_DMX_fx()
853 : *
854 : *
855 : *-------------------------------------------------------------------------*/
856 :
857 0 : static void ivas_binaural_obtain_DMX_fx(
858 : const Word16 numTimeSlots,
859 : BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: fastconv binaural renderer handle */
860 : Word32 RealBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals Q_in */
861 : Word32 ImagBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals Q_in */
862 : Word32 realDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*Q_in-1*/
863 : Word32 imagDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] ) /*Q_in-1*/
864 : {
865 : Word16 chIdx, bandIdx, k;
866 :
867 0 : test();
868 0 : IF( EQ_32( hBinRenderer->ivas_format, MC_FORMAT ) )
869 : {
870 : /* Obtain the downmix */
871 : Word32 P_in_fx[CLDFB_NO_CHANNELS_MAX];
872 : Word32 P_out_fx, factEQ_fx;
873 : Word16 chOutIdx;
874 : Word32 temp1_fx, temp2_fx;
875 :
876 0 : FOR( k = 0; k < numTimeSlots; k++ )
877 : {
878 0 : FOR( chOutIdx = 0; chOutIdx < BINAURAL_CHANNELS; chOutIdx++ )
879 : {
880 0 : set32_fx( realDMX[chOutIdx][k], 0, CLDFB_NO_CHANNELS_MAX );
881 0 : set32_fx( imagDMX[chOutIdx][k], 0, CLDFB_NO_CHANNELS_MAX );
882 : }
883 : }
884 :
885 0 : FOR( chOutIdx = 0; chOutIdx < BINAURAL_CHANNELS; chOutIdx++ )
886 : {
887 0 : set32_fx( P_in_fx, 0, hBinRenderer->conv_band );
888 :
889 0 : FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ )
890 : {
891 0 : Word32 dmxConst = hBinRenderer->hReverb->dmxmtx_fx[chOutIdx][chIdx];
892 0 : move32();
893 :
894 0 : FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
895 : {
896 0 : FOR( k = 0; k < numTimeSlots; k++ )
897 : {
898 0 : temp1_fx = Mpy_32_32( RealBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in
899 0 : temp2_fx = Mpy_32_32( ImagBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in
900 0 : realDMX[chOutIdx][k][bandIdx] = L_add( realDMX[chOutIdx][k][bandIdx], temp1_fx ); // Q_in
901 0 : move32();
902 0 : imagDMX[chOutIdx][k][bandIdx] = L_add( imagDMX[chOutIdx][k][bandIdx], temp2_fx ); // Q_in
903 0 : move32();
904 :
905 0 : P_in_fx[bandIdx] = L_add( P_in_fx[bandIdx], L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); // Q31-2*Q_in
906 0 : move32();
907 : }
908 : }
909 : }
910 :
911 0 : FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
912 : {
913 0 : P_out_fx = 0;
914 0 : move32();
915 0 : FOR( k = 0; k < numTimeSlots; k++ )
916 : {
917 0 : temp1_fx = realDMX[chOutIdx][k][bandIdx];
918 0 : move32();
919 0 : temp2_fx = imagDMX[chOutIdx][k][bandIdx];
920 0 : move32();
921 0 : P_out_fx = L_add( P_out_fx, L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); // Q31-2*Q_in
922 : }
923 0 : test();
924 0 : IF( ( P_in_fx[bandIdx] <= 0 ) || ( P_out_fx <= 0 ) )
925 : {
926 0 : factEQ_fx = 0x40000000; // 1.0f in Q30
927 0 : move32();
928 : }
929 : ELSE
930 : {
931 0 : Word16 div = divide3232( P_in_fx[bandIdx], P_out_fx );
932 0 : Word16 exp = norm_l( div );
933 0 : factEQ_fx = Sqrt32( L_shl( div, Q16 ), &exp );
934 0 : factEQ_fx = L_shl( factEQ_fx, sub( exp, 1 ) ); // Q30
935 : }
936 0 : if ( factEQ_fx <= 0 )
937 : {
938 0 : factEQ_fx = 0x40000000; // 1.0f in Q30
939 0 : move32();
940 : }
941 :
942 0 : factEQ_fx = L_max( L_min( factEQ_fx, 0x7fffffff ), 0x20000000 ); // Q30 , 0x7fffffff -> (1.0f in Q31)-1, 0x20000000 ->1.0f in Q29
943 0 : FOR( k = 0; k < numTimeSlots; k++ )
944 : {
945 0 : realDMX[chOutIdx][k][bandIdx] = Mpy_32_32( realDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1
946 0 : move32();
947 0 : imagDMX[chOutIdx][k][bandIdx] = Mpy_32_32( imagDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1
948 0 : move32();
949 : }
950 : }
951 : }
952 : }
953 0 : ELSE IF( EQ_32( hBinRenderer->ivas_format, SBA_FORMAT ) || EQ_32( hBinRenderer->ivas_format, MASA_FORMAT ) )
954 : {
955 : Word32 *outRealLeftPtr_fx, *outImagLeftPtr_fx, *outRealRightPtr_fx, *outImagRightPtr_fx;
956 : Word32 *inRealPtr_fx, *inImagPtr_fx;
957 :
958 : /*compute DMX */
959 0 : FOR( k = 0; k < numTimeSlots; k++ )
960 : {
961 0 : outRealLeftPtr_fx = realDMX[0][k];
962 0 : outImagLeftPtr_fx = imagDMX[0][k];
963 0 : outRealRightPtr_fx = realDMX[1][k];
964 0 : outImagRightPtr_fx = imagDMX[1][k];
965 0 : set32_fx( outRealLeftPtr_fx, 0, CLDFB_NO_CHANNELS_MAX );
966 0 : set32_fx( outImagLeftPtr_fx, 0, CLDFB_NO_CHANNELS_MAX );
967 0 : set32_fx( outRealRightPtr_fx, 0, CLDFB_NO_CHANNELS_MAX );
968 0 : set32_fx( outImagRightPtr_fx, 0, CLDFB_NO_CHANNELS_MAX );
969 :
970 0 : FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ )
971 : {
972 0 : Word32 foa_const_fx = L_shl( hBinRenderer->hReverb->foa_enc_fx[chIdx][1], 1 ); // Q30
973 :
974 0 : inRealPtr_fx = (Word32 *) &( RealBuffer[chIdx][k][0] );
975 0 : inImagPtr_fx = (Word32 *) &( ImagBuffer[chIdx][k][0] );
976 :
977 0 : FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ )
978 : {
979 0 : outRealLeftPtr_fx[bandIdx] = L_add( outRealLeftPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1
980 0 : move32();
981 0 : outImagLeftPtr_fx[bandIdx] = L_add( outImagLeftPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1
982 0 : move32();
983 :
984 0 : outRealRightPtr_fx[bandIdx] = L_add( outRealRightPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1
985 0 : move32();
986 0 : outImagRightPtr_fx[bandIdx] = L_add( outImagRightPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1
987 0 : move32();
988 : }
989 : }
990 : }
991 : }
992 :
993 0 : return;
994 : }
995 :
996 : /*-------------------------------------------------------------------------
997 : * ivas_binRenderer_open()
998 : *
999 : * Open fastconv binaural renderer handle
1000 : *-------------------------------------------------------------------------*/
1001 271 : ivas_error ivas_binRenderer_open_fx(
1002 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
1003 : )
1004 : {
1005 : BINAURAL_RENDERER_HANDLE hBinRenderer;
1006 : Word16 convBand, chIdx, k;
1007 : ivas_error error;
1008 :
1009 271 : error = IVAS_ERR_OK;
1010 271 : move32();
1011 :
1012 : /*-----------------------------------------------------------------*
1013 : * prepare library opening
1014 : *-----------------------------------------------------------------*/
1015 :
1016 271 : IF( ( hBinRenderer = (BINAURAL_RENDERER_HANDLE) malloc( sizeof( BINAURAL_RENDERER ) ) ) == NULL )
1017 : {
1018 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Renderer\n" ) );
1019 : }
1020 :
1021 271 : hBinRenderer->hInputSetup = &st_ivas->hIntSetup;
1022 :
1023 : /* Define of head rotation has to be done in binRendeder in CLDFB*/
1024 271 : hBinRenderer->rotInCldfb = 0;
1025 271 : move16();
1026 271 : test();
1027 271 : if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
1028 : {
1029 178 : hBinRenderer->rotInCldfb = 1;
1030 178 : move16();
1031 : }
1032 :
1033 :
1034 : /* Declare some common variables needed for renderer */
1035 : /* Which format used for binaural rendering (needed for late reverb) ? MC or SBA */
1036 271 : IF( st_ivas->hIntSetup.is_loudspeaker_setup )
1037 : {
1038 124 : hBinRenderer->ivas_format = MC_FORMAT;
1039 124 : move32();
1040 : }
1041 : ELSE
1042 : {
1043 147 : hBinRenderer->ivas_format = SBA_FORMAT;
1044 147 : move32();
1045 : }
1046 271 : hBinRenderer->max_band = extract_l( Mpy_32_32( Mpy_32_32( BINAURAL_MAXBANDS_Q25, L_shl( st_ivas->hDecoderConfig->output_Fs, Q6 ) ), ONE_BY_48000_Q31 ) );
1047 271 : move16();
1048 :
1049 271 : convBand = hBinRenderer->max_band;
1050 271 : move16();
1051 :
1052 271 : hBinRenderer->timeSlots = MAX_PARAM_SPATIAL_SUBFRAMES; /* Corresponds to 5 msec sound to motion latency */
1053 271 : move16();
1054 :
1055 271 : IF( GT_16( convBand, BINAURAL_CONVBANDS ) )
1056 : {
1057 174 : hBinRenderer->conv_band = BINAURAL_CONVBANDS;
1058 174 : move16();
1059 : }
1060 : ELSE
1061 : {
1062 97 : hBinRenderer->conv_band = convBand;
1063 97 : move16();
1064 : }
1065 :
1066 : /*LFE rendering switched off by default*/
1067 271 : hBinRenderer->render_lfe = 0;
1068 271 : move16();
1069 :
1070 271 : test();
1071 271 : if ( NE_32( st_ivas->ivas_format, ISM_FORMAT ) && st_ivas->hIntSetup.is_loudspeaker_setup )
1072 : {
1073 124 : hBinRenderer->render_lfe = 1;
1074 124 : move16();
1075 : }
1076 :
1077 : /* Load HRTF tables */
1078 271 : IF( NE_32( ( error = ivas_binaural_hrtf_open_fx( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ), IVAS_ERR_OK ) )
1079 : {
1080 0 : return error;
1081 : }
1082 :
1083 271 : test();
1084 271 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hIntSetup.is_loudspeaker_setup == 0 ) )
1085 7 : {
1086 : IVAS_OUTPUT_SETUP out_setup;
1087 :
1088 : /* Allocate memories and buffers needed for convolutional module in CICP19 */
1089 7 : IF( NE_32( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, 1, IVAS_AUDIO_CONFIG_7_1_4, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) )
1090 : {
1091 0 : return error;
1092 : }
1093 :
1094 7 : ivas_output_init( &out_setup, IVAS_AUDIO_CONFIG_7_1_4 );
1095 :
1096 7 : IF( st_ivas->hoa_dec_mtx == NULL )
1097 : {
1098 7 : IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ), IVAS_ERR_OK ) )
1099 : {
1100 0 : return error;
1101 : }
1102 : }
1103 :
1104 7 : hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx;
1105 7 : st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx;
1106 7 : move32();
1107 : }
1108 : ELSE
1109 : {
1110 : /* Allocate memories and buffers needed for convolutional module */
1111 264 : IF( NE_32( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, st_ivas->hIntSetup.is_loudspeaker_setup, st_ivas->hIntSetup.output_config, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) )
1112 : {
1113 0 : return error;
1114 : }
1115 :
1116 264 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
1117 : {
1118 202 : IF( EQ_32( hBinRenderer->ivas_format, MC_FORMAT ) )
1119 : {
1120 62 : st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s_fx;
1121 62 : move32();
1122 : }
1123 : ELSE
1124 : {
1125 140 : IF( EQ_16( hBinRenderer->nInChannels, 16 ) )
1126 : {
1127 140 : st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s_fx;
1128 140 : move32();
1129 : }
1130 0 : ELSE IF( EQ_16( hBinRenderer->nInChannels, 9 ) )
1131 : {
1132 0 : st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA2_latency_s_fx;
1133 0 : move32();
1134 : }
1135 0 : ELSE IF( EQ_16( hBinRenderer->nInChannels, 4 ) )
1136 : {
1137 0 : st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_FOA_latency_s_fx;
1138 0 : move32();
1139 : }
1140 : ELSE
1141 : {
1142 0 : return IVAS_ERR_INVALID_INPUT_FORMAT;
1143 : }
1144 : }
1145 : }
1146 : ELSE
1147 : {
1148 : /* same value for MC or HOA both use MC BRIR*/
1149 62 : st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx;
1150 62 : move32();
1151 : }
1152 : }
1153 :
1154 : /* Allocate memories needed for reverb module */
1155 271 : test();
1156 271 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
1157 : {
1158 0 : IF( NE_32( ( error = ivas_binaural_reverb_open_fastconv_fx( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) )
1159 : {
1160 0 : return error;
1161 : }
1162 :
1163 : /* initialize the dmx matrix */
1164 0 : FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ )
1165 : {
1166 0 : FOR( k = 0; k < hBinRenderer->nInChannels; k++ )
1167 : {
1168 0 : hBinRenderer->hReverb->dmxmtx_fx[chIdx][k] = dmxmtx_table_fx[chIdx][k];
1169 0 : move32();
1170 : }
1171 : }
1172 : }
1173 : ELSE
1174 : {
1175 271 : hBinRenderer->hReverb = NULL;
1176 : }
1177 :
1178 271 : hBinRenderer->hEFAPdata = NULL;
1179 :
1180 271 : IF( hBinRenderer->hReverb != NULL )
1181 : {
1182 0 : test();
1183 0 : test();
1184 0 : IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 )
1185 : {
1186 0 : FOR( k = 0; k < 11; k++ )
1187 : {
1188 0 : ivas_dirac_dec_get_response_fx( extract_l( L_shr_r( ls_azimuth_CICP19_fx[k], 22 ) ), extract_l( L_shr_r( ls_elevation_CICP19_fx[k], 22 ) ), hBinRenderer->hReverb->foa_enc_fx[k], 1, Q29 );
1189 : // Q29: hBinRenderer->hReverb->foa_enc_fx[k]
1190 : }
1191 : }
1192 0 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
1193 : {
1194 0 : IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) )
1195 : {
1196 0 : return error;
1197 : }
1198 :
1199 : /* Copy handles to bin renderer handle*/
1200 0 : hBinRenderer->hEFAPdata = st_ivas->hEFAPdata;
1201 : }
1202 : }
1203 :
1204 : /* Copy the handles to main handle */
1205 271 : st_ivas->hBinRenderer = hBinRenderer;
1206 :
1207 271 : return error;
1208 : }
1209 :
1210 : /*-------------------------------------------------------------------------
1211 : * ivas_binRenderer_convModuleClose()
1212 : *
1213 : * Close convolution module handle of fastconv binaural renderer
1214 : *------------------------------------------------------------------------*/
1215 271 : static void ivas_binRenderer_convModuleClose_fx(
1216 : BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: fastconv binaural renderer handle */
1217 : )
1218 : {
1219 : Word16 bandIdx, chIdx;
1220 :
1221 : BINRENDERER_CONV_MODULE_HANDLE_FX hBinRenConvModule;
1222 :
1223 271 : hBinRenConvModule = ( *hBinRenderer )->hBinRenConvModule;
1224 :
1225 271 : IF( hBinRenConvModule == NULL )
1226 : {
1227 0 : return;
1228 : }
1229 :
1230 11671 : FOR( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ )
1231 : {
1232 11400 : free( hBinRenConvModule->filterTapsLeftReal_fx[bandIdx] );
1233 11400 : hBinRenConvModule->filterTapsLeftReal_fx[bandIdx] = NULL;
1234 :
1235 11400 : free( hBinRenConvModule->filterTapsLeftImag_fx[bandIdx] );
1236 11400 : hBinRenConvModule->filterTapsLeftImag_fx[bandIdx] = NULL;
1237 :
1238 11400 : free( hBinRenConvModule->filterTapsRightReal_fx[bandIdx] );
1239 11400 : hBinRenConvModule->filterTapsRightReal_fx[bandIdx] = NULL;
1240 :
1241 11400 : free( hBinRenConvModule->filterTapsRightImag_fx[bandIdx] );
1242 11400 : hBinRenConvModule->filterTapsRightImag_fx[bandIdx] = NULL;
1243 : }
1244 :
1245 271 : free( hBinRenConvModule->filterTapsLeftReal_fx );
1246 271 : hBinRenConvModule->filterTapsLeftReal_fx = NULL;
1247 :
1248 271 : free( hBinRenConvModule->filterTapsLeftImag_fx );
1249 271 : hBinRenConvModule->filterTapsLeftImag_fx = NULL;
1250 :
1251 271 : free( hBinRenConvModule->filterTapsRightReal_fx );
1252 271 : hBinRenConvModule->filterTapsRightReal_fx = NULL;
1253 :
1254 271 : free( hBinRenConvModule->filterTapsRightImag_fx );
1255 271 : hBinRenConvModule->filterTapsRightImag_fx = NULL;
1256 :
1257 11671 : FOR( bandIdx = 0; bandIdx < ( *hBinRenderer )->conv_band; bandIdx++ )
1258 : {
1259 146130 : FOR( chIdx = 0; chIdx < ( *hBinRenderer )->nInChannels; chIdx++ )
1260 : {
1261 134730 : free( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx] );
1262 134730 : hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx] = NULL;
1263 :
1264 134730 : free( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx] );
1265 134730 : hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx] = NULL;
1266 : }
1267 :
1268 11400 : free( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx] );
1269 11400 : hBinRenConvModule->filterStatesLeftReal_fx[bandIdx] = NULL;
1270 :
1271 11400 : free( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx] );
1272 11400 : hBinRenConvModule->filterStatesLeftImag_fx[bandIdx] = NULL;
1273 : }
1274 :
1275 271 : free( hBinRenConvModule->filterStatesLeftReal_fx );
1276 271 : hBinRenConvModule->filterStatesLeftReal_fx = NULL;
1277 :
1278 271 : free( hBinRenConvModule->filterStatesLeftImag_fx );
1279 271 : hBinRenConvModule->filterStatesLeftImag_fx = NULL;
1280 :
1281 :
1282 271 : free( ( *hBinRenderer )->hBinRenConvModule );
1283 271 : ( *hBinRenderer )->hBinRenConvModule = NULL;
1284 :
1285 271 : return;
1286 : }
1287 :
1288 : /*-------------------------------------------------------------------------
1289 : * ivas_binRenderer_close()
1290 : *
1291 : * Close fastconv binaural renderer memories
1292 : *------------------------------------------------------------------------*/
1293 836 : void ivas_binRenderer_close_fx(
1294 : BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: fastconv binaural renderer handle */
1295 : )
1296 : {
1297 836 : test();
1298 836 : IF( hBinRenderer == NULL || *hBinRenderer == NULL )
1299 : {
1300 565 : return;
1301 : }
1302 :
1303 271 : IF( ( *hBinRenderer )->hBinRenConvModule != NULL )
1304 : {
1305 271 : ivas_binRenderer_convModuleClose_fx( hBinRenderer );
1306 : }
1307 :
1308 271 : IF( ( *hBinRenderer )->hReverb != NULL )
1309 : {
1310 0 : ivas_binaural_reverb_close_fx( &( ( *hBinRenderer )->hReverb ) );
1311 : }
1312 :
1313 271 : free( *hBinRenderer );
1314 271 : *hBinRenderer = NULL;
1315 :
1316 271 : return;
1317 : }
1318 :
1319 : /*-------------------------------------------------------------------------
1320 : * ivas_free_pppHrtfMem()
1321 : *
1322 : * Free fastconv binaural renderer hrtf memories
1323 : *------------------------------------------------------------------------*/
1324 1220 : static void ivas_free_pppHrtfMem_fx(
1325 : Word32 ****ppppHRIR, /*Qx*/
1326 : const Word16 dim,
1327 : const Word16 alloc_init )
1328 : {
1329 : Word16 i, j;
1330 :
1331 1220 : IF( *ppppHRIR != NULL )
1332 : {
1333 37128 : FOR( i = 0; i < BINAURAL_CONVBANDS; i++ )
1334 : {
1335 36400 : IF( alloc_init == 0 )
1336 : {
1337 294400 : FOR( j = 0; j < dim; j++ )
1338 : {
1339 271400 : free( ( *ppppHRIR )[i][j] );
1340 271400 : ( *ppppHRIR )[i][j] = NULL;
1341 : }
1342 : }
1343 36400 : free( ( *ppppHRIR )[i] );
1344 36400 : ( *ppppHRIR )[i] = NULL;
1345 : }
1346 728 : free( *ppppHRIR );
1347 728 : *ppppHRIR = NULL;
1348 : }
1349 :
1350 1220 : return;
1351 : }
1352 :
1353 : /*-------------------------------------------------------------------------
1354 : * ivas_binaural_hrtf_close()
1355 : *
1356 : * Close fastconv binaural renderer hrtf memories
1357 : *------------------------------------------------------------------------*/
1358 604 : void ivas_binaural_hrtf_close(
1359 : HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i : fastconv HRTF handle */
1360 : )
1361 : {
1362 : Word16 allocate_init_flag;
1363 :
1364 604 : test();
1365 604 : IF( hHrtfFastConv == NULL || *hHrtfFastConv == NULL )
1366 : {
1367 543 : return;
1368 : }
1369 :
1370 61 : allocate_init_flag = ( *hHrtfFastConv )->allocate_init_flag;
1371 61 : move16();
1372 :
1373 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag );
1374 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag );
1375 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag );
1376 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag );
1377 :
1378 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftBRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag );
1379 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftBRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag );
1380 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightBRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag );
1381 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightBRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag );
1382 :
1383 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_HOA3_fx, HOA3_CHANNELS, allocate_init_flag );
1384 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_HOA3_fx, HOA3_CHANNELS, allocate_init_flag );
1385 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRReal_HOA3_fx, HOA3_CHANNELS, allocate_init_flag );
1386 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRImag_HOA3_fx, HOA3_CHANNELS, allocate_init_flag );
1387 :
1388 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_HOA2_fx, HOA2_CHANNELS, allocate_init_flag );
1389 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_HOA2_fx, HOA2_CHANNELS, allocate_init_flag );
1390 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRReal_HOA2_fx, HOA2_CHANNELS, allocate_init_flag );
1391 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRImag_HOA2_fx, HOA2_CHANNELS, allocate_init_flag );
1392 :
1393 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_FOA_fx, FOA_CHANNELS, allocate_init_flag );
1394 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_FOA_fx, FOA_CHANNELS, allocate_init_flag );
1395 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRReal_FOA_fx, FOA_CHANNELS, allocate_init_flag );
1396 61 : ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->rightHRIRImag_FOA_fx, FOA_CHANNELS, allocate_init_flag );
1397 :
1398 61 : return;
1399 : }
1400 :
1401 : /*-------------------------------------------------------------------------*
1402 : * ivas_binaural_add_LFE()
1403 : *
1404 : * The functions adds the LFE to the left and right channels after binaural rendering
1405 : *-------------------------------------------------------------------------*/
1406 15180 : void ivas_binaural_add_LFE_fx(
1407 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1408 : Word16 output_frame, /* i : length of input frame */
1409 : Word32 *input_fx[], /* i : transport channels Q11*/
1410 : Word32 *output_fx[] /* o : synthesized core-coder transport channels/DirAC output Q11*/
1411 : )
1412 : {
1413 : Word16 render_lfe, idx_lfe, gain_fx, idx;
1414 :
1415 15180 : IF( st_ivas->hBinRenderer != NULL )
1416 : {
1417 160 : render_lfe = st_ivas->hBinRenderer->render_lfe;
1418 160 : move16();
1419 : }
1420 : ELSE
1421 : {
1422 15020 : render_lfe = TRUE;
1423 15020 : move16();
1424 : }
1425 :
1426 :
1427 15180 : IF( render_lfe )
1428 : {
1429 15180 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
1430 : {
1431 3060 : gain_fx = GAIN_LFE_FX;
1432 3060 : move16();
1433 : }
1434 : ELSE
1435 : {
1436 12120 : test();
1437 12120 : IF( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) )
1438 : {
1439 11960 : gain_fx = st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe_fx;
1440 11960 : move16();
1441 : }
1442 : ELSE
1443 : {
1444 160 : gain_fx = GAIN_LFE_FX;
1445 160 : move16();
1446 : }
1447 : }
1448 30210 : FOR( idx_lfe = 0; idx_lfe < st_ivas->hIntSetup.num_lfe; idx_lfe++ )
1449 : {
1450 15030 : v_multc_fixed_16( input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]], gain_fx, input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]], output_frame ); // q_input_fx - 1
1451 : /* copy LFE to left and right channels */
1452 13327030 : FOR( idx = 0; idx < output_frame; idx++ )
1453 : {
1454 13312000 : input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] = L_shl_sat( input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx], 1 ); // saturating to keep same q
1455 13312000 : move32();
1456 13312000 : output_fx[0][idx] = L_add_sat( output_fx[0][idx], input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] );
1457 13312000 : move32();
1458 13312000 : output_fx[1][idx] = L_add_sat( output_fx[1][idx], input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] );
1459 13312000 : move32();
1460 : }
1461 : }
1462 : }
1463 :
1464 15180 : return;
1465 : }
1466 :
1467 : /*-------------------------------------------------------------------------
1468 : * ivas_binRenderer()
1469 : *
1470 : * Fastconv binaural renderer main function
1471 : *-------------------------------------------------------------------------*/
1472 :
1473 136305 : void ivas_binRenderer_fx(
1474 : BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */
1475 : COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/
1476 : const Word16 numTimeSlots, /* i : number of time slots to render */
1477 : Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals Q_in*/
1478 : Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals Q_in*/
1479 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q_in*/
1480 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q_in*/
1481 : Word16 *Q_in /* i : LS signals exp */
1482 : )
1483 : {
1484 : Word16 chIdx, i, j, k;
1485 : // to be checked: feasibility with 32 bit buffers
1486 : Word64 Cldfb_RealBuffer_Binaural_64fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
1487 : Word64 Cldfb_ImagBuffer_Binaural_64fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
1488 136305 : push_wmops( "fastconv_binaural_rendering" );
1489 :
1490 : /* Compute Convolution */
1491 : /* memory reset for the binaural output */
1492 408915 : FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ )
1493 : {
1494 1360010 : FOR( k = 0; k < numTimeSlots; k++ )
1495 : {
1496 1087400 : set32_fx( Cldfb_RealBuffer_Binaural_fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX );
1497 1087400 : set32_fx( Cldfb_ImagBuffer_Binaural_fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX );
1498 1087400 : set64_fx( Cldfb_RealBuffer_Binaural_64fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX );
1499 1087400 : set64_fx( Cldfb_ImagBuffer_Binaural_64fx[chIdx][k], 0, CLDFB_NO_CHANNELS_MAX );
1500 : }
1501 : }
1502 :
1503 : /* Head rotation in HOA3 or CICPx */
1504 136305 : test();
1505 136305 : test();
1506 136305 : IF( hCombinedOrientationData != NULL && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] && hBinRenderer->rotInCldfb )
1507 : {
1508 62520 : IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 )
1509 : {
1510 : /* Rotation in SHD (HOA3) */
1511 54520 : IF( EQ_16( hCombinedOrientationData->shd_rot_max_order, -1 ) )
1512 : {
1513 18520 : rotateFrame_shd_cldfb( RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, 3 );
1514 18520 : *Q_in = sub( *Q_in, 1 ); //( Q_in + 14 - 15 )
1515 18520 : move16();
1516 : }
1517 36000 : ELSE IF( hCombinedOrientationData->shd_rot_max_order > 0 )
1518 : {
1519 0 : rotateFrame_shd_cldfb( RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, hCombinedOrientationData->shd_rot_max_order );
1520 0 : *Q_in = sub( *Q_in, 1 ); //( Q_in + 14 - 15 )
1521 0 : move16();
1522 : }
1523 : }
1524 : ELSE
1525 : {
1526 : /* Rotation in SD (CICPx) */
1527 8000 : rotateFrame_sd_cldfb_fixed( hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], RealBuffer_fx, ImagBuffer_fx,
1528 8000 : hBinRenderer->hInputSetup, hBinRenderer->hEFAPdata, numTimeSlots, hBinRenderer->conv_band );
1529 : }
1530 : }
1531 :
1532 : /* HOA decoding to CICP19 if needed*/
1533 136305 : test();
1534 136305 : IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && NE_16( hBinRenderer->nInChannels, 16 ) )
1535 : {
1536 28000 : ivas_sba2mc_cldfb_fixed( *( hBinRenderer->hInputSetup ), RealBuffer_fx, ImagBuffer_fx,
1537 28000 : hBinRenderer->nInChannels, hBinRenderer->conv_band, numTimeSlots, hBinRenderer->hoa_dec_mtx );
1538 : }
1539 136305 : ivas_binRenderer_filterModule_fx( Cldfb_RealBuffer_Binaural_64fx, Cldfb_ImagBuffer_Binaural_64fx, RealBuffer_fx, ImagBuffer_fx, numTimeSlots, hBinRenderer, *Q_in );
1540 :
1541 408915 : FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
1542 : {
1543 1363050 : FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
1544 : {
1545 66516840 : FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
1546 : {
1547 65426400 : Cldfb_RealBuffer_Binaural_fx[i][j][k] = W_extract_l( W_shr( Cldfb_RealBuffer_Binaural_64fx[i][j][k], 29 ) ); //(*Q_in + 29) - 29
1548 65426400 : move32();
1549 65426400 : Cldfb_ImagBuffer_Binaural_fx[i][j][k] = W_extract_l( W_shr( Cldfb_ImagBuffer_Binaural_64fx[i][j][k], 29 ) ); //(*Q_in + 29) - 29
1550 65426400 : move32();
1551 : }
1552 : }
1553 : }
1554 : /* Obtain the binaural dmx and compute the reverb */
1555 136305 : IF( hBinRenderer->hReverb != NULL )
1556 : {
1557 : Word32 reverbRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
1558 : Word32 reverbIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
1559 : Word32 inRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
1560 : Word32 inIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
1561 :
1562 0 : ivas_binaural_obtain_DMX_fx( numTimeSlots, hBinRenderer, RealBuffer_fx, ImagBuffer_fx, inRe_fx, inIm_fx );
1563 :
1564 0 : FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ )
1565 : {
1566 0 : FOR( k = 0; k < numTimeSlots; k++ )
1567 : {
1568 0 : set32_fx( reverbRe_fx[chIdx][k], 0, hBinRenderer->max_band );
1569 0 : set32_fx( reverbIm_fx[chIdx][k], 0, hBinRenderer->max_band );
1570 : }
1571 : }
1572 :
1573 0 : ivas_binaural_reverb_processSubframe_fx( hBinRenderer->hReverb, BINAURAL_CHANNELS, numTimeSlots, inRe_fx, inIm_fx, reverbRe_fx, reverbIm_fx );
1574 :
1575 0 : FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
1576 : {
1577 0 : FOR( j = 0; j < numTimeSlots; j++ )
1578 : {
1579 0 : FOR( k = 0; k < hBinRenderer->hReverb->numBins; k++ )
1580 : {
1581 0 : reverbRe_fx[i][j][k] = L_shl( reverbRe_fx[i][j][k], 1 ); //*Q_in
1582 0 : move32();
1583 0 : reverbIm_fx[i][j][k] = L_shl( reverbIm_fx[i][j][k], 1 ); //*Q_in
1584 0 : move32();
1585 : }
1586 : }
1587 : }
1588 :
1589 : /* Add the conv module and reverb module output */
1590 0 : FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ )
1591 : {
1592 0 : FOR( k = 0; k < numTimeSlots; k++ )
1593 : {
1594 : /* Combine first and second parts to generate binaural output signal with room effect */
1595 0 : v_add_32( Cldfb_RealBuffer_Binaural_fx[chIdx][k], reverbRe_fx[chIdx][k], Cldfb_RealBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band ); // Q_in
1596 0 : v_add_32( Cldfb_ImagBuffer_Binaural_fx[chIdx][k], reverbIm_fx[chIdx][k], Cldfb_ImagBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band ); // Q_in
1597 : }
1598 : }
1599 : }
1600 136305 : pop_wmops();
1601 136305 : return;
1602 : }
|