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 <math.h>
37 : #include "cnst.h"
38 : #include "prot_fx.h"
39 : #include "ivas_prot_rend_fx.h"
40 : #include "ivas_cnst.h"
41 : #include "ivas_rom_rend.h"
42 : #include "wmc_auto.h"
43 : #include "ivas_prot_fx.h"
44 : #include "ivas_rom_binaural_crend_head.h"
45 :
46 :
47 : /*-------------------------------------------------------------------------
48 : * ivas_dirac_allocate_parameters()
49 : *
50 : * Allocate and initialize DirAC parameters
51 : *-------------------------------------------------------------------------*/
52 :
53 987 : ivas_error ivas_dirac_allocate_parameters_fx(
54 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */
55 : const Word16 params_flag /* i : set of parameters flag */
56 : )
57 : {
58 : Word16 i;
59 :
60 987 : IF( EQ_16( params_flag, 1 ) )
61 : {
62 596 : IF( ( hSpatParamRendCom->azimuth = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL )
63 : {
64 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
65 : }
66 :
67 596 : IF( ( hSpatParamRendCom->elevation = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL )
68 : {
69 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
70 : }
71 :
72 596 : IF( ( hSpatParamRendCom->diffuseness_vector_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL )
73 : {
74 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
75 : }
76 :
77 596 : IF( ( hSpatParamRendCom->energy_ratio1_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL )
78 : {
79 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
80 : }
81 :
82 596 : IF( ( hSpatParamRendCom->spreadCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL )
83 : {
84 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
85 : }
86 :
87 596 : IF( ( hSpatParamRendCom->surroundingCoherence_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL )
88 : {
89 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
90 : }
91 :
92 3496 : FOR( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ )
93 : {
94 2900 : IF( ( hSpatParamRendCom->azimuth[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
95 : {
96 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
97 : }
98 2900 : set16_fx( hSpatParamRendCom->azimuth[i], 0, hSpatParamRendCom->num_freq_bands );
99 :
100 2900 : IF( ( hSpatParamRendCom->elevation[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
101 : {
102 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
103 : }
104 2900 : set16_fx( hSpatParamRendCom->elevation[i], 0, hSpatParamRendCom->num_freq_bands );
105 :
106 2900 : IF( ( hSpatParamRendCom->diffuseness_vector_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
107 : {
108 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
109 : }
110 2900 : set32_fx( hSpatParamRendCom->diffuseness_vector_fx[i], ONE_IN_Q30, hSpatParamRendCom->num_freq_bands ); // q30
111 :
112 2900 : IF( ( hSpatParamRendCom->energy_ratio1_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
113 : {
114 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
115 : }
116 2900 : set32_fx( hSpatParamRendCom->energy_ratio1_fx[i], 0, hSpatParamRendCom->num_freq_bands );
117 :
118 2900 : IF( ( hSpatParamRendCom->spreadCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
119 : {
120 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
121 : }
122 2900 : set16_fx( hSpatParamRendCom->spreadCoherence_fx[i], 0, hSpatParamRendCom->num_freq_bands );
123 :
124 2900 : IF( ( hSpatParamRendCom->surroundingCoherence_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
125 : {
126 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
127 : }
128 2900 : set16_fx( hSpatParamRendCom->surroundingCoherence_fx[i], 0, hSpatParamRendCom->num_freq_bands );
129 : }
130 : }
131 391 : ELSE IF( EQ_16( params_flag, 2 ) )
132 : {
133 391 : IF( ( hSpatParamRendCom->azimuth2 = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL )
134 : {
135 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
136 : }
137 :
138 391 : IF( ( hSpatParamRendCom->elevation2 = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL )
139 : {
140 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
141 : }
142 :
143 391 : IF( ( hSpatParamRendCom->energy_ratio2_fx = (Word32 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word32 * ) ) ) == NULL )
144 : {
145 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
146 : }
147 :
148 391 : IF( ( hSpatParamRendCom->spreadCoherence2_fx = (Word16 **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( Word16 * ) ) ) == NULL )
149 : {
150 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
151 : }
152 :
153 2449 : FOR( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ )
154 : {
155 2058 : IF( ( hSpatParamRendCom->azimuth2[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
156 : {
157 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
158 : }
159 2058 : set16_fx( hSpatParamRendCom->azimuth2[i], 0, hSpatParamRendCom->num_freq_bands );
160 :
161 2058 : IF( ( hSpatParamRendCom->elevation2[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
162 : {
163 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
164 : }
165 2058 : set16_fx( hSpatParamRendCom->elevation2[i], 0, hSpatParamRendCom->num_freq_bands );
166 :
167 2058 : IF( ( hSpatParamRendCom->energy_ratio2_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
168 : {
169 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
170 : }
171 2058 : set32_fx( hSpatParamRendCom->energy_ratio2_fx[i], 0, hSpatParamRendCom->num_freq_bands );
172 :
173 2058 : IF( ( hSpatParamRendCom->spreadCoherence2_fx[i] = (Word16 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word16 ) ) ) == NULL )
174 : {
175 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
176 : }
177 2058 : set16_fx( hSpatParamRendCom->spreadCoherence2_fx[i], 0, hSpatParamRendCom->num_freq_bands );
178 : }
179 : }
180 :
181 987 : return IVAS_ERR_OK;
182 : }
183 :
184 :
185 : /*-------------------------------------------------------------------------
186 : * ivas_spat_hSpatParamRendCom_config()
187 : *
188 : *
189 : *-------------------------------------------------------------------------*/
190 :
191 4289 : ivas_error ivas_spat_hSpatParamRendCom_config_fx(
192 : SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: IVAS decoder structure */
193 : const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */
194 : const Word16 dec_param_estim_flag,
195 : const IVAS_FORMAT ivas_format,
196 : const MC_MODE mc_mode,
197 : const Word32 output_Fs,
198 : const Word16 hodirac_flag,
199 : const Word16 masa_ext_rend_flag )
200 : {
201 : ivas_error error;
202 : Word16 map_idx;
203 : DIRAC_CONFIG_FLAG flag_config;
204 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
205 :
206 4289 : IF( EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) )
207 1019 : flag_config = DIRAC_RECONFIGURE;
208 : ELSE
209 3270 : flag_config = flag_config_inp;
210 4289 : move32();
211 4289 : error = IVAS_ERR_OK;
212 4289 : move32();
213 :
214 4289 : hSpatParamRendCom = NULL;
215 :
216 4289 : IF( EQ_32( flag_config, DIRAC_RECONFIGURE ) )
217 : {
218 3791 : hSpatParamRendCom = *hSpatParamRendCom_out;
219 : }
220 498 : ELSE IF( flag_config == DIRAC_OPEN )
221 : {
222 : /*-----------------------------------------------------------------*
223 : * prepare library opening
224 : *-----------------------------------------------------------------*/
225 :
226 498 : IF( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL )
227 : {
228 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC meta\n" ) );
229 : }
230 :
231 498 : *hSpatParamRendCom_out = hSpatParamRendCom;
232 : }
233 :
234 4289 : IF( EQ_32( flag_config, DIRAC_OPEN ) )
235 : {
236 : /* hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */
237 498 : hSpatParamRendCom->slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX) in Q31 */ ) ); // Q0+Q31-Q31=>Q0
238 498 : move16();
239 498 : set16_fx( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
240 498 : set16_fx( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
241 498 : hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
242 498 : move16();
243 498 : hSpatParamRendCom->subframes_rendered = 0;
244 498 : move16();
245 498 : hSpatParamRendCom->slots_rendered = 0;
246 498 : move16();
247 498 : hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
248 498 : move16();
249 : /* hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */
250 498 : hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); // 0+31-31=>0
251 498 : move16();
252 498 : hSpatParamRendCom->numSimultaneousDirections = 0;
253 498 : move16();
254 498 : hSpatParamRendCom->numParametricDirections = 0;
255 498 : move16();
256 498 : hSpatParamRendCom->numIsmDirections = 0;
257 498 : move16();
258 : }
259 :
260 : /*-----------------------------------------------------------------*
261 : * set input parameters
262 : *-----------------------------------------------------------------*/
263 :
264 4289 : test();
265 4289 : test();
266 4289 : IF( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) && EQ_32( flag_config, DIRAC_RECONFIGURE ) )
267 : {
268 1019 : test();
269 1019 : test();
270 1019 : IF( hodirac_flag && hSpatParamRendCom->azimuth2 == NULL )
271 : {
272 86 : IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ), IVAS_ERR_OK ) )
273 : {
274 0 : return error;
275 : }
276 : }
277 933 : ELSE IF( !hodirac_flag && hSpatParamRendCom->azimuth2 != NULL )
278 : {
279 79 : ivas_dirac_deallocate_parameters_fx( hSpatParamRendCom, 2 );
280 : }
281 : }
282 :
283 4289 : IF( flag_config == DIRAC_OPEN )
284 : {
285 498 : hSpatParamRendCom->dirac_md_buffer_length = 0;
286 498 : move16();
287 498 : hSpatParamRendCom->dirac_bs_md_write_idx = 0;
288 498 : move16();
289 498 : hSpatParamRendCom->dirac_read_idx = 0;
290 498 : move16();
291 498 : test();
292 498 : test();
293 498 : IF( EQ_32( mc_mode, MC_MODE_MCMASA ) || EQ_16( masa_ext_rend_flag, 1 ) )
294 : {
295 240 : hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES;
296 240 : move16();
297 :
298 240 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
299 1200 : FOR( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ )
300 : {
301 960 : hSpatParamRendCom->render_to_md_map[map_idx] = map_idx;
302 960 : move16();
303 : }
304 : }
305 258 : ELSE IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) )
306 : {
307 137 : hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR;
308 137 : move16();
309 137 : hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR;
310 137 : move16();
311 :
312 137 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
313 685 : FOR( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ )
314 : {
315 548 : hSpatParamRendCom->render_to_md_map[map_idx] = map_idx;
316 548 : move16();
317 : }
318 : }
319 : ELSE
320 : {
321 : Word16 num_slots_in_subfr, tmp;
322 121 : tmp = 1;
323 121 : move16();
324 121 : IF( dec_param_estim_flag )
325 50 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
326 : ELSE
327 71 : num_slots_in_subfr = 1;
328 121 : move16();
329 121 : hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR;
330 121 : move16();
331 121 : hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR;
332 121 : move16();
333 121 : hSpatParamRendCom->dirac_read_idx = 0;
334 121 : move16();
335 :
336 121 : set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME );
337 :
338 121 : if ( EQ_16( num_slots_in_subfr, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) )
339 : {
340 50 : tmp = 2;
341 50 : move16();
342 : }
343 :
344 1205 : FOR( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ )
345 : {
346 1084 : hSpatParamRendCom->render_to_md_map[map_idx] = add( hSpatParamRendCom->dirac_read_idx, shr( map_idx, tmp ) );
347 1084 : move16();
348 : }
349 : }
350 :
351 498 : IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ), IVAS_ERR_OK ) )
352 : {
353 0 : return error;
354 : }
355 :
356 498 : test();
357 498 : test();
358 498 : test();
359 498 : test();
360 498 : IF( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || ( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) && hodirac_flag ) )
361 : {
362 207 : IF( NE_32( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ), IVAS_ERR_OK ) )
363 : {
364 0 : return error;
365 : }
366 : }
367 : ELSE
368 : {
369 291 : hSpatParamRendCom->azimuth2 = NULL;
370 291 : hSpatParamRendCom->elevation2 = NULL;
371 291 : hSpatParamRendCom->energy_ratio2_fx = NULL;
372 291 : hSpatParamRendCom->spreadCoherence2_fx = NULL;
373 : }
374 : }
375 :
376 4289 : return error;
377 : }
378 :
379 :
380 : /*-------------------------------------------------------------------------
381 : * ivas_spat_hSpatParamRendCom_close()
382 : *
383 : *
384 : *-------------------------------------------------------------------------*/
385 :
386 1074 : void ivas_spat_hSpatParamRendCom_close_fx(
387 : SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out )
388 : {
389 1074 : test();
390 1074 : IF( hSpatParamRendCom_out == NULL || *hSpatParamRendCom_out == NULL )
391 : {
392 576 : return;
393 : }
394 498 : ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 1 );
395 498 : ivas_dirac_deallocate_parameters_fx( *hSpatParamRendCom_out, 2 );
396 :
397 498 : free( *hSpatParamRendCom_out );
398 498 : *hSpatParamRendCom_out = NULL;
399 :
400 498 : return;
401 : }
402 :
403 :
404 : /*-------------------------------------------------------------------------
405 : * ivas_dirac_rend_close()
406 : *
407 : *
408 : *-------------------------------------------------------------------------*/
409 :
410 3168 : void ivas_dirac_rend_close_fx(
411 : DIRAC_REND_HANDLE *hDirACRend_out )
412 : {
413 : Word16 i, j;
414 : DIRAC_REND_HANDLE hDirACRend;
415 :
416 3168 : test();
417 3168 : IF( hDirACRend_out == NULL || *hDirACRend_out == NULL )
418 : {
419 2781 : return;
420 : }
421 :
422 387 : hDirACRend = *hDirACRend_out;
423 :
424 : /* close Output synthesis sub-module */
425 387 : ivas_dirac_dec_output_synthesis_close_fx( hDirACRend );
426 :
427 : /* close Decorrelator sub-module */
428 387 : IF( hDirACRend->proto_signal_decorr_on )
429 : {
430 326 : ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state );
431 : }
432 :
433 : /* Params */
434 :
435 : /* free frequency axis buffer */
436 387 : IF( hDirACRend->frequency_axis_fx != NULL )
437 : {
438 387 : free( hDirACRend->frequency_axis_fx );
439 387 : hDirACRend->frequency_axis_fx = NULL;
440 : }
441 :
442 387 : IF( hDirACRend->diffuse_response_function_fx != NULL )
443 : {
444 387 : free( hDirACRend->diffuse_response_function_fx );
445 387 : hDirACRend->diffuse_response_function_fx = NULL;
446 : }
447 :
448 387 : IF( hDirACRend->hoa_encoder_fx != NULL )
449 : {
450 15 : free( hDirACRend->hoa_encoder_fx );
451 15 : hDirACRend->hoa_encoder_fx = NULL;
452 : }
453 :
454 387 : IF( hDirACRend->hoa_encoder_fx != NULL )
455 : {
456 0 : free( hDirACRend->hoa_encoder_fx );
457 0 : hDirACRend->hoa_encoder_fx = NULL;
458 : }
459 :
460 : /* prototype indexing */
461 387 : IF( hDirACRend->proto_index_dir != NULL )
462 : {
463 387 : free( hDirACRend->proto_index_dir );
464 387 : hDirACRend->proto_index_dir = NULL;
465 : }
466 :
467 387 : IF( hDirACRend->proto_index_diff != NULL )
468 : {
469 387 : free( hDirACRend->proto_index_diff );
470 387 : hDirACRend->proto_index_dir = NULL;
471 : }
472 :
473 : /* States */
474 :
475 : /* free prototype signal buffers */
476 387 : IF( hDirACRend->proto_frame_f_fx != NULL )
477 : {
478 208 : free( hDirACRend->proto_frame_f_fx );
479 208 : hDirACRend->proto_frame_f_fx = NULL;
480 : }
481 :
482 :
483 1548 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
484 : {
485 38313 : FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ )
486 : {
487 37152 : IF( hDirACRend->buffer_intensity_real_fx[i][j] != NULL )
488 : {
489 12384 : free( hDirACRend->buffer_intensity_real_fx[i][j] );
490 12384 : hDirACRend->buffer_intensity_real_fx[i][j] = NULL;
491 : }
492 : }
493 : }
494 387 : IF( hDirACRend->buffer_energy_fx != NULL )
495 : {
496 129 : free( hDirACRend->buffer_energy_fx );
497 129 : hDirACRend->buffer_energy_fx = NULL;
498 : }
499 :
500 387 : IF( hDirACRend->masa_stereo_type_detect != NULL )
501 : {
502 66 : free( hDirACRend->masa_stereo_type_detect );
503 66 : hDirACRend->masa_stereo_type_detect = NULL;
504 : }
505 :
506 387 : ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) );
507 :
508 387 : free( *hDirACRend_out );
509 387 : *hDirACRend_out = NULL;
510 :
511 387 : return;
512 : }
513 :
514 :
515 : /*-------------------------------------------------------------------------
516 : * ivas_dirac_deallocate_parameters()
517 : *
518 : * Deallocate DirAC parameters
519 : *-------------------------------------------------------------------------*/
520 :
521 1271 : void ivas_dirac_deallocate_parameters_fx(
522 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */
523 : const Word16 params_flag /* i : set of parameters flag */
524 : )
525 : {
526 : Word16 i;
527 : Word16 md_buffer_length;
528 :
529 1271 : IF( hSpatParamRendCom == NULL )
530 : {
531 0 : return;
532 : }
533 :
534 1271 : md_buffer_length = hSpatParamRendCom->dirac_md_buffer_length;
535 1271 : move16();
536 :
537 1271 : IF( EQ_16( params_flag, 1 ) )
538 : {
539 596 : IF( hSpatParamRendCom->azimuth != NULL )
540 : {
541 3496 : FOR( i = 0; i < md_buffer_length; i++ )
542 : {
543 2900 : IF( hSpatParamRendCom->azimuth[i] != NULL )
544 : {
545 2900 : free( hSpatParamRendCom->azimuth[i] );
546 2900 : hSpatParamRendCom->azimuth[i] = NULL;
547 : }
548 : }
549 :
550 596 : free( hSpatParamRendCom->azimuth );
551 596 : hSpatParamRendCom->azimuth = NULL;
552 : }
553 :
554 596 : IF( hSpatParamRendCom->elevation != NULL )
555 : {
556 3496 : FOR( i = 0; i < md_buffer_length; i++ )
557 : {
558 2900 : IF( hSpatParamRendCom->elevation[i] != NULL )
559 : {
560 2900 : free( hSpatParamRendCom->elevation[i] );
561 2900 : hSpatParamRendCom->elevation[i] = NULL;
562 : }
563 : }
564 :
565 596 : free( hSpatParamRendCom->elevation );
566 596 : hSpatParamRendCom->elevation = NULL;
567 : }
568 :
569 596 : IF( hSpatParamRendCom->energy_ratio1_fx != NULL )
570 : {
571 3496 : FOR( i = 0; i < md_buffer_length; i++ )
572 : {
573 2900 : IF( hSpatParamRendCom->energy_ratio1_fx[i] != NULL )
574 : {
575 2900 : free( hSpatParamRendCom->energy_ratio1_fx[i] );
576 2900 : hSpatParamRendCom->energy_ratio1_fx[i] = NULL;
577 : }
578 : }
579 596 : free( hSpatParamRendCom->energy_ratio1_fx );
580 596 : hSpatParamRendCom->energy_ratio1_fx = NULL;
581 : }
582 :
583 596 : IF( hSpatParamRendCom->diffuseness_vector_fx != NULL )
584 : {
585 3496 : FOR( i = 0; i < md_buffer_length; i++ )
586 : {
587 2900 : IF( hSpatParamRendCom->diffuseness_vector_fx[i] != NULL )
588 : {
589 2900 : free( hSpatParamRendCom->diffuseness_vector_fx[i] );
590 2900 : hSpatParamRendCom->diffuseness_vector_fx[i] = NULL;
591 : }
592 : }
593 :
594 596 : free( hSpatParamRendCom->diffuseness_vector_fx );
595 596 : hSpatParamRendCom->diffuseness_vector_fx = NULL;
596 : }
597 :
598 596 : IF( hSpatParamRendCom->spreadCoherence_fx != NULL )
599 : {
600 3496 : FOR( i = 0; i < md_buffer_length; i++ )
601 : {
602 2900 : IF( hSpatParamRendCom->spreadCoherence_fx[i] != NULL )
603 : {
604 2900 : free( hSpatParamRendCom->spreadCoherence_fx[i] );
605 2900 : hSpatParamRendCom->spreadCoherence_fx[i] = NULL;
606 : }
607 : }
608 596 : free( hSpatParamRendCom->spreadCoherence_fx );
609 596 : hSpatParamRendCom->spreadCoherence_fx = NULL;
610 : }
611 :
612 596 : IF( hSpatParamRendCom->surroundingCoherence_fx != NULL )
613 : {
614 3496 : FOR( i = 0; i < md_buffer_length; i++ )
615 : {
616 2900 : IF( hSpatParamRendCom->surroundingCoherence_fx[i] != NULL )
617 : {
618 2900 : free( hSpatParamRendCom->surroundingCoherence_fx[i] );
619 2900 : hSpatParamRendCom->surroundingCoherence_fx[i] = NULL;
620 : }
621 : }
622 596 : free( hSpatParamRendCom->surroundingCoherence_fx );
623 596 : hSpatParamRendCom->surroundingCoherence_fx = NULL;
624 : }
625 : }
626 675 : ELSE IF( EQ_16( params_flag, 2 ) )
627 : {
628 675 : IF( hSpatParamRendCom->azimuth2 != NULL )
629 : {
630 2449 : FOR( i = 0; i < md_buffer_length; i++ )
631 : {
632 2058 : IF( hSpatParamRendCom->azimuth2[i] != NULL )
633 : {
634 2058 : free( hSpatParamRendCom->azimuth2[i] );
635 2058 : hSpatParamRendCom->azimuth2[i] = NULL;
636 : }
637 : }
638 391 : free( hSpatParamRendCom->azimuth2 );
639 391 : hSpatParamRendCom->azimuth2 = NULL;
640 : }
641 :
642 675 : IF( hSpatParamRendCom->elevation2 != NULL )
643 : {
644 2449 : FOR( i = 0; i < md_buffer_length; i++ )
645 : {
646 2058 : IF( hSpatParamRendCom->elevation2[i] != NULL )
647 : {
648 2058 : free( hSpatParamRendCom->elevation2[i] );
649 2058 : hSpatParamRendCom->elevation2[i] = NULL;
650 : }
651 : }
652 391 : free( hSpatParamRendCom->elevation2 );
653 391 : hSpatParamRendCom->elevation2 = NULL;
654 : }
655 :
656 675 : IF( hSpatParamRendCom->energy_ratio2_fx != NULL )
657 : {
658 2449 : FOR( i = 0; i < md_buffer_length; i++ )
659 : {
660 2058 : IF( hSpatParamRendCom->energy_ratio2_fx[i] != NULL )
661 : {
662 2058 : free( hSpatParamRendCom->energy_ratio2_fx[i] );
663 2058 : hSpatParamRendCom->energy_ratio2_fx[i] = NULL;
664 : }
665 : }
666 391 : free( hSpatParamRendCom->energy_ratio2_fx );
667 391 : hSpatParamRendCom->energy_ratio2_fx = NULL;
668 : }
669 :
670 675 : IF( hSpatParamRendCom->spreadCoherence2_fx != NULL )
671 : {
672 2449 : FOR( i = 0; i < md_buffer_length; i++ )
673 : {
674 2058 : IF( hSpatParamRendCom->spreadCoherence2_fx[i] != NULL )
675 : {
676 2058 : free( hSpatParamRendCom->spreadCoherence2_fx[i] );
677 2058 : hSpatParamRendCom->spreadCoherence2_fx[i] = NULL;
678 : }
679 : }
680 391 : free( hSpatParamRendCom->spreadCoherence2_fx );
681 391 : hSpatParamRendCom->spreadCoherence2_fx = NULL;
682 : }
683 : }
684 :
685 1271 : return;
686 : }
687 :
688 :
689 : /*-------------------------------------------------------------------------
690 : * ivas_dirac_alloc_mem()
691 : *
692 : * Allocate stack memory for DirAC renderer
693 : *------------------------------------------------------------------------*/
694 :
695 2171 : ivas_error ivas_dirac_alloc_mem_fx(
696 : DIRAC_REND_HANDLE hDirACRend,
697 : const RENDERER_TYPE renderer_type,
698 : const Word16 num_freq_bands,
699 : DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem,
700 : const Word16 hodirac_flag )
701 : {
702 : Word16 num_freq_bands_diff, size;
703 : Word16 size_ho;
704 : Word16 size_pf;
705 : Word16 num_outputs_dir, num_outputs_diff;
706 : Word16 num_protos_dir;
707 :
708 2171 : num_protos_dir = hDirACRend->num_protos_dir;
709 2171 : move16();
710 :
711 2171 : num_freq_bands_diff = hDirACRend->h_output_synthesis_psd_params.max_band_decorr;
712 2171 : move16();
713 :
714 2171 : num_outputs_dir = hDirACRend->num_outputs_dir;
715 2171 : move16();
716 2171 : num_outputs_diff = hDirACRend->num_outputs_diff;
717 2171 : move16();
718 :
719 2171 : size = imult1616( num_freq_bands, num_outputs_dir );
720 2171 : IF( hodirac_flag )
721 : {
722 112 : size_ho = imult1616( size, DIRAC_HO_NUMSECTORS );
723 112 : size_pf = imult1616( num_freq_bands, DIRAC_HO_NUMSECTORS );
724 : }
725 : ELSE
726 : {
727 2059 : size_ho = size;
728 2059 : move16();
729 2059 : size_pf = num_freq_bands;
730 2059 : move16();
731 : }
732 :
733 : /* PSD related buffers */
734 2171 : hDirAC_mem->cy_auto_dir_smooth_fx = NULL;
735 2171 : hDirAC_mem->proto_power_smooth_fx = NULL;
736 2171 : hDirAC_mem->proto_power_diff_smooth_fx = NULL;
737 2171 : hDirAC_mem->direct_responses_square_fx = NULL;
738 2171 : hDirAC_mem->frame_dec_f_fx = NULL;
739 2171 : IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
740 : {
741 1358 : IF( ( hDirAC_mem->cy_auto_dir_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL )
742 : {
743 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
744 : }
745 1358 : set_zero_fx( hDirAC_mem->cy_auto_dir_smooth_fx, size );
746 1358 : hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len = size;
747 1358 : move16();
748 :
749 1358 : IF( ( hDirAC_mem->proto_power_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL )
750 : {
751 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
752 : }
753 1358 : set_zero_fx( hDirAC_mem->proto_power_smooth_fx, size );
754 1358 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len = size;
755 1358 : move16();
756 :
757 1358 : IF( ( hDirAC_mem->proto_power_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL )
758 : {
759 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
760 : }
761 1358 : set_zero_fx( hDirAC_mem->proto_power_diff_smooth_fx, size );
762 1358 : hDirAC_mem->proto_power_diff_smooth_len = size;
763 1358 : move16();
764 1358 : hDirAC_mem->proto_power_diff_smooth_q = Q31;
765 1358 : move16();
766 :
767 1358 : IF( ( hDirAC_mem->direct_responses_square_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL )
768 : {
769 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
770 : }
771 1358 : set32_fx( hDirAC_mem->direct_responses_square_fx, 0, size );
772 1358 : test();
773 1358 : test();
774 1358 : test();
775 1358 : IF( hDirACRend->proto_signal_decorr_on && ( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) ) )
776 : {
777 1200 : IF( ( hDirAC_mem->frame_dec_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL )
778 : {
779 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
780 : }
781 1200 : set_zero_fx( hDirAC_mem->frame_dec_f_fx, 2 * num_outputs_diff * num_freq_bands );
782 1200 : hDirAC_mem->frame_dec_f_len = imult1616( imult1616( 2, num_outputs_diff ), num_freq_bands );
783 : }
784 : }
785 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx = hDirAC_mem->proto_power_smooth_fx;
786 : #ifdef FIX_867_CLDFB_NRG_SCALE
787 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = Q31;
788 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = Q31;
789 2171 : move16();
790 2171 : move16();
791 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = Q31;
792 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = Q31;
793 2171 : move16();
794 2171 : move16();
795 : #else
796 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = Q31;
797 : move16();
798 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = Q31;
799 : move16();
800 : #endif
801 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx = hDirAC_mem->proto_power_diff_smooth_fx;
802 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirAC_mem->proto_power_diff_smooth_q;
803 2171 : move16();
804 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len = hDirAC_mem->proto_power_diff_smooth_len;
805 2171 : move16();
806 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = Q31;
807 2171 : move16();
808 2171 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = Q31;
809 2171 : move16();
810 2171 : hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx = hDirAC_mem->cy_auto_dir_smooth_fx;
811 2171 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = 0;
812 2171 : move16();
813 2171 : hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx = hDirAC_mem->direct_responses_square_fx;
814 2171 : hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31;
815 2171 : move16();
816 2171 : move16();
817 :
818 : /* Target and smoothed nrg factors/gains */
819 2171 : IF( ( hDirAC_mem->cy_cross_dir_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size_ho ) ) == NULL )
820 : {
821 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
822 : }
823 2171 : hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len = size_ho;
824 2171 : move16();
825 2171 : set_zero_fx( hDirAC_mem->cy_cross_dir_smooth_fx, size_ho );
826 :
827 2171 : IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
828 : {
829 1358 : IF( ( hDirAC_mem->cy_auto_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL )
830 : {
831 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
832 : }
833 1358 : set_zero_fx( hDirAC_mem->cy_auto_diff_smooth_fx, size );
834 1358 : hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = size;
835 1358 : move16();
836 : }
837 : ELSE
838 : {
839 813 : IF( ( hDirAC_mem->cy_auto_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL )
840 : {
841 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
842 : }
843 813 : set_zero_fx( hDirAC_mem->cy_auto_diff_smooth_fx, imult1616( num_outputs_diff, num_freq_bands_diff ) );
844 813 : hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = imult1616( num_outputs_diff, num_freq_bands_diff );
845 : }
846 2171 : hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx = hDirAC_mem->cy_cross_dir_smooth_fx;
847 2171 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = 31;
848 2171 : move16();
849 2171 : hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx = hDirAC_mem->cy_auto_diff_smooth_fx;
850 2171 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = 0;
851 2171 : move16();
852 :
853 : /*Responses (gains/factors)*/
854 2171 : IF( ( hDirAC_mem->direct_responses_fx = (Word32 *) malloc( sizeof( Word32 ) * size_ho ) ) == NULL )
855 : {
856 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
857 : }
858 2171 : set32_fx( hDirAC_mem->direct_responses_fx, 0, size );
859 :
860 :
861 2171 : hDirACRend->h_output_synthesis_psd_state.direct_responses_fx = hDirAC_mem->direct_responses_fx;
862 2171 : hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31;
863 2171 : move16();
864 :
865 : /* Prototypes */
866 2171 : hDirAC_mem->proto_direct_buffer_f_fx = NULL;
867 2171 : hDirAC_mem->proto_diffuse_buffer_f_fx = NULL;
868 2171 : test();
869 2171 : test();
870 2171 : IF( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) )
871 : {
872 2171 : IF( ( hDirAC_mem->proto_direct_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL )
873 : {
874 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
875 : }
876 2171 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len = imult1616( imult1616( 2 * MAX_PARAM_SPATIAL_SUBFRAMES, num_protos_dir ), num_freq_bands );
877 2171 : set_zero_fx( hDirAC_mem->proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len );
878 2171 : move16();
879 2171 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = Q31;
880 2171 : move16();
881 :
882 2171 : IF( hDirACRend->proto_signal_decorr_on )
883 : {
884 2013 : IF( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
885 : {
886 412 : IF( ( hDirAC_mem->proto_diffuse_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL )
887 : {
888 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
889 : }
890 412 : hDirAC_mem->proto_diffuse_buffer_f_len = imult1616( 2 * MAX_PARAM_SPATIAL_SUBFRAMES, size );
891 412 : move16();
892 : }
893 : ELSE
894 : {
895 1601 : IF( ( hDirAC_mem->proto_diffuse_buffer_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL )
896 : {
897 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
898 : }
899 1601 : hDirAC_mem->proto_diffuse_buffer_f_len = imult1616( imult1616( 2 * MAX_PARAM_SPATIAL_SUBFRAMES, num_outputs_diff ), num_freq_bands );
900 : }
901 2013 : set_zero_fx( hDirAC_mem->proto_diffuse_buffer_f_fx, hDirAC_mem->proto_diffuse_buffer_f_len );
902 : }
903 : }
904 2171 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx = hDirAC_mem->proto_direct_buffer_f_fx;
905 2171 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx = hDirAC_mem->proto_diffuse_buffer_f_fx;
906 2171 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len = hDirAC_mem->proto_diffuse_buffer_f_len;
907 2171 : move16();
908 2171 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = Q31;
909 2171 : move16();
910 :
911 : /* Gains/power factors*/
912 2171 : hDirAC_mem->direct_power_factor_fx = NULL;
913 2171 : hDirAC_mem->diffuse_power_factor_fx = NULL;
914 :
915 2171 : test();
916 2171 : test();
917 2171 : IF( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) )
918 : {
919 2171 : IF( ( hDirAC_mem->direct_power_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * size_pf ) ) == NULL )
920 : {
921 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
922 : }
923 2171 : IF( ( hDirAC_mem->diffuse_power_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * size_pf ) ) == NULL )
924 : {
925 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
926 : }
927 : }
928 :
929 2171 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx = hDirAC_mem->direct_power_factor_fx;
930 2171 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx = hDirAC_mem->diffuse_power_factor_fx;
931 2171 : hDirACRend->h_output_synthesis_psd_state.diff_dir_power_factor_len = size_pf;
932 2171 : set_zero_fx( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, size_pf );
933 2171 : set_zero_fx( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, size_pf );
934 2171 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31;
935 2171 : move16();
936 2171 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31;
937 2171 : move16();
938 :
939 2171 : hDirAC_mem->reference_power_fx = NULL;
940 2171 : hDirAC_mem->onset_filter_fx = NULL;
941 2171 : IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
942 : {
943 1358 : test();
944 1358 : test();
945 1358 : IF( NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) )
946 : {
947 1358 : IF( ( hDirAC_mem->reference_power_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_freq_bands ) ) == NULL )
948 : {
949 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
950 : }
951 :
952 1358 : hDirAC_mem->reference_power_len = imult1616( 2, num_freq_bands );
953 1358 : move16();
954 : #ifdef FIX_867_CLDFB_NRG_SCALE
955 1358 : hDirAC_mem->reference_power_q[0] = Q31;
956 1358 : hDirAC_mem->reference_power_q[1] = Q31;
957 1358 : move16();
958 1358 : move16();
959 1358 : hDirAC_mem->reference_power_smooth_q[0] = Q31;
960 1358 : hDirAC_mem->reference_power_smooth_q[1] = Q31;
961 1358 : move16();
962 1358 : move16();
963 : #else
964 : hDirAC_mem->reference_power_q = Q31;
965 : move16();
966 : hDirAC_mem->reference_power_smooth_q = Q31;
967 : move16();
968 : #endif
969 1358 : IF( hDirACRend->proto_signal_decorr_on )
970 : {
971 1200 : IF( ( hDirAC_mem->onset_filter_fx = (Word32 *) malloc( sizeof( Word32 ) * num_outputs_diff * num_freq_bands ) ) == NULL )
972 : {
973 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
974 : }
975 1200 : set_zero_fx( hDirAC_mem->onset_filter_fx, imult1616( num_outputs_diff, num_freq_bands ) );
976 : }
977 : }
978 : }
979 : ELSE
980 : {
981 813 : IF( GT_16( num_protos_dir, 2 ) )
982 : {
983 804 : IF( ( hDirAC_mem->reference_power_fx = (Word32 *) malloc( sizeof( Word32 ) * 5 * num_freq_bands ) ) == NULL )
984 : {
985 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
986 : }
987 :
988 804 : hDirAC_mem->reference_power_len = imult1616( 5, num_freq_bands );
989 804 : set16_fx( hDirAC_mem->reference_power_q, Q31, 2 );
990 : }
991 :
992 813 : IF( hDirACRend->proto_signal_decorr_on )
993 : {
994 813 : IF( ( hDirAC_mem->onset_filter_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * num_freq_bands ) ) == NULL )
995 : {
996 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) );
997 : }
998 813 : set_zero_fx( hDirAC_mem->onset_filter_fx, imult1616( 2, num_freq_bands ) );
999 : }
1000 : }
1001 :
1002 2171 : return IVAS_ERR_OK;
1003 : }
1004 :
1005 :
1006 : /*-------------------------------------------------------------------------
1007 : * ivas_dirac_free_mem()
1008 : *
1009 : *
1010 : *-------------------------------------------------------------------------*/
1011 :
1012 2171 : void ivas_dirac_free_mem_fx(
1013 : DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem )
1014 : {
1015 2171 : IF( hDirAC_mem->cy_auto_dir_smooth_fx != NULL )
1016 : {
1017 1358 : free( hDirAC_mem->cy_auto_dir_smooth_fx );
1018 : }
1019 2171 : IF( hDirAC_mem->proto_power_smooth_fx != NULL )
1020 : {
1021 1358 : free( hDirAC_mem->proto_power_smooth_fx );
1022 : }
1023 2171 : IF( hDirAC_mem->proto_power_diff_smooth_fx != NULL )
1024 : {
1025 1358 : free( hDirAC_mem->proto_power_diff_smooth_fx );
1026 : }
1027 2171 : IF( hDirAC_mem->direct_responses_square_fx != NULL )
1028 : {
1029 1358 : free( hDirAC_mem->direct_responses_square_fx );
1030 : }
1031 2171 : IF( hDirAC_mem->frame_dec_f_fx != NULL )
1032 : {
1033 1200 : free( hDirAC_mem->frame_dec_f_fx );
1034 : }
1035 2171 : IF( hDirAC_mem->cy_cross_dir_smooth_fx != NULL )
1036 : {
1037 2171 : free( hDirAC_mem->cy_cross_dir_smooth_fx );
1038 : }
1039 2171 : IF( hDirAC_mem->cy_auto_diff_smooth_fx != NULL )
1040 : {
1041 2171 : free( hDirAC_mem->cy_auto_diff_smooth_fx );
1042 : }
1043 2171 : IF( hDirAC_mem->direct_responses_fx != NULL )
1044 : {
1045 2171 : free( hDirAC_mem->direct_responses_fx );
1046 : }
1047 2171 : IF( hDirAC_mem->proto_direct_buffer_f_fx != NULL )
1048 : {
1049 2171 : free( hDirAC_mem->proto_direct_buffer_f_fx );
1050 : }
1051 2171 : IF( hDirAC_mem->proto_diffuse_buffer_f_fx != NULL )
1052 : {
1053 2013 : free( hDirAC_mem->proto_diffuse_buffer_f_fx );
1054 : }
1055 2171 : IF( hDirAC_mem->direct_power_factor_fx != NULL )
1056 : {
1057 2171 : free( hDirAC_mem->direct_power_factor_fx );
1058 : }
1059 2171 : IF( hDirAC_mem->diffuse_power_factor_fx != NULL )
1060 : {
1061 2171 : free( hDirAC_mem->diffuse_power_factor_fx );
1062 : }
1063 2171 : IF( hDirAC_mem->reference_power_fx != NULL )
1064 : {
1065 2162 : free( hDirAC_mem->reference_power_fx );
1066 : }
1067 2171 : IF( hDirAC_mem->onset_filter_fx != NULL )
1068 : {
1069 2013 : free( hDirAC_mem->onset_filter_fx );
1070 : }
1071 :
1072 2171 : return;
1073 : }
1074 :
1075 :
1076 : /*-------------------------------------------------------------------------
1077 : * compute_hoa_encoder_mtx()
1078 : *
1079 : *
1080 : *------------------------------------------------------------------------*/
1081 :
1082 424 : void compute_hoa_encoder_mtx_fx(
1083 : const Word32 *azimuth, /*q22*/
1084 : const Word32 *elevation, /*q22*/
1085 : Word32 *response_fx, /*q31*/
1086 : const Word16 num_responses,
1087 : const Word16 ambisonics_order )
1088 : {
1089 : Word16 k, num_sh;
1090 :
1091 424 : num_sh = ivas_sba_get_nchan_fx( ambisonics_order, 0 );
1092 3806 : FOR( k = 0; k < num_responses; k++ )
1093 : {
1094 3382 : ivas_dirac_dec_get_response_fx( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order, Q31 ); /* Q31 */
1095 : }
1096 :
1097 424 : return;
1098 : }
1099 :
1100 :
1101 : /*-------------------------------------------------------------------------
1102 : * ivas_dirac_dec_get_frequency_axis()
1103 : *
1104 : * DirAC decoding initialization
1105 : *------------------------------------------------------------------------*/
1106 :
1107 1532 : void ivas_dirac_dec_get_frequency_axis_fx(
1108 : Word16 *frequency_axis, /* Q0 */
1109 : const Word32 output_Fs,
1110 : const Word16 num_freq_bands )
1111 : {
1112 : Word16 k, const_part, scale;
1113 : /* calc cldfb frequency axis */
1114 :
1115 1532 : const_part = BASOP_Util_Divide3216_Scale( output_Fs, shl( num_freq_bands, 1 ), &scale ); // 15-(scale+31-15)=>-1-scale
1116 1532 : const_part = shr( const_part, sub( -1, scale ) ); // q(-1-scale)->q0
1117 78572 : FOR( k = 0; k < num_freq_bands; k++ )
1118 : {
1119 : /* frequency_axis[k] = ((float)k + 0.5f) * const_part; */
1120 77040 : frequency_axis[k] = add( i_mult( k, const_part ), shr( const_part, 1 ) ); /*q0*/
1121 77040 : move16();
1122 : }
1123 :
1124 1532 : return;
1125 : }
1126 :
1127 :
1128 : /*-------------------------------------------------------------------------
1129 : * initDiffuseResponses()
1130 : *
1131 : *
1132 : *-------------------------------------------------------------------------*/
1133 :
1134 2171 : void initDiffuseResponses_fx(
1135 : Word16 *diffuse_response_function_fx, /*q15*/
1136 : const Word16 num_channels,
1137 : const AUDIO_CONFIG output_config,
1138 : const IVAS_OUTPUT_SETUP hOutSetup,
1139 : const Word16 ambisonics_order,
1140 : const IVAS_FORMAT ivas_format,
1141 : Word16 *num_ele_spk_no_diffuse_rendering,
1142 : const AUDIO_CONFIG transport_config )
1143 : {
1144 : Word16 i, l, k, idx, num_horizontal_speakers;
1145 2171 : *num_ele_spk_no_diffuse_rendering = 0;
1146 :
1147 : Word16 var1, exp_var1, res;
1148 :
1149 2171 : test();
1150 2171 : test();
1151 2171 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) )
1152 : {
1153 111 : diffuse_response_function_fx[0] = MAX16B; /*1 q15*/
1154 111 : move16();
1155 111 : diffuse_response_function_fx[1] = 18918 /*inv_sqrt(3.0f) oin Q15*/;
1156 111 : move16();
1157 : }
1158 2060 : ELSE IF( !( EQ_32( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) )
1159 : {
1160 : /* set diffuse response function */
1161 835 : test();
1162 835 : test();
1163 835 : test();
1164 835 : test();
1165 835 : test();
1166 835 : test();
1167 835 : test();
1168 835 : test();
1169 835 : test();
1170 835 : test();
1171 835 : test();
1172 835 : test();
1173 835 : test();
1174 835 : test();
1175 835 : test();
1176 835 : test();
1177 835 : test();
1178 835 : test();
1179 835 : test();
1180 835 : test();
1181 835 : test();
1182 835 : IF( EQ_32( ivas_format, MC_FORMAT ) && ( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) )
1183 : {
1184 0 : num_horizontal_speakers = sub( num_channels, NUM_ELEVATED_SPEAKERS );
1185 0 : Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_horizontal_speakers ); // q15
1186 0 : set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS );
1187 0 : *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS;
1188 0 : move16();
1189 : }
1190 835 : ELSE IF( EQ_32( ivas_format, MC_FORMAT ) && ( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) )
1191 : {
1192 79 : num_horizontal_speakers = sub( num_channels, NUM_ELEVATED_SPEAKERS );
1193 79 : exp_var1 = 15;
1194 79 : move16();
1195 79 : var1 = ISqrt16( num_horizontal_speakers, &exp_var1 ); // q=15-exp_var1
1196 79 : var1 = shr( var1, negate( exp_var1 ) ); // Q15
1197 79 : set16_fx( diffuse_response_function_fx, var1, num_horizontal_speakers ); // q15
1198 79 : set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS );
1199 79 : *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS;
1200 79 : move16();
1201 : }
1202 756 : ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && EQ_16( num_channels, 5 ) )
1203 : {
1204 101 : Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_channels ); // q15
1205 : }
1206 655 : ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && EQ_16( num_channels, 7 ) )
1207 : {
1208 197 : Copy( diffuse_response_CICP14_fx, diffuse_response_function_fx, num_channels ); // q15
1209 : }
1210 458 : ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) && EQ_16( num_channels, 9 ) )
1211 : {
1212 207 : Copy( diffuse_response_CICP16_fx, diffuse_response_function_fx, num_channels ); // q15
1213 : }
1214 251 : ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1215 : {
1216 0 : IF( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( transport_config, IVAS_AUDIO_CONFIG_7_1 ) )
1217 : {
1218 : /* Detect loudspeakers with elevation */
1219 0 : num_horizontal_speakers = 0;
1220 0 : move16();
1221 0 : FOR( i = 0; i < num_channels; i++ )
1222 : {
1223 0 : IF( LE_32( L_abs( hOutSetup.ls_elevation_fx[i] /*q22*/ ), 20971520 /*5 in Q22*/ ) )
1224 : {
1225 0 : num_horizontal_speakers = add( num_horizontal_speakers, 1 );
1226 0 : diffuse_response_function_fx[i] = MAX16B; // q15
1227 0 : move16();
1228 : }
1229 : ELSE
1230 : {
1231 0 : *num_ele_spk_no_diffuse_rendering = add( *num_ele_spk_no_diffuse_rendering, 1 );
1232 0 : move16();
1233 0 : diffuse_response_function_fx[i] = 0;
1234 0 : move16();
1235 : }
1236 : }
1237 : /* Diffuse only to horizontal plane IF enough loudspeakers */
1238 0 : IF( GT_16( num_horizontal_speakers, 2 ) )
1239 : {
1240 0 : exp_var1 = 15;
1241 0 : move16();
1242 0 : Word16 num_horizontal_speakers_isq = ISqrt16( num_horizontal_speakers, &exp_var1 ); // q15-exp_var1
1243 0 : num_horizontal_speakers_isq = shr( num_horizontal_speakers_isq, negate( exp_var1 ) ); // q15
1244 0 : assert( 0 );
1245 : /*No stream hitting*/
1246 : FOR( i = 0; i < num_channels; i++ )
1247 : {
1248 : diffuse_response_function_fx[i] = mult( diffuse_response_function_fx[i], num_horizontal_speakers_isq ); // q15
1249 : move16();
1250 : }
1251 : }
1252 : ELSE
1253 : {
1254 0 : var1 = num_channels, exp_var1 = 15;
1255 0 : move16();
1256 0 : move16();
1257 0 : res = ISqrt16( var1, &exp_var1 ); // q=15-exp_var1
1258 0 : res = shr( res, negate( exp_var1 ) ); // q=15
1259 0 : set16_fx( diffuse_response_function_fx, res, num_channels ); // q15
1260 0 : *num_ele_spk_no_diffuse_rendering = 0;
1261 0 : move16();
1262 : }
1263 : }
1264 : ELSE
1265 : {
1266 0 : var1 = num_channels, exp_var1 = 15;
1267 0 : move16();
1268 0 : move16();
1269 0 : res = ISqrt16( var1, &exp_var1 ); // q=15-exp_var1
1270 0 : res = shr( res, negate( exp_var1 ) ); // q15
1271 0 : set16_fx( diffuse_response_function_fx, res, num_channels ); // q15
1272 : }
1273 : }
1274 : ELSE
1275 : {
1276 251 : var1 = num_channels, exp_var1 = 15;
1277 251 : move16();
1278 251 : move16();
1279 251 : res = ISqrt16( var1, &exp_var1 ); // q(15-exp_var1)
1280 251 : res = shr( res, negate( exp_var1 ) ); // q15
1281 251 : set16_fx( diffuse_response_function_fx, res, num_channels ); // q15
1282 : }
1283 : }
1284 : ELSE
1285 : {
1286 1225 : idx = 0;
1287 1225 : move16();
1288 : Word16 j;
1289 5698 : FOR( l = 0; l <= ambisonics_order; l++ )
1290 : {
1291 4473 : j = add( imult1616( 2, l ), 1 );
1292 21502 : FOR( k = 0; k < j; k++ )
1293 : {
1294 17029 : var1 = j, exp_var1 = 15;
1295 17029 : move16();
1296 17029 : move16();
1297 17029 : res = ISqrt16( var1, &exp_var1 ); // q(15-exp_var1)
1298 17029 : diffuse_response_function_fx[idx] = shr( res, negate( exp_var1 ) ); // q15
1299 17029 : idx = idx + 1;
1300 : }
1301 : }
1302 : }
1303 :
1304 2171 : return;
1305 : }
1306 :
1307 :
1308 : /*-------------------------------------------------------------------------
1309 : * protoSignalComputation_shd()
1310 : *
1311 : *
1312 : *-------------------------------------------------------------------------*/
1313 :
1314 884436 : void protoSignalComputation_shd_fx(
1315 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/
1316 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/
1317 : Word32 *proto_direct_buffer_f_fx, /*Q(proto_direct_buffer_f_q)*/
1318 : Word16 *proto_direct_buffer_f_q,
1319 : Word32 *proto_diffuse_buffer_f_fx, /*Q(proto_diffuse_buffer_f_q)*/
1320 : Word16 *proto_diffuse_buffer_f_q,
1321 : Word32 *reference_power_fx, /*Q(reference_power_q)*/
1322 : Word16 *reference_power_q,
1323 : const Word16 slot_index,
1324 : const Word16 num_inputs,
1325 : const Word16 num_outputs_diff,
1326 : const Word16 num_freq_bands,
1327 : Word32 *p_Rmat_fx, /* Q30 */
1328 : Word16 q_cldfb )
1329 : {
1330 : Word16 l, k;
1331 : Word16 Rmat_k[4];
1332 : Word32 *p_proto_direct_buffer_fx;
1333 : Word32 *p_proto_diffuse_buffer_fx;
1334 : Word32 re1, im1;
1335 : Word32 re2, im2;
1336 : Word32 re3, im3;
1337 : Word32 *p_k_fx[4];
1338 : Word16 min_q_shift, q_shift;
1339 : Word16 idx, idx1;
1340 :
1341 884436 : k = 0; /* to avoid compilation warning */
1342 884436 : move16();
1343 :
1344 884436 : min_q_shift = Q31;
1345 884436 : move16();
1346 884436 : q_shift = Q31;
1347 884436 : move16();
1348 :
1349 884436 : p_proto_direct_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_inputs ) ); /*proto_direct_buffer_f_q*/
1350 884436 : p_proto_diffuse_buffer_fx = proto_diffuse_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); /*proto_diffuse_buffer_f_q*/
1351 :
1352 884436 : IF( EQ_16( num_inputs, 1 ) )
1353 : {
1354 2988512 : FOR( l = 0; l < num_freq_bands; l++ )
1355 : {
1356 2939520 : p_proto_direct_buffer_fx[2 * l] = RealBuffer_fx[0][0][l]; /*Q(q_cldfb)*/
1357 2939520 : move32();
1358 2939520 : p_proto_direct_buffer_fx[2 * l + 1] = ImagBuffer_fx[0][0][l]; /*Q(q_cldfb)*/
1359 2939520 : move32();
1360 : }
1361 48992 : *proto_direct_buffer_f_q = q_cldfb;
1362 48992 : move16();
1363 : }
1364 835444 : ELSE IF( EQ_16( num_inputs, 2 ) )
1365 : {
1366 0 : IF( p_Rmat_fx != 0 )
1367 : {
1368 0 : assert( EQ_16( num_inputs, 4 ) && "This code block should never be run with num_inputs != 4!" );
1369 :
1370 0 : FOR( l = 0; l < num_freq_bands; l++ )
1371 : {
1372 0 : re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/
1373 0 : im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/
1374 :
1375 0 : re2 = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/
1376 0 : im2 = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/
1377 :
1378 0 : p_proto_direct_buffer_fx[2 * l] = re1; /*Q(q_cldfb)*/
1379 0 : move32();
1380 0 : p_proto_direct_buffer_fx[2 * l + 1] = im1; /*Q(q_cldfb)*/
1381 0 : move32();
1382 0 : p_proto_direct_buffer_fx[2 * ( num_freq_bands + l )] = L_shl( Mpy_32_32( p_Rmat_fx[0], re2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx =>Q(q_cldfb)
1383 0 : move32();
1384 0 : p_proto_direct_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_shl( Mpy_32_32( p_Rmat_fx[0], im2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx => Q(q_cldfb)
1385 0 : move32();
1386 : }
1387 0 : *proto_direct_buffer_f_q = q_cldfb;
1388 0 : move16();
1389 : }
1390 : ELSE
1391 : {
1392 0 : FOR( l = 0; l < num_freq_bands; l++ )
1393 : {
1394 0 : re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/
1395 0 : im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/
1396 :
1397 0 : p_proto_direct_buffer_fx[2 * l] = re1; /*Q(q_cldfb)*/
1398 0 : move32();
1399 0 : p_proto_direct_buffer_fx[2 * l + 1] = im1; /*Q(q_cldfb)*/
1400 0 : move32();
1401 0 : p_proto_direct_buffer_fx[2 * num_freq_bands + 2 * l] = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/
1402 0 : move32();
1403 0 : p_proto_direct_buffer_fx[2 * num_freq_bands + 2 * l + 1] = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/
1404 0 : move32();
1405 : }
1406 : }
1407 0 : *proto_direct_buffer_f_q = q_cldfb;
1408 0 : move16();
1409 : }
1410 835444 : ELSE IF( GE_16( num_inputs, 4 ) )
1411 : {
1412 835444 : p_k_fx[0] = p_proto_direct_buffer_fx; /*Q(proto_direct_buffer_f_q)*/
1413 835444 : p_k_fx[1] = p_proto_direct_buffer_fx + i_mult( 2, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/
1414 835444 : p_k_fx[2] = p_proto_direct_buffer_fx + i_mult( 4, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/
1415 835444 : p_k_fx[3] = p_proto_direct_buffer_fx + i_mult( 6, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/
1416 :
1417 835444 : Rmat_k[0] = 0;
1418 835444 : move16();
1419 835444 : Rmat_k[1] = 1;
1420 835444 : move16();
1421 835444 : Rmat_k[2] = 2;
1422 835444 : move16();
1423 835444 : Rmat_k[3] = 0;
1424 835444 : move16();
1425 :
1426 : /* calculate the minimum possible shift for the buffers RealBuffer_fx and ImagBuffer_fx */
1427 4177220 : FOR( k = 0; k < 4; k++ )
1428 : {
1429 3341776 : q_shift = L_norm_arr( RealBuffer_fx[k][0], num_freq_bands );
1430 3341776 : min_q_shift = s_min( min_q_shift, q_shift );
1431 3341776 : q_shift = L_norm_arr( ImagBuffer_fx[k][0], num_freq_bands );
1432 3341776 : min_q_shift = s_min( min_q_shift, q_shift );
1433 : }
1434 :
1435 835444 : min_q_shift = sub( min_q_shift, 4 ); /* 4 is for guard bits*/
1436 :
1437 835444 : IF( p_Rmat_fx != 0 )
1438 : {
1439 147200 : assert( EQ_16( num_inputs, 4 ) && "This code block should never be run with num_inputs != 4!" );
1440 :
1441 5779200 : FOR( l = 0; l < num_freq_bands; l++ )
1442 : {
1443 5632000 : *p_k_fx[0] = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/
1444 5632000 : move32();
1445 5632000 : reference_power_fx[l + num_freq_bands] = Mpy_32_32( *p_k_fx[0], *p_k_fx[0] ); /*2*Q(q_cldfb+min_q_shift)-31*/
1446 5632000 : move32();
1447 5632000 : p_k_fx[0]++;
1448 :
1449 5632000 : *p_k_fx[0] = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/
1450 5632000 : move32();
1451 5632000 : reference_power_fx[l + num_freq_bands] = Madd_32_32( reference_power_fx[l + num_freq_bands], *p_k_fx[0], *p_k_fx[0] ); /*2*Q(q_cldfb+min_q_shift)-31*/
1452 5632000 : move32();
1453 5632000 : p_k_fx[0]++;
1454 :
1455 5632000 : reference_power_fx[l] = L_shr( reference_power_fx[l + num_freq_bands], 1 ); /*2*Q(q_cldfb+min_q_shift)-31-1*/
1456 5632000 : move32();
1457 :
1458 5632000 : re1 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/
1459 5632000 : re2 = L_shl( RealBuffer_fx[2][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/
1460 5632000 : re3 = L_shl( RealBuffer_fx[3][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/
1461 5632000 : im1 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/
1462 5632000 : im2 = L_shl( ImagBuffer_fx[2][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/
1463 5632000 : im3 = L_shl( ImagBuffer_fx[3][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/
1464 :
1465 22528000 : FOR( k = 1; k < 4; k++ )
1466 : {
1467 16896000 : idx = i_mult( 3, Rmat_k[k] );
1468 16896000 : idx1 = add( l, i_mult( add( k, 1 ), num_freq_bands ) );
1469 :
1470 16896000 : *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[idx + 1], re1 ), p_Rmat_fx[idx + 2], re2 ), p_Rmat_fx[idx], re3 ); /*Q(30 + q_cldfb+min_q_shift-31)=>Q(q_cldfb+min_q_shift-1)*/
1471 16896000 : move32();
1472 16896000 : *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor for p_k_fx Q(q_cldfb+min_q_shift)
1473 16896000 : move32();
1474 16896000 : reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); // Q(2*(q_cldfb + min_q_shift)-31)
1475 16896000 : move32();
1476 16896000 : p_k_fx[k]++;
1477 :
1478 16896000 : *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[idx + 1], im1 ), p_Rmat_fx[idx + 2], im2 ), p_Rmat_fx[idx], im3 ); /*Q(q_cldfb+min_q_shift-1)*/
1479 16896000 : move32();
1480 16896000 : *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor Q(q_cldfb+min_q_shift)
1481 16896000 : move32();
1482 16896000 : reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); // Q(2*(q_cldfb + min_q_shift)-31)
1483 16896000 : move32();
1484 16896000 : p_k_fx[k]++;
1485 :
1486 16896000 : reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[idx1], 1 ) ); /*2*Q(q_cldfb+min_q_shift)-31-1*/
1487 16896000 : move32();
1488 : }
1489 :
1490 5632000 : *proto_direct_buffer_f_q = add( q_cldfb, min_q_shift );
1491 5632000 : move16();
1492 : #ifdef FIX_867_CLDFB_NRG_SCALE
1493 5632000 : Word16 qidx = s_min( 1, s_max( 0, sub( l, CLDFB_NO_CHANNELS_HALF - 1 ) ) );
1494 5632000 : reference_power_q[qidx] = sub( add( *proto_direct_buffer_f_q, *proto_direct_buffer_f_q ), 31 );
1495 5632000 : move16();
1496 : #else
1497 : *reference_power_q = sub( add( *proto_direct_buffer_f_q, *proto_direct_buffer_f_q ), 31 );
1498 : move16();
1499 : #endif
1500 :
1501 5632000 : Word16 shift = sub( *proto_direct_buffer_f_q, q_cldfb );
1502 22528000 : FOR( k = 1; k < 4; k++ )
1503 : {
1504 16896000 : RealBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )], shift ); // proto_direct_buffer_f_q -> q_cldfb
1505 16896000 : move32();
1506 16896000 : ImagBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1], shift ); // proto_direct_buffer_f_q -> q_cldfb
1507 16896000 : move32();
1508 : }
1509 : }
1510 : }
1511 : ELSE
1512 : {
1513 688244 : set_zero_fx( reference_power_fx, num_freq_bands );
1514 3441220 : FOR( k = 0; k < 4; k++ )
1515 : {
1516 154844816 : FOR( l = 0; l < num_freq_bands; l++ )
1517 : {
1518 152091840 : p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )] = RealBuffer_fx[k][0][l]; // q_cldfb
1519 152091840 : move32();
1520 152091840 : p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1] = ImagBuffer_fx[k][0][l]; // q_cldfb
1521 152091840 : move32();
1522 :
1523 152091840 : re1 = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
1524 152091840 : im1 = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
1525 :
1526 152091840 : reference_power_fx[l + ( k + 1 ) * num_freq_bands] = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31
1527 152091840 : move32();
1528 152091840 : reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[l + ( k + 1 ) * num_freq_bands], 1 ) ); // 2*(q_cldfb+min_q_shift)-31-1
1529 152091840 : move32();
1530 : }
1531 : }
1532 688244 : *proto_direct_buffer_f_q = q_cldfb;
1533 688244 : move16();
1534 : #ifdef FIX_867_CLDFB_NRG_SCALE
1535 688244 : reference_power_q[0] = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
1536 688244 : reference_power_q[1] = reference_power_q[0];
1537 688244 : move16();
1538 688244 : move16();
1539 : #else
1540 : *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
1541 : move16();
1542 : #endif
1543 : }
1544 :
1545 : /* Additional transport channels = planar SBA components of degree higher than 1*/
1546 2257852 : FOR( ; k < num_inputs; k++ )
1547 : {
1548 84949288 : FOR( l = 0; l < num_freq_bands; l++ )
1549 : {
1550 83526880 : p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )] = RealBuffer_fx[k][0][l]; // q_cldfb
1551 83526880 : move32();
1552 83526880 : p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1] = ImagBuffer_fx[k][0][l]; // q_cldfb
1553 83526880 : move32();
1554 : }
1555 : }
1556 : }
1557 :
1558 :
1559 : /*Copy direct to diffuse proto*/
1560 884436 : Copy32( p_proto_direct_buffer_fx, p_proto_diffuse_buffer_fx, i_mult( i_mult( 2, num_freq_bands ), s_min( num_outputs_diff, num_inputs ) ) ); /*proto_diffuse_buffer_f_q -> proto_direct_buffer_f_q*/
1561 884436 : *proto_diffuse_buffer_f_q = *proto_direct_buffer_f_q;
1562 884436 : move16();
1563 :
1564 884436 : IF( EQ_16( num_inputs, 1 ) )
1565 : {
1566 : /* Add comfort noise addition (CNA) to diffuse proto only*/
1567 2988512 : FOR( l = 0; l < num_freq_bands; l++ )
1568 : {
1569 2939520 : p_proto_diffuse_buffer_fx[2 * l] = L_add( p_proto_diffuse_buffer_fx[2 * l], RealBuffer_fx[1][0][l] ); // q_cldfb
1570 2939520 : move32();
1571 2939520 : p_proto_diffuse_buffer_fx[2 * l + 1] = L_add( p_proto_diffuse_buffer_fx[2 * l + 1], ImagBuffer_fx[1][0][l] ); // q_cldfb
1572 2939520 : move32();
1573 : }
1574 : }
1575 :
1576 884436 : return;
1577 : }
1578 :
1579 :
1580 : /*-------------------------------------------------------------------------
1581 : * protoSignalComputation1()
1582 : *
1583 : *
1584 : *-------------------------------------------------------------------------*/
1585 :
1586 133800 : void protoSignalComputation1_fx(
1587 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
1588 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
1589 : Word32 *proto_frame_f_fx, /*proto_frame_f_q*/
1590 : Word16 *proto_frame_f_q,
1591 : Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/
1592 : Word16 *proto_direct_buffer_f_q,
1593 : Word32 *reference_power_fx, /*reference_power_q*/
1594 : Word16 *reference_power_q,
1595 : Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/
1596 : Word16 *proto_power_smooth_q,
1597 : const Word16 slot_index,
1598 : const Word16 num_outputs_diff,
1599 : const Word16 num_freq_bands,
1600 : Word16 q_cldfb )
1601 : {
1602 : Word16 l, k, idx;
1603 : Word32 *p_proto_buffer_fx;
1604 : #ifdef FIX_867_CLDFB_NRG_SCALE
1605 : Word16 proto_power_smooth_fx_q[2], min_q_shift, q_shift;
1606 : #else
1607 : Word16 proto_power_smooth_fx_q, min_q_shift, q_shift;
1608 : #endif
1609 : Word32 re, im;
1610 :
1611 133800 : min_q_shift = Q31;
1612 133800 : move16();
1613 133800 : q_shift = Q31;
1614 133800 : move16();
1615 :
1616 133800 : p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * ( 2 * num_freq_bands ) ); /*proto_direct_buffer_f_q*/
1617 :
1618 : /* calculate the maximum shift possible for the bufferS RealBuffer_fx and ImagBuffer_fx*/
1619 133800 : q_shift = L_norm_arr( RealBuffer_fx[0][0], num_freq_bands );
1620 133800 : min_q_shift = s_min( q_shift, min_q_shift );
1621 133800 : q_shift = L_norm_arr( ImagBuffer_fx[0][0], num_freq_bands );
1622 133800 : min_q_shift = s_min( q_shift, min_q_shift );
1623 :
1624 133800 : min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) );
1625 :
1626 : /* calculate the maximum shift possible for the buffer proto_power_smooth_fx */
1627 133800 : q_shift = getScaleFactor32( proto_power_smooth_fx, num_freq_bands );
1628 133800 : q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) );
1629 :
1630 133800 : Scale_sig32( proto_power_smooth_fx, num_freq_bands, q_shift ); /*proto_power_smooth_q+q_shift*/
1631 : #ifdef FIX_867_CLDFB_NRG_SCALE
1632 133800 : proto_power_smooth_q[0] = add( proto_power_smooth_q[0], q_shift );
1633 133800 : proto_power_smooth_q[1] = add( proto_power_smooth_q[1], q_shift );
1634 133800 : proto_power_smooth_fx_q[0] = proto_power_smooth_q[0];
1635 133800 : proto_power_smooth_fx_q[1] = proto_power_smooth_q[1];
1636 133800 : move16();
1637 133800 : move16();
1638 : #else
1639 : *proto_power_smooth_q = add( *proto_power_smooth_q, q_shift );
1640 : proto_power_smooth_fx_q = *proto_power_smooth_q;
1641 : move16();
1642 : #endif
1643 :
1644 7839240 : FOR( l = 0; l < num_freq_bands; l++ )
1645 : {
1646 : #ifdef FIX_867_CLDFB_NRG_SCALE
1647 7705440 : Word16 qidx = s_min( 1, s_max( 0, sub( l, CLDFB_NO_CHANNELS_HALF - 1 ) ) );
1648 : #endif
1649 7705440 : re = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
1650 7705440 : im = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
1651 :
1652 7705440 : reference_power_fx[l] = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
1653 7705440 : move32();
1654 : #ifdef FIX_867_CLDFB_NRG_SCALE
1655 7705440 : reference_power_q[qidx] = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
1656 7705440 : move16();
1657 :
1658 7705440 : IF( LT_16( reference_power_q[qidx], proto_power_smooth_q[qidx] ) )
1659 : {
1660 4560520 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( proto_power_smooth_q[qidx], reference_power_q[qidx] ) ), reference_power_fx[l] ); // reference_power_q
1661 4560520 : move32();
1662 4560520 : proto_power_smooth_fx_q[qidx] = reference_power_q[qidx];
1663 4560520 : move16();
1664 : }
1665 : ELSE
1666 : {
1667 3144920 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( reference_power_q[qidx], proto_power_smooth_q[qidx] ) ) ); // proto_power_smooth_q
1668 3144920 : move32();
1669 3144920 : proto_power_smooth_fx_q[qidx] = proto_power_smooth_q[qidx];
1670 3144920 : move16();
1671 : }
1672 : #else
1673 : *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
1674 : move16();
1675 :
1676 : IF( LT_16( *reference_power_q, *proto_power_smooth_q ) )
1677 : {
1678 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *proto_power_smooth_q, *reference_power_q ) ), reference_power_fx[l] ); // reference_power_q
1679 : move32();
1680 : proto_power_smooth_fx_q = *reference_power_q;
1681 : move16();
1682 : }
1683 : ELSE
1684 : {
1685 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( *reference_power_q, *proto_power_smooth_q ) ) ); // proto_power_smooth_q
1686 : move32();
1687 : proto_power_smooth_fx_q = *proto_power_smooth_q;
1688 : move16();
1689 : }
1690 : #endif
1691 :
1692 7705440 : idx = 2 * l;
1693 7705440 : p_proto_buffer_fx[idx] = RealBuffer_fx[0][0][l]; // q_cldfb
1694 7705440 : move32();
1695 7705440 : p_proto_buffer_fx[idx + 1] = ImagBuffer_fx[0][0][l]; // q_cldfb
1696 7705440 : move32();
1697 :
1698 15410880 : FOR( k = 0; k < num_outputs_diff; k++ )
1699 : {
1700 7705440 : idx = add( i_mult( i_mult( 2, k ), num_freq_bands ), i_mult( 2, l ) );
1701 7705440 : proto_frame_f_fx[idx] = RealBuffer_fx[0][0][l]; // q_cldfb
1702 7705440 : move32();
1703 7705440 : proto_frame_f_fx[idx + 1] = ImagBuffer_fx[0][0][l]; // q_cldfb
1704 7705440 : move32();
1705 : }
1706 : }
1707 :
1708 133800 : *proto_frame_f_q = q_cldfb;
1709 133800 : move16();
1710 133800 : *proto_direct_buffer_f_q = q_cldfb;
1711 133800 : move16();
1712 : #ifdef FIX_867_CLDFB_NRG_SCALE
1713 133800 : proto_power_smooth_q[0] = proto_power_smooth_fx_q[0];
1714 133800 : proto_power_smooth_q[1] = proto_power_smooth_fx_q[1];
1715 133800 : move16();
1716 133800 : move16();
1717 : #else
1718 : *proto_power_smooth_q = proto_power_smooth_fx_q;
1719 : move16();
1720 : #endif
1721 :
1722 133800 : return;
1723 : }
1724 :
1725 :
1726 : /*-------------------------------------------------------------------------
1727 : * protoSignalComputation2()
1728 : *
1729 : *
1730 : *-------------------------------------------------------------------------*/
1731 :
1732 175029 : void protoSignalComputation2_fx(
1733 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
1734 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
1735 : Word32 *proto_frame_f_fx, /*q_proto_frame_f*/
1736 : Word16 *q_proto_frame_f,
1737 : Word32 *proto_direct_buffer_f_fx, /*q_proto_direct_buffer_f*/
1738 : Word16 *q_proto_direct_buffer_f,
1739 : Word32 *reference_power_fx, /*q_reference_power*/
1740 : Word16 *q_reference_power,
1741 : Word32 *proto_power_smooth_fx, /*q_proto_power_smooth*/
1742 : Word16 *q_proto_power_smooth,
1743 : const Word16 isloudspeaker,
1744 : const Word16 slot_index,
1745 : const Word16 num_freq_bands,
1746 : MASA_STEREO_TYPE_DETECT *stereo_type_detect,
1747 : Word16 q_cldfb )
1748 : {
1749 : Word16 l;
1750 : Word16 dipole_freq_range[2];
1751 : Word32 *p_proto_buffer_fx;
1752 : Word32 Real_aux_fx, Imag_aux_fx, re_aux, im_aux;
1753 : Word32 re1, im1, re2, im2;
1754 : Word32 RealSubtract_fx, ImagSubtract_fx;
1755 : Word32 left_bb_power_fx, right_bb_power_fx, total_bb_power_fx, lr_bb_power_fx;
1756 : Word32 left_hi_power_fx, right_hi_power_fx, total_hi_power_fx, lr_hi_power_fx;
1757 : Word32 sum_power_fx, Left_power_fx, Right_power_fx;
1758 : Word16 q_lr_bb_power, q_lr_hi_power;
1759 : Word32 lr_total_bb_ratio_fx, lr_total_hi_ratio_fx;
1760 : Word32 min_sum_total_ratio_fx, min_sum_total_ratio_db_fx;
1761 : Word32 sum_total_ratio_fx[MASA_SUM_FREQ_RANGE_BINS];
1762 : Word16 q_sum_total_ratio;
1763 : Word32 a_fx, b_fx, a2_fx, b2_fx;
1764 : Word16 interpolatorSpaced_fx, interpolatorDmx_fx;
1765 : Word32 tempSpaced_fx, tempDmx_fx;
1766 : #ifdef FIX_867_CLDFB_NRG_SCALE
1767 : Word16 q_shift, min_q_shift[2], exp, q_temp[2], temp_q_shift, q_temp2;
1768 : #else
1769 : Word16 q_shift, min_q_shift, exp, q_temp, temp_q_shift, q_temp2;
1770 : #endif
1771 : Word32 temp;
1772 : Word64 W_tmp1, W_tmp2;
1773 : Word64 reference_power_64fx[CLDFB_NO_CHANNELS_MAX];
1774 : Word16 q_reference_power_64fx;
1775 : Word16 head_room, q_Left_Right_power;
1776 : #ifdef FIX_867_CLDFB_NRG_SCALE
1777 175029 : Word16 num_proto = 3;
1778 : #endif
1779 : /* Calculate maximum possible shift for the buffers RealBuffer_fx and ImagBuffer_fx */
1780 : #ifdef FIX_867_CLDFB_NRG_SCALE
1781 175029 : min_q_shift[0] = Q31;
1782 175029 : min_q_shift[1] = Q31;
1783 175029 : move16();
1784 175029 : move16();
1785 : #else
1786 : min_q_shift = Q31;
1787 : move16();
1788 : #endif
1789 175029 : temp_q_shift = Q31;
1790 175029 : move16();
1791 175029 : q_sum_total_ratio = Q31;
1792 175029 : move16();
1793 175029 : exp = 0;
1794 175029 : move16();
1795 175029 : interpolatorSpaced_fx = 0;
1796 175029 : move16();
1797 175029 : interpolatorDmx_fx = MAX16B;
1798 175029 : move16();
1799 :
1800 : /* Calculate the max shift possible for the buffers RealBuffer_fx and ImagBuffer_fx */
1801 525087 : FOR( l = 0; l < 2; l++ )
1802 : {
1803 : #ifdef FIX_867_CLDFB_NRG_SCALE
1804 350058 : q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ) ), L_norm_arr( ImagBuffer_fx[l][0], s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ) ) );
1805 350058 : min_q_shift[0] = s_min( min_q_shift[0], q_shift );
1806 350058 : q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0] + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ), L_norm_arr( ImagBuffer_fx[l][0] + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
1807 350058 : min_q_shift[1] = s_min( min_q_shift[1], q_shift );
1808 : #if ( MASA_SUM_FREQ_RANGE_BINS > CLDFB_NO_CHANNELS_HALF )
1809 : #error MASA_SUM_FREQ_RANGE_BINS if greater than CLDFB_NO_CHANNELS_HALF, this does not work
1810 : #endif
1811 : #else
1812 : q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], num_freq_bands ), L_norm_arr( ImagBuffer_fx[l][0], num_freq_bands ) );
1813 : min_q_shift = s_min( min_q_shift, q_shift );
1814 : #endif
1815 350058 : q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ), L_norm_arr( ImagBuffer_fx[l][0], s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) );
1816 350058 : temp_q_shift = s_min( temp_q_shift, q_shift );
1817 : }
1818 :
1819 : #ifdef FIX_867_CLDFB_NRG_SCALE
1820 175029 : min_q_shift[0] = sub( min_q_shift[0], 2 ); // guard bits
1821 175029 : min_q_shift[1] = sub( min_q_shift[1], 2 ); // guard bits
1822 : #else
1823 : min_q_shift = sub( min_q_shift, 2 ); // guard bits
1824 : #endif
1825 175029 : temp_q_shift = sub( temp_q_shift, 2 ); // guard bits
1826 :
1827 : /* Upscaling of the buffer proto_power_smooth_fx */
1828 : #ifdef FIX_867_CLDFB_NRG_SCALE
1829 175029 : IF( isloudspeaker )
1830 : {
1831 93852 : num_proto = 3;
1832 93852 : q_shift = L_norm_arr( proto_power_smooth_fx, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) );
1833 93852 : q_shift = s_min( q_shift, L_norm_arr( proto_power_smooth_fx + num_freq_bands, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
1834 93852 : q_shift = s_min( q_shift, L_norm_arr( proto_power_smooth_fx + num_freq_bands + num_freq_bands, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
1835 93852 : scale_sig32( proto_power_smooth_fx, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1836 93852 : scale_sig32( proto_power_smooth_fx + num_freq_bands, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1837 93852 : scale_sig32( proto_power_smooth_fx + num_freq_bands + num_freq_bands, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1838 : }
1839 : ELSE
1840 : {
1841 81177 : num_proto = 2;
1842 81177 : q_shift = L_norm_arr( proto_power_smooth_fx, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) );
1843 81177 : q_shift = s_min( q_shift, L_norm_arr( proto_power_smooth_fx + num_freq_bands, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
1844 81177 : scale_sig32( proto_power_smooth_fx, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1845 81177 : scale_sig32( proto_power_smooth_fx + num_freq_bands, s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1846 : }
1847 175029 : q_proto_power_smooth[0] = add( q_proto_power_smooth[0], sub( q_shift, 1 ) );
1848 175029 : move16();
1849 175029 : IF( isloudspeaker )
1850 : {
1851 93852 : q_shift = L_norm_arr( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
1852 93852 : q_shift = s_min( q_shift, L_norm_arr( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + num_freq_bands, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
1853 93852 : q_shift = s_min( q_shift, L_norm_arr( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + num_freq_bands + num_freq_bands, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
1854 93852 : scale_sig32( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1855 93852 : scale_sig32( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + num_freq_bands, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1856 93852 : scale_sig32( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + num_freq_bands + num_freq_bands, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1857 : }
1858 : ELSE
1859 : {
1860 81177 : q_shift = L_norm_arr( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
1861 81177 : q_shift = s_min( q_shift, L_norm_arr( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + num_freq_bands, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) ) );
1862 81177 : scale_sig32( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1863 81177 : scale_sig32( proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + num_freq_bands, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1864 : }
1865 175029 : q_proto_power_smooth[1] = add( q_proto_power_smooth[1], sub( q_shift, 1 ) );
1866 175029 : move16();
1867 : #else
1868 : IF( isloudspeaker )
1869 : {
1870 : q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( 3, num_freq_bands ) );
1871 : scale_sig32( proto_power_smooth_fx, i_mult( 3, num_freq_bands ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1872 : }
1873 : ELSE
1874 : {
1875 : q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ) );
1876 : scale_sig32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1
1877 : }
1878 : *q_proto_power_smooth = add( *q_proto_power_smooth, sub( q_shift, 1 ) );
1879 : move16();
1880 : #endif
1881 :
1882 175029 : IF( isloudspeaker )
1883 : {
1884 93852 : p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 3 ); // q_proto_direct_buffer_f
1885 :
1886 : #ifdef FIX_867_CLDFB_NRG_SCALE
1887 93852 : q_temp[0] = sub( add( add( q_cldfb, min_q_shift[0] ), add( q_cldfb, min_q_shift[0] ) ), 31 );
1888 93852 : q_temp[1] = sub( add( add( q_cldfb, min_q_shift[1] ), add( q_cldfb, min_q_shift[1] ) ), 31 );
1889 : #else
1890 : q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
1891 : move16();
1892 : #endif
1893 :
1894 5628972 : FOR( l = 0; l < num_freq_bands; l++ )
1895 : {
1896 : #ifdef FIX_867_CLDFB_NRG_SCALE
1897 5535120 : Word16 qidx = s_min( 1, s_max( 0, sub( l, CLDFB_NO_CHANNELS_HALF - 1 ) ) );
1898 :
1899 5535120 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
1900 5535120 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
1901 5535120 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
1902 5535120 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
1903 : #else
1904 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
1905 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
1906 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift
1907 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift
1908 : #endif
1909 :
1910 5535120 : Real_aux_fx = L_add( re1, re2 ); // q_cldfb+min_q_shift
1911 5535120 : Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+min_q_shift
1912 :
1913 : // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 );
1914 5535120 : W_tmp1 = W_add( W_mult0_32_32( re1, re1 ), W_mult0_32_32( im1, im1 ) ); // 2*(q_cldfb+min_q_shift)
1915 : // Right_power_fx = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 );
1916 5535120 : W_tmp2 = W_add( W_mult0_32_32( re2, re2 ), W_mult0_32_32( im2, im2 ) ); // 2*(q_cldfb+min_q_shift)
1917 :
1918 :
1919 : // reference_power_fx[l] = L_add( Left_power_fx, Right_power_fx );
1920 5535120 : reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift)
1921 5535120 : move64();
1922 :
1923 5535120 : temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31
1924 :
1925 : #ifdef FIX_867_CLDFB_NRG_SCALE
1926 5535120 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
1927 : #else
1928 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
1929 : #endif
1930 : {
1931 : #ifdef FIX_867_CLDFB_NRG_SCALE
1932 4320770 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
1933 : #else
1934 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
1935 : #endif
1936 4320770 : move32();
1937 : }
1938 : ELSE
1939 : {
1940 : #ifdef FIX_867_CLDFB_NRG_SCALE
1941 1214350 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
1942 : #else
1943 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
1944 : #endif
1945 1214350 : move32();
1946 : }
1947 :
1948 5535120 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
1949 5535120 : move32();
1950 5535120 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
1951 5535120 : move32();
1952 :
1953 5535120 : temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31
1954 :
1955 : #ifdef FIX_867_CLDFB_NRG_SCALE
1956 5535120 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
1957 : #else
1958 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
1959 : #endif
1960 : {
1961 : #ifdef FIX_867_CLDFB_NRG_SCALE
1962 4320770 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
1963 : #else
1964 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
1965 : #endif
1966 4320770 : move32();
1967 : }
1968 : ELSE
1969 : {
1970 : #ifdef FIX_867_CLDFB_NRG_SCALE
1971 1214350 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
1972 : #else
1973 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
1974 : #endif
1975 1214350 : move32();
1976 : }
1977 :
1978 5535120 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = re1; // q_cldfb+min_q_shift
1979 5535120 : move32();
1980 5535120 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = im1; // q_cldfb+min_q_shift
1981 5535120 : move32();
1982 :
1983 5535120 : temp = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); // 2*(q_cldfb+min_q_shift)-31
1984 : #ifdef FIX_867_CLDFB_NRG_SCALE
1985 5535120 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
1986 : #else
1987 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
1988 : #endif
1989 : {
1990 : #ifdef FIX_867_CLDFB_NRG_SCALE
1991 4320770 : proto_power_smooth_fx[l + ( 2 * num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[l + ( 2 * num_freq_bands )], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
1992 : #else
1993 : proto_power_smooth_fx[l + ( 2 * num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[l + ( 2 * num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
1994 : #endif
1995 4320770 : move32();
1996 : }
1997 : ELSE
1998 : {
1999 : #ifdef FIX_867_CLDFB_NRG_SCALE
2000 1214350 : proto_power_smooth_fx[l + ( 2 * num_freq_bands )] = L_add( proto_power_smooth_fx[l + ( 2 * num_freq_bands )], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2001 : #else
2002 : proto_power_smooth_fx[l + ( 2 * num_freq_bands )] = L_add( proto_power_smooth_fx[l + ( 2 * num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2003 : #endif
2004 1214350 : move32();
2005 : }
2006 :
2007 5535120 : p_proto_buffer_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift
2008 5535120 : move32();
2009 5535120 : p_proto_buffer_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift
2010 5535120 : move32();
2011 :
2012 5535120 : proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2013 5535120 : move32();
2014 5535120 : proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2015 5535120 : move32();
2016 :
2017 5535120 : proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+min_q_shift
2018 5535120 : move32();
2019 5535120 : proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+min_q_shift
2020 5535120 : move32();
2021 5535120 : proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift
2022 5535120 : move32();
2023 5535120 : proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift
2024 5535120 : move32();
2025 : }
2026 : }
2027 81177 : ELSE IF( stereo_type_detect != NULL )
2028 : {
2029 61933 : p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * 4 * num_freq_bands ); // q_proto_direct_buffer_f
2030 :
2031 61933 : left_bb_power_fx = 0;
2032 61933 : move32();
2033 61933 : right_bb_power_fx = 0;
2034 61933 : move32();
2035 61933 : total_bb_power_fx = 0;
2036 61933 : move32();
2037 :
2038 61933 : left_hi_power_fx = 0;
2039 61933 : move32();
2040 61933 : right_hi_power_fx = 0;
2041 61933 : move32();
2042 61933 : total_hi_power_fx = 0;
2043 61933 : move32();
2044 :
2045 61933 : dipole_freq_range[0] = stereo_type_detect->dipole_freq_range[0];
2046 61933 : move16();
2047 61933 : dipole_freq_range[1] = stereo_type_detect->dipole_freq_range[1];
2048 61933 : move16();
2049 :
2050 61933 : a_fx = 21474836; /*0.01 in Q31*/ /* Temporal smoothing coefficient */
2051 61933 : move32();
2052 61933 : b_fx = L_sub( ONE_IN_Q31, a_fx ); /* Temporal smoothing coefficient q31*/
2053 61933 : move32();
2054 61933 : a2_fx = 214748365; /*0.1 in Q31*/ /* Temporal smoothing coefficient */
2055 61933 : move32();
2056 61933 : b2_fx = L_sub( ONE_IN_Q31, a2_fx ); /* Temporal smoothing coefficient */
2057 :
2058 61933 : IF( stereo_type_detect->interpolator > 0 )
2059 : {
2060 30 : IF( EQ_16( stereo_type_detect->type_change_direction, MASA_STEREO_SPACED_MICS ) )
2061 : {
2062 : /* interpolatorSpaced = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); */
2063 30 : interpolatorSpaced_fx = i_mult_sat( stereo_type_detect->interpolator, 2048 /* 1 / MASA_STEREO_INTERPOLATION_SLOTS in Q15 */ ); /* Q15 */
2064 30 : interpolatorDmx_fx = sub( MAX16B, interpolatorSpaced_fx ); /* Q15 */
2065 : }
2066 : ELSE
2067 : {
2068 : /* interpolatorDmx = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); */
2069 0 : interpolatorDmx_fx = i_mult_sat( stereo_type_detect->interpolator, 2048 /* 1 / MASA_STEREO_INTERPOLATION_SLOTS in Q15 */ ); /* Q15 */
2070 0 : interpolatorSpaced_fx = sub( MAX16B, interpolatorDmx_fx ); /* Q15 */
2071 : }
2072 : }
2073 :
2074 : #ifdef FIX_867_CLDFB_NRG_SCALE
2075 : Word16 total_shift[2], q_temp_total;
2076 : /* total_shift shift required to get common Q of sum power values */
2077 61933 : total_shift[0] = shl( s_max( 0, sub( min_q_shift[0], min_q_shift[1] ) ), 1 );
2078 61933 : total_shift[1] = shl( s_max( 0, sub( min_q_shift[1], min_q_shift[0] ) ), 1 );
2079 61933 : min_q_shift[0] = sub( min_q_shift[0], idiv1616( find_guarded_bits_fx( num_freq_bands ), 2 ) );
2080 61933 : min_q_shift[1] = sub( min_q_shift[1], idiv1616( find_guarded_bits_fx( num_freq_bands ), 2 ) );
2081 61933 : q_temp[0] = sub( add( add( q_cldfb, min_q_shift[0] ), add( q_cldfb, min_q_shift[0] ) ), 31 );
2082 61933 : q_temp[1] = sub( add( add( q_cldfb, min_q_shift[1] ), add( q_cldfb, min_q_shift[1] ) ), 31 );
2083 61933 : q_temp_total = s_min( q_temp[0], q_temp[1] );
2084 : #else
2085 : min_q_shift = sub( min_q_shift, idiv1616( find_guarded_bits_fx( num_freq_bands ), 2 ) );
2086 :
2087 : q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
2088 : #endif
2089 61933 : q_temp2 = sub( add( add( q_cldfb, temp_q_shift ), add( q_cldfb, temp_q_shift ) ), 31 );
2090 :
2091 61933 : head_room = 63;
2092 61933 : move16();
2093 3337973 : FOR( l = 0; l < num_freq_bands; l++ )
2094 : {
2095 : #ifdef FIX_867_CLDFB_NRG_SCALE
2096 3276040 : Word16 qidx = s_min( 1, s_max( 0, sub( l, CLDFB_NO_CHANNELS_HALF - 1 ) ) );
2097 3276040 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2098 3276040 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2099 3276040 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2100 3276040 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2101 : #else
2102 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
2103 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
2104 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift
2105 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift
2106 : #endif
2107 :
2108 3276040 : W_tmp1 = W_add( W_mult0_32_32( re1, re1 ), W_mult0_32_32( im1, im1 ) );
2109 3276040 : W_tmp2 = W_add( W_mult0_32_32( re2, re2 ), W_mult0_32_32( im2, im2 ) );
2110 :
2111 3276040 : head_room = s_min( head_room, W_norm( W_add( W_tmp1, W_tmp2 ) ) );
2112 : }
2113 61933 : head_room = sub( head_room, find_guarded_bits_fx( num_freq_bands ) );
2114 :
2115 : #ifdef FIX_867_CLDFB_NRG_SCALE
2116 : #if ( MASA_SUM_FREQ_RANGE_BINS > CLDFB_NO_CHANNELS_HALF )
2117 : #error MASA_SUM_FREQ_RANGE_BINS must be less than CLDFB_NO_CHANNELS_HALF
2118 : #endif
2119 61933 : q_Left_Right_power = add( shl( add( q_cldfb, min_q_shift[0] ), 1 ), sub( head_room, 32 ) );
2120 : #else
2121 : q_Left_Right_power = add( shl( add( q_cldfb, min_q_shift ), 1 ), sub( head_room, 32 ) );
2122 : #endif
2123 :
2124 3337973 : FOR( l = 0; l < num_freq_bands; l++ )
2125 : {
2126 : #ifdef FIX_867_CLDFB_NRG_SCALE
2127 3276040 : Word16 qidx = s_min( 1, s_max( 0, sub( l, CLDFB_NO_CHANNELS_HALF - 1 ) ) );
2128 3276040 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2129 3276040 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2130 3276040 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2131 3276040 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2132 : #else
2133 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
2134 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
2135 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift
2136 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift
2137 : #endif
2138 :
2139 : /* Compute sum signal */
2140 3276040 : Real_aux_fx = L_add( re1, re2 ); // q_cldfb+min_q_shift
2141 3276040 : Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+min_q_shift
2142 :
2143 : /* Compute reference power */
2144 : // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 );
2145 3276040 : W_tmp1 = W_add( W_mult0_32_32( re1, re1 ), W_mult0_32_32( im1, im1 ) ); // 2*(q_cldfb+min_q_shift)
2146 3276040 : Left_power_fx = W_extract_h( W_shl( W_tmp1, head_room ) ); // q_Left_Right_power
2147 :
2148 : // Right_power_fx = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 );
2149 3276040 : W_tmp2 = W_add( W_mult0_32_32( re2, re2 ), W_mult0_32_32( im2, im2 ) ); // 2*(q_cldfb+min_q_shift)
2150 3276040 : Right_power_fx = W_extract_h( W_shl( W_tmp2, head_room ) ); // q_Left_Right_power
2151 :
2152 : // reference_power_fx[l] = L_add( Left_power_fx, Right_power_fx );
2153 3276040 : reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift)
2154 3276040 : move64();
2155 :
2156 : #ifdef FIX_867_CLDFB_NRG_SCALE
2157 3276040 : Left_power_fx = L_shr( Left_power_fx, total_shift[qidx] );
2158 3276040 : Right_power_fx = L_shr( Right_power_fx, total_shift[qidx] );
2159 3276040 : left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); // q_Left_Right_power
2160 3276040 : right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); // q_Left_Right_power
2161 : // total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] );
2162 3276040 : total_bb_power_fx = L_add( total_bb_power_fx, W_extract_h( W_shl( reference_power_64fx[l], sub( head_room, total_shift[qidx] ) ) ) ); // q_Left_Right_power
2163 : #else
2164 : left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); // q_Left_Right_power
2165 : right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); // q_Left_Right_power
2166 : // total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] );
2167 : total_bb_power_fx = L_add( total_bb_power_fx, W_extract_h( W_shl( reference_power_64fx[l], head_room ) ) ); // q_Left_Right_power
2168 : #endif
2169 :
2170 3276040 : IF( GT_16( l, MASA_HI_FREQ_START_BIN ) )
2171 : {
2172 2347045 : left_hi_power_fx = L_add( left_hi_power_fx, Left_power_fx ); // q_Left_Right_power
2173 2347045 : right_hi_power_fx = L_add( right_hi_power_fx, Right_power_fx ); // q_Left_Right_power
2174 : // total_hi_power_fx = L_add( total_hi_power_fx, reference_power_fx[l] );
2175 : #ifdef FIX_867_CLDFB_NRG_SCALE
2176 2347045 : total_hi_power_fx = L_add( total_hi_power_fx, W_extract_h( W_shl( reference_power_64fx[l], sub( head_room, total_shift[qidx] ) ) ) ); // q_Left_Right_power
2177 : #else
2178 : total_hi_power_fx = L_add( total_hi_power_fx, W_extract_h( W_shl( reference_power_64fx[l], head_room ) ) ); // q_Left_Right_power
2179 : #endif
2180 : }
2181 :
2182 3276040 : IF( LT_16( l, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) )
2183 : {
2184 : #ifdef FIX_867_CLDFB_NRG_SCALE
2185 1524325 : re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift[0] ) ); // q_cldfb+temp_q_shift
2186 1524325 : im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift[0] ) ); // q_cldfb+temp_q_shift
2187 : #else
2188 : re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift
2189 : im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift
2190 : #endif
2191 :
2192 1524325 : sum_power_fx = Madd_32_32( Mpy_32_32( re_aux, re_aux ), im_aux, im_aux ); // 2*(q_cldfb+temp_q_shift)-31
2193 1524325 : temp = Mpy_32_32( a_fx, sum_power_fx ); // 2*(q_cldfb+temp_q_shift)-31
2194 :
2195 1524325 : IF( LT_16( q_temp2, stereo_type_detect->q_sum_power ) )
2196 : {
2197 11600 : stereo_type_detect->sum_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ), sub( stereo_type_detect->q_sum_power, q_temp2 ) ) ); // q_temp2
2198 11600 : move32();
2199 : }
2200 : ELSE
2201 : {
2202 1512725 : stereo_type_detect->sum_power_fx[l] = L_add( L_shr( temp, sub( q_temp2, stereo_type_detect->q_sum_power ) ), Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ) ); // stereo_type_detect->q_sum_power
2203 1512725 : move32();
2204 : }
2205 :
2206 : #ifdef FIX_867_CLDFB_NRG_SCALE
2207 1524325 : temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], add( 31, total_shift[qidx] ) ) ) ); // 2*(q_cldfb+min_q_shift) -31
2208 1524325 : IF( LT_16( q_temp_total, stereo_type_detect->q_total_power ) )
2209 : {
2210 11645 : stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp_total ) ) ); // q_temp
2211 11645 : move32();
2212 : }
2213 : ELSE
2214 : {
2215 1512680 : stereo_type_detect->total_power_fx[l] = L_add( L_shr( temp, sub( q_temp_total, stereo_type_detect->q_total_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ) ); // stereo_type_detect->q_total_power
2216 1512680 : move32();
2217 : }
2218 : #else
2219 : temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31
2220 : IF( LT_16( q_temp, stereo_type_detect->q_total_power ) )
2221 : {
2222 : stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp ) ) ); // q_temp
2223 : move32();
2224 : }
2225 : ELSE
2226 : {
2227 : stereo_type_detect->total_power_fx[l] = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ) ); // stereo_type_detect->q_total_power
2228 : move32();
2229 : }
2230 : #endif
2231 :
2232 1524325 : test();
2233 1524325 : IF( ( stereo_type_detect->sum_power_fx[l] == 0 ) && ( stereo_type_detect->total_power_fx[l] == 0 ) )
2234 : {
2235 2663 : sum_total_ratio_fx[l] = MAX_32; // q15
2236 2663 : move32();
2237 : }
2238 1521662 : ELSE IF( stereo_type_detect->total_power_fx[l] == 0 )
2239 : {
2240 516142 : sum_total_ratio_fx[l] = MAX_32; // q15
2241 516142 : move32();
2242 : }
2243 : ELSE
2244 : {
2245 1005520 : sum_total_ratio_fx[l] = BASOP_Util_Divide3232_Scale( stereo_type_detect->sum_power_fx[l], stereo_type_detect->total_power_fx[l], &exp ); // 15-(exp+s_min( stereo_type_detect->q_total_power, q_temp )-s_min( stereo_type_detect->q_sum_power, q_temp2 ))
2246 1005520 : move32();
2247 : #ifdef FIX_867_CLDFB_NRG_SCALE
2248 1005520 : q_sum_total_ratio = add( sub( 15, exp ), sub( s_min( stereo_type_detect->q_sum_power, q_temp2 ), s_min( stereo_type_detect->q_total_power, q_temp_total ) ) );
2249 : #else
2250 : q_sum_total_ratio = add( sub( 15, exp ), sub( s_min( stereo_type_detect->q_sum_power, q_temp2 ), s_min( stereo_type_detect->q_total_power, q_temp ) ) );
2251 : #endif
2252 1005520 : sum_total_ratio_fx[l] = L_shl( sum_total_ratio_fx[l], sub( Q15, q_sum_total_ratio ) ); // q15
2253 1005520 : move32();
2254 : }
2255 : }
2256 :
2257 3276040 : IF( l == 0 )
2258 : {
2259 61933 : RealSubtract_fx = L_sub( re1, re2 ); // q_cldfb+min_q_shift
2260 61933 : ImagSubtract_fx = L_sub( im1, im2 ); // q_cldfb+min_q_shift
2261 :
2262 61933 : temp = Madd_32_32( Mpy_32_32( RealSubtract_fx, RealSubtract_fx ), ImagSubtract_fx, ImagSubtract_fx ); // 2*(q_cldfb+min_q_shift)-31
2263 : #ifdef FIX_867_CLDFB_NRG_SCALE
2264 61933 : assert( qidx == 0 );
2265 61933 : IF( LT_16( q_temp[qidx], stereo_type_detect->q_subtract_power_y ) )
2266 : {
2267 23770 : stereo_type_detect->subtract_power_y_fx = L_add( L_shr( stereo_type_detect->subtract_power_y_fx, sub( stereo_type_detect->q_subtract_power_y, q_temp[qidx] ) ), temp ); // q_temp
2268 23770 : move32();
2269 23770 : stereo_type_detect->q_subtract_power_y = q_temp[qidx];
2270 23770 : move16();
2271 : }
2272 : ELSE
2273 : {
2274 38163 : stereo_type_detect->subtract_power_y_fx = L_add( stereo_type_detect->subtract_power_y_fx, L_shr( temp, sub( q_temp[qidx], stereo_type_detect->q_subtract_power_y ) ) ); // stereo_type_detect->q_subtract_power_y
2275 38163 : move32();
2276 : }
2277 :
2278 : #else
2279 : IF( LT_16( q_temp, stereo_type_detect->q_subtract_power_y ) )
2280 : {
2281 : stereo_type_detect->subtract_power_y_fx = L_add( L_shr( stereo_type_detect->subtract_power_y_fx, sub( stereo_type_detect->q_subtract_power_y, q_temp ) ), temp ); // q_temp
2282 : move32();
2283 : stereo_type_detect->q_subtract_power_y = q_temp;
2284 : move16();
2285 : }
2286 : ELSE
2287 : {
2288 : stereo_type_detect->subtract_power_y_fx = L_add( stereo_type_detect->subtract_power_y_fx, L_shr( temp, sub( q_temp, stereo_type_detect->q_subtract_power_y ) ) ); // stereo_type_detect->q_subtract_power_y
2289 : move32();
2290 : }
2291 : #endif
2292 : }
2293 :
2294 : /* Compute protos (and their power) for direct sound rendering */
2295 :
2296 : /* W prototype */
2297 3276040 : IF( stereo_type_detect->interpolator > 0 )
2298 : {
2299 1800 : IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) )
2300 : {
2301 1650 : Real_aux_fx = Madd_32_16( Mpy_32_16_1( Real_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Real_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift
2302 1650 : Imag_aux_fx = Madd_32_16( Mpy_32_16_1( Imag_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Imag_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift
2303 :
2304 1650 : temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift) -31
2305 : #ifdef FIX_867_CLDFB_NRG_SCALE
2306 1650 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2307 : #else
2308 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2309 : #endif
2310 : {
2311 : #ifdef FIX_867_CLDFB_NRG_SCALE
2312 1650 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2313 : #else
2314 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2315 : #endif
2316 1650 : move32();
2317 : }
2318 : ELSE
2319 : {
2320 : #ifdef FIX_867_CLDFB_NRG_SCALE
2321 0 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2322 : #else
2323 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2324 : #endif
2325 0 : move32();
2326 : }
2327 :
2328 1650 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2329 1650 : move32();
2330 1650 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2331 1650 : move32();
2332 : }
2333 : ELSE
2334 : {
2335 150 : tempSpaced_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31
2336 150 : tempDmx_fx = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31
2337 :
2338 150 : temp = Madd_32_16( Mpy_32_16_1( tempSpaced_fx, interpolatorSpaced_fx ), tempDmx_fx, interpolatorDmx_fx ); // 2*(q_cldfb+min_q_shift)-31
2339 : #ifdef FIX_867_CLDFB_NRG_SCALE
2340 150 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2341 : #else
2342 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2343 : #endif
2344 : {
2345 : #ifdef FIX_867_CLDFB_NRG_SCALE
2346 150 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2347 : #else
2348 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2349 : #endif
2350 150 : move32();
2351 : }
2352 : ELSE
2353 : {
2354 : #ifdef FIX_867_CLDFB_NRG_SCALE
2355 0 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2356 : #else
2357 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2358 : #endif
2359 0 : move32();
2360 : }
2361 :
2362 150 : p_proto_buffer_fx[2 * l] = Madd_32_16( Mpy_32_16_1( re1, interpolatorSpaced_fx ), Real_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift
2363 150 : move32();
2364 150 : p_proto_buffer_fx[2 * l + 1] = Madd_32_16( Mpy_32_16_1( im1, interpolatorSpaced_fx ), Imag_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift
2365 150 : move32();
2366 : }
2367 : }
2368 3274240 : ELSE IF( EQ_16( stereo_type_detect->masa_stereo_type, MASA_STEREO_SPACED_MICS ) )
2369 : {
2370 526080 : IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) )
2371 : {
2372 482240 : Real_aux_fx = L_shr( Real_aux_fx, 1 ); // q_cldfb+min_q_shift
2373 482240 : Imag_aux_fx = L_shr( Imag_aux_fx, 1 ); // q_cldfb+min_q_shift
2374 482240 : temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31
2375 : #ifdef FIX_867_CLDFB_NRG_SCALE
2376 482240 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2377 : #else
2378 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2379 : #endif
2380 : {
2381 : #ifdef FIX_867_CLDFB_NRG_SCALE
2382 482240 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2383 : #else
2384 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2385 : #endif
2386 482240 : move32();
2387 : }
2388 : ELSE
2389 : {
2390 : #ifdef FIX_867_CLDFB_NRG_SCALE
2391 0 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2392 : #else
2393 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2394 : #endif
2395 0 : move32();
2396 : }
2397 :
2398 482240 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2399 482240 : move32();
2400 482240 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2401 482240 : move32();
2402 : }
2403 : ELSE
2404 : {
2405 43840 : temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31
2406 : #ifdef FIX_867_CLDFB_NRG_SCALE
2407 43840 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2408 : #else
2409 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2410 : #endif
2411 : {
2412 : #ifdef FIX_867_CLDFB_NRG_SCALE
2413 43840 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2414 : #else
2415 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2416 : #endif
2417 43840 : move32();
2418 : }
2419 : ELSE
2420 : {
2421 : #ifdef FIX_867_CLDFB_NRG_SCALE
2422 0 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2423 : #else
2424 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2425 : #endif
2426 0 : move32();
2427 : }
2428 :
2429 43840 : p_proto_buffer_fx[2 * l] = re1; // q_cldfb+min_q_shift
2430 43840 : move32();
2431 43840 : p_proto_buffer_fx[2 * l + 1] = im1; // q_cldfb+min_q_shift
2432 43840 : move32();
2433 : }
2434 : }
2435 : ELSE
2436 : {
2437 2748160 : temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31
2438 : #ifdef FIX_867_CLDFB_NRG_SCALE
2439 2748160 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2440 : #else
2441 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2442 : #endif
2443 : {
2444 : #ifdef FIX_867_CLDFB_NRG_SCALE
2445 2747650 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2446 : #else
2447 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2448 : #endif
2449 2747650 : move32();
2450 : }
2451 : ELSE
2452 : {
2453 : #ifdef FIX_867_CLDFB_NRG_SCALE
2454 510 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2455 : #else
2456 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2457 : #endif
2458 510 : move32();
2459 : }
2460 :
2461 2748160 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2462 2748160 : move32();
2463 2748160 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2464 2748160 : move32();
2465 : }
2466 :
2467 : /* Y prototype */
2468 3276040 : IF( stereo_type_detect->interpolator > 0 )
2469 : {
2470 1800 : IF( LT_16( l, dipole_freq_range[0] ) )
2471 : {
2472 30 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift
2473 30 : move32();
2474 30 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l + 1], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift
2475 30 : move32();
2476 : }
2477 1770 : ELSE IF( LT_16( l, dipole_freq_range[1] ) )
2478 : {
2479 60 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( L_sub( im1, im2 ), interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift
2480 60 : move32();
2481 60 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( -L_sub( re1, re2 ), interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift
2482 60 : move32();
2483 : }
2484 : ELSE
2485 : {
2486 1710 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift
2487 1710 : move32();
2488 1710 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l + 1], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift
2489 1710 : move32();
2490 : }
2491 :
2492 1800 : temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31
2493 : #ifdef FIX_867_CLDFB_NRG_SCALE
2494 1800 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2495 : #else
2496 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2497 : #endif
2498 : {
2499 : #ifdef FIX_867_CLDFB_NRG_SCALE
2500 1800 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2501 : #else
2502 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2503 : #endif
2504 1800 : move32();
2505 : }
2506 : ELSE
2507 : {
2508 : #ifdef FIX_867_CLDFB_NRG_SCALE
2509 0 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2510 : #else
2511 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2512 : #endif
2513 0 : move32();
2514 : }
2515 : }
2516 3274240 : ELSE IF( EQ_16( stereo_type_detect->masa_stereo_type, MASA_STEREO_SPACED_MICS ) )
2517 : {
2518 526080 : IF( LT_16( l, dipole_freq_range[0] ) ) /* proto = W */
2519 : {
2520 8768 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = p_proto_buffer_fx[2 * l]; // q_cldfb+min_q_shift
2521 8768 : move32();
2522 8768 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = p_proto_buffer_fx[2 * l + 1]; // q_cldfb+min_q_shift
2523 8768 : move32();
2524 8768 : proto_power_smooth_fx[l + num_freq_bands] = proto_power_smooth_fx[l];
2525 8768 : move32();
2526 : }
2527 517312 : ELSE IF( LT_16( l, dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */
2528 : {
2529 17536 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( im1, im2 ); // q_cldfb+min_q_shift
2530 17536 : move32();
2531 17536 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = -L_sub( re1, re2 ); // q_cldfb+min_q_shift
2532 17536 : move32();
2533 :
2534 17536 : temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31
2535 : #ifdef FIX_867_CLDFB_NRG_SCALE
2536 17536 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2537 : #else
2538 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2539 : #endif
2540 : {
2541 : #ifdef FIX_867_CLDFB_NRG_SCALE
2542 17536 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2543 : #else
2544 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2545 : #endif
2546 17536 : move32();
2547 : }
2548 : ELSE
2549 : {
2550 : #ifdef FIX_867_CLDFB_NRG_SCALE
2551 0 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2552 : #else
2553 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2554 : #endif
2555 0 : move32();
2556 : }
2557 : }
2558 : ELSE /* proto = W */
2559 : {
2560 499776 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = p_proto_buffer_fx[2 * l]; // q_cldfb+min_q_shift
2561 499776 : move32();
2562 499776 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = p_proto_buffer_fx[2 * l + 1]; // q_cldfb+min_q_shift
2563 499776 : move32();
2564 499776 : proto_power_smooth_fx[l + num_freq_bands] = proto_power_smooth_fx[l]; // min( q_temp, *q_proto_power_smooth )
2565 499776 : move32();
2566 : }
2567 : }
2568 : ELSE
2569 : {
2570 2748160 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( re1, re2 ); // q_cldfb+min_q_shift
2571 2748160 : move32();
2572 2748160 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_sub( im1, im2 ); // q_cldfb+min_q_shift
2573 2748160 : move32();
2574 :
2575 2748160 : temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31
2576 : #ifdef FIX_867_CLDFB_NRG_SCALE
2577 2748160 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2578 : #else
2579 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2580 : #endif
2581 : {
2582 : #ifdef FIX_867_CLDFB_NRG_SCALE
2583 2747650 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2584 : #else
2585 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2586 : #endif
2587 2747650 : move32();
2588 : }
2589 : ELSE
2590 : {
2591 : #ifdef FIX_867_CLDFB_NRG_SCALE
2592 510 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2593 : #else
2594 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2595 : #endif
2596 510 : move32();
2597 : }
2598 : }
2599 :
2600 : /* Compute protos for decorrelation */
2601 3276040 : proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2602 3276040 : move32();
2603 3276040 : proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2604 3276040 : move32();
2605 3276040 : proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+min_q_shift
2606 3276040 : move32();
2607 3276040 : proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+min_q_shift
2608 3276040 : move32();
2609 3276040 : proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift
2610 3276040 : move32();
2611 3276040 : proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift
2612 3276040 : move32();
2613 : }
2614 :
2615 61933 : stereo_type_detect->q_sum_power = s_min( stereo_type_detect->q_sum_power, q_temp2 );
2616 61933 : move16();
2617 : #ifdef FIX_867_CLDFB_NRG_SCALE
2618 61933 : stereo_type_detect->q_total_power = s_min( stereo_type_detect->q_total_power, q_temp_total );
2619 61933 : move16();
2620 : #else
2621 : stereo_type_detect->q_total_power = s_min( stereo_type_detect->q_total_power, q_temp );
2622 : move16();
2623 : #endif
2624 61933 : q_sum_total_ratio = Q15;
2625 61933 : move16();
2626 :
2627 61933 : IF( stereo_type_detect->interpolator > 0 )
2628 : {
2629 30 : stereo_type_detect->interpolator++;
2630 30 : IF( EQ_16( stereo_type_detect->interpolator, MASA_STEREO_INTERPOLATION_SLOTS ) )
2631 : {
2632 2 : stereo_type_detect->interpolator = 0;
2633 2 : move16();
2634 2 : stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction;
2635 2 : move32();
2636 : }
2637 : }
2638 :
2639 61933 : temp = Mpy_32_32( a_fx, left_bb_power_fx ); // q_Left_Right_power
2640 61933 : IF( LT_16( q_Left_Right_power, stereo_type_detect->q_left_bb_power ) )
2641 : {
2642 611 : stereo_type_detect->left_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ), sub( stereo_type_detect->q_left_bb_power, q_Left_Right_power ) ) ); // q_Left_Right_power
2643 611 : move32();
2644 611 : stereo_type_detect->q_left_bb_power = q_Left_Right_power;
2645 611 : move16();
2646 : }
2647 : ELSE
2648 : {
2649 61322 : stereo_type_detect->left_bb_power_fx = Madd_32_32( L_shr( temp, sub( q_Left_Right_power, stereo_type_detect->q_left_bb_power ) ), b_fx, stereo_type_detect->left_bb_power_fx ); // stereo_type_detect->q_left_bb_power
2650 61322 : move32();
2651 : }
2652 :
2653 61933 : temp = Mpy_32_32( a_fx, right_bb_power_fx ); // q_Left_Right_power
2654 61933 : IF( LT_16( q_Left_Right_power, stereo_type_detect->q_right_bb_power ) )
2655 : {
2656 611 : stereo_type_detect->right_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ), sub( stereo_type_detect->q_right_bb_power, q_Left_Right_power ) ) ); // q_Left_Right_power
2657 611 : move32();
2658 611 : stereo_type_detect->q_right_bb_power = q_Left_Right_power;
2659 611 : move16();
2660 : }
2661 : ELSE
2662 : {
2663 61322 : stereo_type_detect->right_bb_power_fx = Madd_32_32( L_shr( temp, sub( q_Left_Right_power, stereo_type_detect->q_right_bb_power ) ), b_fx, stereo_type_detect->right_bb_power_fx ); // stereo_type_detect->q_right_bb_power
2664 61322 : move32();
2665 : }
2666 :
2667 61933 : temp = Mpy_32_32( a_fx, total_bb_power_fx ); // q_Left_Right_power
2668 61933 : IF( LT_16( q_Left_Right_power, stereo_type_detect->q_total_bb_power ) )
2669 : {
2670 611 : stereo_type_detect->total_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ), sub( stereo_type_detect->q_total_bb_power, q_Left_Right_power ) ) ); // q_Left_Right_power
2671 611 : move32();
2672 611 : stereo_type_detect->q_total_bb_power = q_Left_Right_power;
2673 611 : move16();
2674 : }
2675 : ELSE
2676 : {
2677 61322 : stereo_type_detect->total_bb_power_fx = Madd_32_32( L_shr( temp, sub( q_Left_Right_power, stereo_type_detect->q_total_bb_power ) ), b_fx, stereo_type_detect->total_bb_power_fx ); // stereo_type_detect->q_total_bb_power
2678 61322 : move32();
2679 : }
2680 :
2681 61933 : IF( LT_16( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) )
2682 : {
2683 0 : lr_bb_power_fx = L_min( stereo_type_detect->left_bb_power_fx, L_shr( stereo_type_detect->right_bb_power_fx, sub( stereo_type_detect->q_right_bb_power, stereo_type_detect->q_left_bb_power ) ) ); // stereo_type_detect->q_left_bb_power
2684 0 : move32();
2685 0 : q_lr_bb_power = stereo_type_detect->q_left_bb_power;
2686 0 : move16();
2687 : }
2688 : ELSE
2689 : {
2690 61933 : lr_bb_power_fx = L_min( L_shr( stereo_type_detect->left_bb_power_fx, sub( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ), stereo_type_detect->right_bb_power_fx ); // stereo_type_detect->q_right_bb_power
2691 61933 : move32();
2692 61933 : q_lr_bb_power = stereo_type_detect->q_right_bb_power;
2693 61933 : move16();
2694 : }
2695 61933 : q_lr_bb_power = sub( q_lr_bb_power, 1 ); /* = (lr_bb_power_fx * 2) */
2696 61933 : temp = BASOP_Util_Divide3232_Scale_newton( lr_bb_power_fx, L_add( stereo_type_detect->total_bb_power_fx, EPSILON_FX ), &exp ); // Q(31-(exp+stereo_type_detect->q_total_bb_power-q_lr_bb_power))
2697 61933 : exp = sub( 31, add( sub( 31, exp ), sub( q_lr_bb_power, stereo_type_detect->q_total_bb_power ) ) );
2698 61933 : temp = BASOP_Util_Log2( temp ); // q25
2699 61933 : IF( NE_32( temp, MIN_32 ) )
2700 : {
2701 61926 : temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25
2702 : }
2703 : // 20480 = 10 in Q11
2704 61933 : lr_total_bb_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21
2705 :
2706 : #ifdef FIX_867_CLDFB_NRG_SCALE
2707 61933 : stereo_type_detect->left_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, left_hi_power_fx ), sub( 31, q_temp_total ), Mpy_32_32( b2_fx, stereo_type_detect->left_hi_power_fx ), sub( 31, stereo_type_detect->q_left_hi_power ), &stereo_type_detect->q_left_hi_power );
2708 61933 : move32();
2709 61933 : stereo_type_detect->q_left_hi_power = sub( 31, stereo_type_detect->q_left_hi_power );
2710 61933 : move16();
2711 61933 : stereo_type_detect->right_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, right_hi_power_fx ), sub( 31, q_temp_total ), Mpy_32_32( b2_fx, stereo_type_detect->right_hi_power_fx ), sub( 31, stereo_type_detect->q_right_hi_power ), &stereo_type_detect->q_right_hi_power );
2712 61933 : move32();
2713 61933 : stereo_type_detect->q_right_hi_power = sub( 31, stereo_type_detect->q_right_hi_power );
2714 61933 : move16();
2715 61933 : stereo_type_detect->total_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, total_hi_power_fx ), sub( 31, q_temp_total ), Mpy_32_32( b2_fx, stereo_type_detect->total_hi_power_fx ), sub( 31, stereo_type_detect->q_total_hi_power ), &stereo_type_detect->q_total_hi_power );
2716 61933 : move32();
2717 : #else
2718 : stereo_type_detect->left_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, left_hi_power_fx ), sub( 31, q_temp ), Mpy_32_32( b2_fx, stereo_type_detect->left_hi_power_fx ), sub( 31, stereo_type_detect->q_left_hi_power ), &stereo_type_detect->q_left_hi_power );
2719 : move32();
2720 : stereo_type_detect->q_left_hi_power = sub( 31, stereo_type_detect->q_left_hi_power );
2721 : move16();
2722 : stereo_type_detect->right_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, right_hi_power_fx ), sub( 31, q_temp ), Mpy_32_32( b2_fx, stereo_type_detect->right_hi_power_fx ), sub( 31, stereo_type_detect->q_right_hi_power ), &stereo_type_detect->q_right_hi_power );
2723 : move32();
2724 : stereo_type_detect->q_right_hi_power = sub( 31, stereo_type_detect->q_right_hi_power );
2725 : move16();
2726 : stereo_type_detect->total_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, total_hi_power_fx ), sub( 31, q_temp ), Mpy_32_32( b2_fx, stereo_type_detect->total_hi_power_fx ), sub( 31, stereo_type_detect->q_total_hi_power ), &stereo_type_detect->q_total_hi_power );
2727 : move32();
2728 : #endif
2729 61933 : stereo_type_detect->q_total_hi_power = sub( 31, stereo_type_detect->q_total_hi_power );
2730 61933 : move16();
2731 :
2732 61933 : IF( LT_16( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) )
2733 : {
2734 23509 : lr_hi_power_fx = L_min( stereo_type_detect->left_hi_power_fx, L_shr( stereo_type_detect->right_hi_power_fx, sub( stereo_type_detect->q_right_hi_power, stereo_type_detect->q_left_hi_power ) ) ); // stereo_type_detect->q_left_hi_power
2735 23509 : move32();
2736 23509 : q_lr_hi_power = stereo_type_detect->q_left_hi_power;
2737 : }
2738 : ELSE
2739 : {
2740 38424 : lr_hi_power_fx = L_min( L_shr( stereo_type_detect->left_hi_power_fx, sub( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ), stereo_type_detect->right_hi_power_fx ); // stereo_type_detect->q_right_hi_power
2741 38424 : move32();
2742 38424 : q_lr_hi_power = stereo_type_detect->q_right_hi_power;
2743 : }
2744 61933 : q_lr_hi_power = sub( q_lr_hi_power, 1 ); /* = (q_lr_hi_power * 2) */
2745 61933 : temp = BASOP_Util_Divide3232_Scale_newton( lr_hi_power_fx, L_add( stereo_type_detect->total_hi_power_fx, EPSILON_FX ), &exp ); // Q=31-(exp+ stereo_type_detect->q_total_hi_power-q_lr_hi_power)
2746 61933 : exp = sub( 31, add( sub( 31, exp ), sub( q_lr_hi_power, stereo_type_detect->q_total_hi_power ) ) );
2747 61933 : temp = BASOP_Util_Log2( temp ); // q25
2748 61933 : IF( NE_32( temp, MIN_32 ) )
2749 : {
2750 61926 : temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25
2751 : }
2752 : // 20480 = 10 in Q11
2753 61933 : lr_total_hi_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21
2754 :
2755 61933 : minimum_l( sum_total_ratio_fx, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio_fx ); // q_sum_total_ratio
2756 61933 : exp = sub( 31, q_sum_total_ratio );
2757 61933 : temp = BASOP_Util_Log2( min_sum_total_ratio_fx ); // q25
2758 61933 : IF( NE_32( temp, MIN_32 ) )
2759 : {
2760 61933 : temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25
2761 : }
2762 : // 20480 = 10 in Q11
2763 61933 : min_sum_total_ratio_db_fx = Mpy_32_16_1( temp, 20480 ); // Q21
2764 :
2765 61933 : stereo_type_detect->lr_total_bb_ratio_db_fx = lr_total_bb_ratio_fx; // Q21
2766 61933 : move32();
2767 61933 : stereo_type_detect->lr_total_hi_ratio_db_fx = lr_total_hi_ratio_fx; // Q21
2768 61933 : move32();
2769 61933 : stereo_type_detect->min_sum_total_ratio_db_fx = min_sum_total_ratio_db_fx; // Q21
2770 61933 : move32();
2771 :
2772 61933 : ivas_masa_stereotype_detection_fx( stereo_type_detect );
2773 : }
2774 : ELSE
2775 : {
2776 19244 : p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * num_freq_bands * 4 ); // q_proto_direct_buffer_f
2777 :
2778 : #ifdef FIX_867_CLDFB_NRG_SCALE
2779 19244 : q_temp[0] = sub( add( add( q_cldfb, min_q_shift[0] ), add( q_cldfb, min_q_shift[0] ) ), 31 );
2780 19244 : q_temp[1] = sub( add( add( q_cldfb, min_q_shift[1] ), add( q_cldfb, min_q_shift[1] ) ), 31 );
2781 : #else
2782 : q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
2783 : #endif
2784 :
2785 1077884 : FOR( l = 0; l < num_freq_bands; l++ )
2786 : {
2787 : #ifdef FIX_867_CLDFB_NRG_SCALE
2788 1058640 : Word16 qidx = s_min( 1, s_max( 0, sub( l, CLDFB_NO_CHANNELS_HALF - 1 ) ) );
2789 1058640 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+ min_q_shift
2790 1058640 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+ min_q_shift
2791 1058640 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+ min_q_shift
2792 1058640 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+ min_q_shift
2793 : #else
2794 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+ min_q_shift
2795 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+ min_q_shift
2796 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+ min_q_shift
2797 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+ min_q_shift
2798 : #endif
2799 :
2800 1058640 : Real_aux_fx = L_add( re1, re2 ); // q_cldfb+ min_q_shift
2801 1058640 : Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+ min_q_shift
2802 :
2803 : // reference_power_fx[l] = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx );
2804 1058640 : reference_power_64fx[l] = W_add( W_mult0_32_32( Real_aux_fx, Real_aux_fx ), W_mult0_32_32( Imag_aux_fx, Imag_aux_fx ) ); // q_temp
2805 1058640 : move64();
2806 :
2807 : #ifdef FIX_867_CLDFB_NRG_SCALE
2808 1058640 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2809 : #else
2810 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2811 : #endif
2812 : {
2813 : #ifdef FIX_867_CLDFB_NRG_SCALE
2814 741660 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // q_temp
2815 : #else
2816 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // q_temp
2817 : #endif
2818 741660 : move32();
2819 : }
2820 : ELSE
2821 : {
2822 : #ifdef FIX_867_CLDFB_NRG_SCALE
2823 316980 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( W_extract_l( W_shr( reference_power_64fx[l], 31 ) ), sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2824 : #else
2825 : proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( W_extract_l( W_shr( reference_power_64fx[l], 31 ) ), sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2826 : #endif
2827 316980 : move32();
2828 : }
2829 :
2830 1058640 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+ min_q_shift
2831 1058640 : move32();
2832 1058640 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+ min_q_shift
2833 1058640 : move32();
2834 :
2835 1058640 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( re1, re2 ); // q_cldfb+ min_q_shift
2836 1058640 : move32();
2837 1058640 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_sub( im1, im2 ); // q_cldfb+ min_q_shift
2838 1058640 : move32();
2839 :
2840 1058640 : temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // q_temp
2841 : #ifdef FIX_867_CLDFB_NRG_SCALE
2842 1058640 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2843 : #else
2844 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2845 : #endif
2846 : {
2847 : #ifdef FIX_867_CLDFB_NRG_SCALE
2848 741660 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( q_proto_power_smooth[qidx], q_temp[qidx] ) ), temp ); // q_temp
2849 : #else
2850 : proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2851 : #endif
2852 741660 : move32();
2853 : }
2854 : ELSE
2855 : {
2856 : #ifdef FIX_867_CLDFB_NRG_SCALE
2857 316980 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp[qidx], q_proto_power_smooth[qidx] ) ) ); // q_proto_power_smooth
2858 : #else
2859 : proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth
2860 : #endif
2861 316980 : move32();
2862 : }
2863 :
2864 1058640 : proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+ min_q_shift
2865 1058640 : move32();
2866 1058640 : proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+ min_q_shift
2867 1058640 : move32();
2868 :
2869 1058640 : proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+ min_q_shift
2870 1058640 : move32();
2871 1058640 : proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+ min_q_shift
2872 1058640 : move32();
2873 1058640 : proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+ min_q_shift
2874 1058640 : move32();
2875 1058640 : proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+ min_q_shift
2876 1058640 : move32();
2877 : }
2878 : }
2879 : #ifdef FIX_867_CLDFB_NRG_SCALE
2880 175029 : q_reference_power_64fx = shl( add( q_cldfb, min_q_shift[0] ), 1 );
2881 :
2882 175029 : Word16 norm_shift = 63;
2883 175029 : move16();
2884 5353899 : FOR( l = 0; l < s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ); l++ )
2885 : {
2886 5178870 : IF( reference_power_64fx[l] )
2887 : {
2888 5177551 : norm_shift = s_min( norm_shift, W_norm( reference_power_64fx[l] ) );
2889 : }
2890 : }
2891 5353899 : FOR( l = 0; l < s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ); l++ )
2892 : {
2893 5178870 : reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); // q_reference_power_64fx+norm_shift-32
2894 5178870 : move32();
2895 : }
2896 175029 : q_reference_power[0] = sub( add( q_reference_power_64fx, norm_shift ), 32 );
2897 175029 : move16();
2898 :
2899 175029 : q_reference_power_64fx = shl( add( q_cldfb, min_q_shift[1] ), 1 );
2900 175029 : norm_shift = 63;
2901 175029 : move16();
2902 4865959 : FOR( l = CLDFB_NO_CHANNELS_HALF; l < num_freq_bands; l++ )
2903 : {
2904 4690930 : IF( reference_power_64fx[l] )
2905 : {
2906 4689684 : norm_shift = s_min( norm_shift, W_norm( reference_power_64fx[l] ) );
2907 : }
2908 : }
2909 4865959 : FOR( l = CLDFB_NO_CHANNELS_HALF; l < num_freq_bands; l++ )
2910 : {
2911 4690930 : reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); // q_reference_power_64fx+norm_shift-32
2912 4690930 : move32();
2913 : }
2914 175029 : q_reference_power[1] = sub( add( q_reference_power_64fx, norm_shift ), 32 );
2915 175029 : move16();
2916 : #else
2917 : q_reference_power_64fx = shl( add( q_cldfb, min_q_shift ), 1 );
2918 : Word16 norm_shift = 63;
2919 : move16();
2920 : FOR( l = 0; l < num_freq_bands; l++ )
2921 : {
2922 : IF( reference_power_64fx[l] )
2923 : {
2924 : norm_shift = s_min( norm_shift, W_norm( reference_power_64fx[l] ) );
2925 : }
2926 : }
2927 : FOR( l = 0; l < num_freq_bands; l++ )
2928 : {
2929 : reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); // q_reference_power_64fx+norm_shift-32
2930 : move32();
2931 : }
2932 : *q_reference_power = sub( add( q_reference_power_64fx, norm_shift ), 32 );
2933 : move16();
2934 : #endif
2935 :
2936 : #ifdef FIX_867_CLDFB_NRG_SCALE
2937 175029 : IF( GT_16( min_q_shift[0], min_q_shift[1] ) )
2938 : {
2939 8 : FOR( l = 0; l < i_mult( num_proto, num_freq_bands ); l += num_freq_bands )
2940 : {
2941 6 : Scale_sig32( proto_frame_f_fx + shl( l, 1 ), shl( s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ), 1 ), sub( min_q_shift[1], min_q_shift[0] ) );
2942 : }
2943 2 : *q_proto_frame_f = add( q_cldfb, min_q_shift[1] );
2944 2 : move16();
2945 : }
2946 : ELSE
2947 : {
2948 618931 : FOR( l = 0; l < i_mult( num_proto, num_freq_bands ); l += num_freq_bands )
2949 : {
2950 443904 : Scale_sig32( proto_frame_f_fx + shl( add( l, CLDFB_NO_CHANNELS_HALF ), 1 ), shl( s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), 1 ), sub( min_q_shift[0], min_q_shift[1] ) );
2951 : }
2952 175027 : *q_proto_frame_f = add( q_cldfb, min_q_shift[0] );
2953 175027 : move16();
2954 : }
2955 175029 : IF( GT_16( min_q_shift[0], min_q_shift[1] ) )
2956 : {
2957 8 : FOR( l = 0; l < i_mult( num_proto, num_freq_bands ); l += num_freq_bands )
2958 : {
2959 6 : Scale_sig32( p_proto_buffer_fx + shl( l, 1 ), shl( s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ), 1 ), sub( min_q_shift[1], min_q_shift[0] ) );
2960 : }
2961 2 : *q_proto_direct_buffer_f = add( q_cldfb, min_q_shift[1] );
2962 2 : move16();
2963 : }
2964 : ELSE
2965 : {
2966 618931 : FOR( l = 0; l < i_mult( num_proto, num_freq_bands ); l += num_freq_bands )
2967 : {
2968 443904 : Scale_sig32( p_proto_buffer_fx + shl( add( l, CLDFB_NO_CHANNELS_HALF ), 1 ), shl( s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), 1 ), sub( min_q_shift[0], min_q_shift[1] ) );
2969 : }
2970 175027 : *q_proto_direct_buffer_f = add( q_cldfb, min_q_shift[0] );
2971 175027 : move16();
2972 : }
2973 : #else
2974 : *q_proto_frame_f = add( q_cldfb, min_q_shift );
2975 : move16();
2976 : *q_proto_direct_buffer_f = add( q_cldfb, min_q_shift );
2977 : move16();
2978 : #endif
2979 : #ifdef FIX_867_CLDFB_NRG_SCALE
2980 175029 : q_proto_power_smooth[0] = s_min( q_proto_power_smooth[0], q_temp[0] );
2981 175029 : q_proto_power_smooth[1] = s_min( q_proto_power_smooth[1], q_temp[1] );
2982 175029 : move16();
2983 175029 : move16();
2984 : #else
2985 : *q_proto_power_smooth = s_min( *q_proto_power_smooth, q_temp );
2986 : move16();
2987 : #endif
2988 :
2989 175029 : return;
2990 : }
2991 :
2992 :
2993 : /*-------------------------------------------------------------------------
2994 : * protoSignalComputation4()
2995 : *
2996 : *
2997 : *-------------------------------------------------------------------------*/
2998 :
2999 72000 : void protoSignalComputation4_fx(
3000 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3001 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3002 : Word32 *proto_frame_f_fx, /*proto_frame_f_q*/
3003 : Word16 *proto_frame_f_q,
3004 : Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/
3005 : Word16 *proto_direct_buffer_f_q,
3006 : Word32 *reference_power_fx, /*reference_power_q*/
3007 : Word16 *reference_power_q,
3008 : Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/
3009 : Word16 *proto_power_smooth_q,
3010 : const Word16 slot_index,
3011 : const Word16 num_outputs_diff,
3012 : const Word16 num_freq_bands,
3013 : const Word32 *mtx_hoa_decoder, /*q29*/
3014 : const Word16 nchan_transport,
3015 : const Word16 *sba_map_tc_ind,
3016 : Word16 q_cldfb )
3017 : {
3018 : Word16 k, l, idx, idx2;
3019 : Word16 n, offset;
3020 : Word32 sq_tmp_fx;
3021 : Word32 *p_proto_buffer_fx;
3022 : Word16 min_q_shift, q_shift;
3023 : #ifdef FIX_867_CLDFB_NRG_SCALE
3024 : Word16 min_q_shift2, q_shift2;
3025 : #endif
3026 : Word32 re, im;
3027 : Word16 proto_power_smooth_fx_q, sq_tmp_q;
3028 :
3029 72000 : min_q_shift = Q31;
3030 72000 : move16();
3031 72000 : q_shift = Q31;
3032 72000 : move16();
3033 : #ifdef FIX_867_CLDFB_NRG_SCALE
3034 72000 : min_q_shift2 = Q31;
3035 72000 : move16();
3036 72000 : q_shift2 = Q31;
3037 72000 : move16();
3038 : #endif
3039 72000 : sq_tmp_q = 0;
3040 72000 : move16();
3041 :
3042 72000 : set_zero_fx( reference_power_fx, num_freq_bands );
3043 :
3044 : /* calculate the shift possible for both RealBuffer_fx and ImagBuffer_fx buffers*/
3045 367040 : FOR( k = 0; k < s_max( 4, nchan_transport ); k++ )
3046 : {
3047 : #ifdef FIX_867_CLDFB_NRG_SCALE
3048 295040 : q_shift = L_norm_arr( RealBuffer_fx[k][0], s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ) );
3049 295040 : min_q_shift = s_min( q_shift, min_q_shift );
3050 295040 : q_shift = L_norm_arr( ImagBuffer_fx[k][0], s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ) );
3051 295040 : min_q_shift = s_min( q_shift, min_q_shift );
3052 295040 : q_shift2 = L_norm_arr( RealBuffer_fx[k][0] + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
3053 295040 : min_q_shift2 = s_min( q_shift2, min_q_shift2 );
3054 295040 : q_shift2 = L_norm_arr( ImagBuffer_fx[k][0] + CLDFB_NO_CHANNELS_HALF, s_max( 0, sub( num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ) );
3055 295040 : min_q_shift2 = s_min( q_shift2, min_q_shift2 );
3056 : #else
3057 : q_shift = L_norm_arr( RealBuffer_fx[k][0], num_freq_bands );
3058 : min_q_shift = s_min( q_shift, min_q_shift );
3059 : q_shift = L_norm_arr( ImagBuffer_fx[k][0], num_freq_bands );
3060 : min_q_shift = s_min( q_shift, min_q_shift );
3061 : #endif
3062 : }
3063 72000 : q_shift = min_q_shift;
3064 72000 : min_q_shift = sub( min_q_shift, find_guarded_bits_fx( i_mult( 2, 4 ) ) );
3065 : #ifdef FIX_867_CLDFB_NRG_SCALE
3066 72000 : q_shift2 = min_q_shift2;
3067 72000 : min_q_shift2 = sub( min_q_shift2, find_guarded_bits_fx( i_mult( 2, 4 ) ) );
3068 : #endif
3069 :
3070 360000 : FOR( k = 0; k < 4; k++ )
3071 : {
3072 : #ifdef FIX_867_CLDFB_NRG_SCALE
3073 8928000 : FOR( l = 0; l < s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ); l++ )
3074 : {
3075 8640000 : re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
3076 8640000 : im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
3077 :
3078 8640000 : sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
3079 :
3080 8640000 : reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 /*0.5 in Q15*/ ); // 2*(q_cldfb+min_q_shift)-31
3081 8640000 : move32();
3082 : }
3083 8928000 : FOR( l = CLDFB_NO_CHANNELS_HALF; l < num_freq_bands; l++ )
3084 : {
3085 8640000 : re = L_shl( RealBuffer_fx[k][0][l], min_q_shift2 ); // q_cldfb+min_q_shift
3086 8640000 : im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift2 ); // q_cldfb+min_q_shift
3087 :
3088 8640000 : sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
3089 :
3090 8640000 : reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 /*0.5 in Q15*/ ); // 2*(q_cldfb+min_q_shift)-31
3091 8640000 : move32();
3092 : }
3093 : #else
3094 : FOR( l = 0; l < num_freq_bands; l++ )
3095 : {
3096 : re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
3097 : im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
3098 :
3099 : sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
3100 :
3101 : reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 /*0.5 in Q15*/ ); // 2*(q_cldfb+min_q_shift)-31
3102 : move32();
3103 : }
3104 : #endif
3105 : }
3106 : #ifdef FIX_867_CLDFB_NRG_SCALE
3107 72000 : sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3108 72000 : reference_power_q[0] = sq_tmp_q;
3109 72000 : move16();
3110 72000 : sq_tmp_q = sub( add( add( q_cldfb, min_q_shift2 ), add( q_cldfb, min_q_shift2 ) ), 31 );
3111 72000 : reference_power_q[1] = sq_tmp_q;
3112 72000 : move16();
3113 :
3114 72000 : min_q_shift = sub( s_min( q_shift, q_shift2 ), find_guarded_bits_fx( 2 ) );
3115 : #else
3116 : sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3117 : *reference_power_q = sub( add( sq_tmp_q, Q15 ), 15 );
3118 : move16();
3119 :
3120 : min_q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) );
3121 : #endif
3122 :
3123 : /*For decorrelated diffuseness*/
3124 784000 : FOR( l = 0; l < num_outputs_diff; l++ )
3125 : {
3126 43432000 : FOR( k = 0; k < num_freq_bands; k++ )
3127 : {
3128 42720000 : idx = add( i_mult( i_mult( 2, l ), num_freq_bands ), i_mult( 2, k ) );
3129 42720000 : proto_frame_f_fx[idx] = 0;
3130 42720000 : move32();
3131 42720000 : proto_frame_f_fx[idx + 1] = 0;
3132 42720000 : move32();
3133 218246400 : FOR( n = 0; n < nchan_transport; n++ )
3134 : {
3135 175526400 : idx2 = add( i_mult( l, 16 ), sba_map_tc_ind[n] );
3136 :
3137 175526400 : re = L_shl( RealBuffer_fx[n][0][k], min_q_shift ); // q_cldfb+min_q_shift
3138 175526400 : im = L_shl( ImagBuffer_fx[n][0][k], min_q_shift ); // q_cldfb+min_q_shift
3139 :
3140 175526400 : proto_frame_f_fx[idx] = Madd_32_32( proto_frame_f_fx[idx], re, mtx_hoa_decoder[idx2] ); // q_cldfb+min_q_shift+29-31 => q_cldfb+min_q_shift-2
3141 175526400 : move32();
3142 175526400 : proto_frame_f_fx[idx + 1] = Madd_32_32( proto_frame_f_fx[idx + 1], im, mtx_hoa_decoder[idx2] ); // q_cldfb+min_q_shift-2
3143 175526400 : move32();
3144 : }
3145 : }
3146 : }
3147 72000 : *proto_frame_f_q = sub( add( add( min_q_shift, q_cldfb ), Q29 ), 31 );
3148 72000 : move16();
3149 :
3150 : /* calculate the shift possible to up scale the buffer proto_power_smooth_fx*/
3151 72000 : min_q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ) );
3152 72000 : min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) );
3153 :
3154 72000 : Scale_sig32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ), min_q_shift ); // proto_power_smooth_q+min_q_shift
3155 72000 : *proto_power_smooth_q = add( *proto_power_smooth_q, min_q_shift );
3156 72000 : move16();
3157 72000 : proto_power_smooth_fx_q = *proto_power_smooth_q;
3158 72000 : move16();
3159 :
3160 : /* calculate the shift possible to up scale the values of the buffer proto_frame_f_fx*/
3161 72000 : min_q_shift = getScaleFactor32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ) );
3162 72000 : min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) );
3163 :
3164 72000 : Scale_sig32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ), min_q_shift ); // proto_frame_f_q+min_q_shift
3165 72000 : *proto_frame_f_q = add( *proto_frame_f_q, min_q_shift );
3166 72000 : move16();
3167 :
3168 72000 : offset = i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) );
3169 72000 : p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; // proto_direct_buffer_f_q
3170 :
3171 784000 : FOR( k = 0; k < num_outputs_diff; k++ )
3172 : {
3173 43432000 : FOR( l = 0; l < num_freq_bands; l++ )
3174 : {
3175 42720000 : idx = 2 * ( k * num_freq_bands + l );
3176 :
3177 42720000 : sq_tmp_fx = Madd_32_32( Mpy_32_32( proto_frame_f_fx[idx], proto_frame_f_fx[idx] ), proto_frame_f_fx[idx + 1], proto_frame_f_fx[idx + 1] ); // 2*(proto_frame_f_q)-31
3178 42720000 : sq_tmp_q = sub( add( *proto_frame_f_q, *proto_frame_f_q ), 31 );
3179 :
3180 42720000 : IF( LT_16( *proto_power_smooth_q, sq_tmp_q ) )
3181 : {
3182 8328480 : proto_power_smooth_fx[l + ( k * num_freq_bands )] = L_add( proto_power_smooth_fx[l + ( k * num_freq_bands )], L_shr( sq_tmp_fx, sub( sq_tmp_q, *proto_power_smooth_q ) ) ); // proto_power_smooth_q
3183 8328480 : move32();
3184 8328480 : proto_power_smooth_fx_q = *proto_power_smooth_q;
3185 8328480 : move16();
3186 : }
3187 : ELSE
3188 : {
3189 34391520 : proto_power_smooth_fx[l + ( k * num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[l + ( k * num_freq_bands )], sub( *proto_power_smooth_q, sq_tmp_q ) ), sq_tmp_fx ); // sq_tmp_q
3190 34391520 : move32();
3191 34391520 : proto_power_smooth_fx_q = sq_tmp_q;
3192 34391520 : move16();
3193 : }
3194 :
3195 42720000 : p_proto_buffer_fx[idx] = proto_frame_f_fx[idx]; // proto_frame_f_q
3196 42720000 : move32();
3197 42720000 : p_proto_buffer_fx[idx + 1] = proto_frame_f_fx[idx + 1]; // proto_frame_f_q
3198 42720000 : move32();
3199 : }
3200 : }
3201 :
3202 72000 : *proto_direct_buffer_f_q = *proto_frame_f_q;
3203 72000 : move16();
3204 : #ifdef FIX_867_CLDFB_NRG_SCALE
3205 72000 : proto_power_smooth_q[0] = proto_power_smooth_fx_q;
3206 72000 : proto_power_smooth_q[1] = proto_power_smooth_fx_q;
3207 72000 : move16();
3208 72000 : move16();
3209 : #else
3210 : *proto_power_smooth_q = proto_power_smooth_fx_q;
3211 : move16();
3212 : #endif
3213 :
3214 72000 : return;
3215 : }
3216 :
3217 :
3218 : /*-------------------------------------------------------------------------
3219 : * ivas_dirac_dec_compute_diffuse_proto()
3220 : *
3221 : * Compute diffuse prototype buffer and smooth power, only for decorrelated bands
3222 : *------------------------------------------------------------------------*/
3223 :
3224 346064 : void ivas_dirac_dec_compute_diffuse_proto_fx(
3225 : DIRAC_REND_HANDLE hDirACRend,
3226 : const Word16 num_freq_bands,
3227 : const Word16 slot_idx /* i : slot index */
3228 : )
3229 : {
3230 : Word16 k, l;
3231 : Word16 num_freq_bands_diff;
3232 : DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
3233 : DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
3234 : Word16 m;
3235 :
3236 : Word32 *proto_frame_dec_f_fx;
3237 : Word32 *p_diff_buffer_fx, *p_diff_buffer_1_fx;
3238 : Word32 *p_proto_diff_fx, *p_power_smooth_fx;
3239 : Word32 *p_hoa_enc_fx;
3240 :
3241 346064 : proto_frame_dec_f_fx = hDirACRend->proto_frame_dec_f_fx; // hDirACRend->proto_frame_dec_f_q
3242 346064 : h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
3243 346064 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
3244 :
3245 346064 : num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr;
3246 346064 : move16();
3247 :
3248 346064 : IF( num_freq_bands_diff == 0 )
3249 : {
3250 72000 : return;
3251 : }
3252 :
3253 274064 : p_diff_buffer_fx = h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + ( ( ( slot_idx * num_freq_bands_diff ) << 1 ) * hDirACRend->hOutSetup.nchan_out_woLFE ); // proto_diffuse_buffer_f_q
3254 274064 : p_diff_buffer_1_fx = p_diff_buffer_fx + 1;
3255 274064 : p_power_smooth_fx = h_dirac_output_synthesis_state->proto_power_diff_smooth_fx; // h_dirac_output_synthesis_state->proto_power_diff_smooth_q
3256 :
3257 274064 : Word16 diffuse_start = imult1616( slot_idx, shl( imult1616( num_freq_bands_diff, hDirACRend->hOutSetup.nchan_out_woLFE ), 1 ) );
3258 : Word16 diff_e, smooth_e, proto_e, max_e;
3259 : Word32 diff_square, diff_square_1, diff_square_sum;
3260 : Word16 diff_square_e;
3261 : Word16 old_diff_e;
3262 274064 : diff_e = sub( 31, h_dirac_output_synthesis_state->proto_diffuse_buffer_f_q );
3263 274064 : old_diff_e = diff_e;
3264 274064 : move16();
3265 274064 : smooth_e = sub( 31, h_dirac_output_synthesis_state->proto_power_diff_smooth_q );
3266 274064 : proto_e = sub( 31, hDirACRend->proto_frame_dec_f_q );
3267 :
3268 274064 : IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
3269 : {
3270 209936 : diff_square_e = add( shl( proto_e, 1 ), 1 );
3271 209936 : max_e = add( s_max( diff_square_e, smooth_e ), 1 );
3272 209936 : Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); // 31-max_e
3273 1682192 : FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ )
3274 : {
3275 1472256 : p_proto_diff_fx = proto_frame_dec_f_fx + shl( imult1616( k, num_freq_bands ), 1 ); // hDirACRend->proto_frame_dec_f_q
3276 23556096 : FOR( l = 0; l < num_freq_bands_diff; l++ )
3277 : {
3278 22083840 : *p_diff_buffer_fx = *( p_proto_diff_fx++ ); // hDirACRend->proto_frame_dec_f_q
3279 22083840 : move32();
3280 22083840 : *p_diff_buffer_1_fx = *( p_proto_diff_fx++ ); // hDirACRend->proto_frame_dec_f_q
3281 22083840 : move32();
3282 :
3283 22083840 : diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2 * proto_e + 1
3284 22083840 : diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2 * proto_e + 1
3285 22083840 : diff_square_sum = L_add( diff_square, diff_square_1 ); // Q(31- diff_square_e)
3286 22083840 : diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); // Q(31-max_e)
3287 22083840 : *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); // Q(31-max_e)
3288 22083840 : move32();
3289 :
3290 22083840 : p_power_smooth_fx++;
3291 22083840 : p_diff_buffer_fx += 2;
3292 22083840 : p_diff_buffer_1_fx += 2;
3293 : }
3294 : }
3295 209936 : diff_e = proto_e;
3296 209936 : move16();
3297 : }
3298 : ELSE
3299 : {
3300 : /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/
3301 64128 : Word16 gb = find_guarded_bits_fx( hDirACRend->num_outputs_diff );
3302 64128 : diff_square_e = add( shl( add( proto_e, gb ), 1 ), 1 );
3303 64128 : max_e = add( s_max( diff_square_e, smooth_e ), 1 );
3304 64128 : Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); // 31-max_e
3305 587040 : FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ )
3306 : {
3307 8366592 : FOR( l = 0; l < num_freq_bands_diff; l++ )
3308 : {
3309 7843680 : p_hoa_enc_fx = hDirACRend->hoa_encoder_fx + k; // q31
3310 7843680 : p_proto_diff_fx = proto_frame_dec_f_fx + shl( l, 1 ); // hDirACRend->proto_frame_dec_f_q
3311 :
3312 7843680 : *p_diff_buffer_fx = 0;
3313 7843680 : move32();
3314 7843680 : *p_diff_buffer_1_fx = 0;
3315 7843680 : move32();
3316 :
3317 : /*LS to HOA*/
3318 70593120 : FOR( m = 0; m < hDirACRend->num_outputs_diff; m++ )
3319 : {
3320 62749440 : *p_diff_buffer_fx = L_add( *p_diff_buffer_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *p_proto_diff_fx ), gb ) ); // hDirACRend->proto_frame_dec_f_q-gb
3321 62749440 : move32();
3322 62749440 : *p_diff_buffer_1_fx = L_add( *p_diff_buffer_1_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *( p_proto_diff_fx + 1 ) ), gb ) ); // hDirACRend->proto_frame_dec_f_q-gb
3323 62749440 : move32();
3324 62749440 : p_hoa_enc_fx += hDirACRend->hOutSetup.nchan_out_woLFE;
3325 62749440 : p_proto_diff_fx += shl( num_freq_bands, 1 );
3326 : }
3327 :
3328 7843680 : diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2*( proto_e + gb) + 1
3329 7843680 : diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2*( proto_e + gb) + 1
3330 7843680 : diff_square_sum = L_add( diff_square, diff_square_1 ); // 2*( proto_e + gb) + 1
3331 7843680 : diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); // 31-max_e
3332 7843680 : *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); // 31-max_e
3333 7843680 : move32();
3334 :
3335 7843680 : p_power_smooth_fx++;
3336 :
3337 7843680 : p_diff_buffer_fx += 2;
3338 7843680 : p_diff_buffer_1_fx += 2;
3339 : }
3340 : }
3341 64128 : diff_e = add( proto_e, gb );
3342 : }
3343 274064 : h_dirac_output_synthesis_state->proto_power_diff_smooth_q = sub( 31, max_e );
3344 274064 : move16();
3345 :
3346 274064 : Word16 new_diff_e = s_max( diff_e, old_diff_e );
3347 274064 : Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx, diffuse_start, sub( old_diff_e, new_diff_e ) ); // 31-new_diff_e
3348 274064 : Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start,
3349 274064 : i_mult( shl( num_freq_bands_diff, 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ), sub( diff_e, new_diff_e ) ); // 31-new_diff_e
3350 274064 : h_dirac_output_synthesis_state->proto_diffuse_buffer_f_q = sub( 31, new_diff_e );
3351 274064 : move16();
3352 :
3353 274064 : return;
3354 : }
3355 :
3356 :
3357 : /*-------------------------------------------------------------------------
3358 : * computeDirectionAngles()
3359 : *
3360 : *------------------------------------------------------------------------*/
3361 :
3362 694820 : void computeDirectionAngles_fx(
3363 : Word32 *intensity_real_x_fx, /*q_intensity_real*/
3364 : Word32 *intensity_real_y_fx, /*q_intensity_real*/
3365 : Word32 *intensity_real_z_fx, /*q_intensity_real*/
3366 : Word16 q_intensity_real,
3367 : const Word16 num_frequency_bands,
3368 : Word16 *azimuth,
3369 : Word16 *elevation )
3370 : {
3371 : Word16 k;
3372 : Word32 intensityNorm;
3373 : Word32 x, y, z, radius;
3374 : Word32 temp;
3375 : Word16 res, q_intensityNorm, exp, q_temp;
3376 : Word16 q_x, q_y, q_z, exp1, exp2, exp3, q_tmp1, q_tmp2;
3377 : Word32 x_re, y_re, z_re, tmp1, tmp2;
3378 :
3379 694820 : exp = 0;
3380 694820 : move16();
3381 :
3382 8337840 : FOR( k = 0; k < num_frequency_bands; ++k )
3383 : {
3384 7643020 : exp1 = norm_l( intensity_real_x_fx[k] );
3385 7643020 : exp2 = norm_l( intensity_real_y_fx[k] );
3386 7643020 : exp3 = norm_l( intensity_real_z_fx[k] );
3387 7643020 : x_re = L_shl( intensity_real_x_fx[k], exp1 ); /*q_intensity_real+exp1*/
3388 7643020 : y_re = L_shl( intensity_real_y_fx[k], exp2 ); /*q_intensity_real+exp2*/
3389 7643020 : z_re = L_shl( intensity_real_z_fx[k], exp3 ); /*q_intensity_real+exp3*/
3390 :
3391 7643020 : tmp1 = Mpy_32_32( x_re, x_re ); /*2*(q_intensity_real+exp1)-31*/
3392 7643020 : q_tmp1 = sub( add( add( q_intensity_real, exp1 ), add( q_intensity_real, exp1 ) ), 31 );
3393 7643020 : tmp2 = Mpy_32_32( y_re, y_re ); /*2*(q_intensity_real+exp2)-31*/
3394 7643020 : q_tmp2 = sub( add( add( q_intensity_real, exp2 ), add( q_intensity_real, exp2 ) ), 31 );
3395 :
3396 7643020 : temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); // 31-exp
3397 :
3398 7643020 : tmp2 = Mpy_32_32( z_re, z_re ); /*2*(q_intensity_real+exp3)-31*/
3399 7643020 : q_tmp2 = sub( add( add( q_intensity_real, exp3 ), add( q_intensity_real, exp3 ) ), 31 );
3400 :
3401 7643020 : intensityNorm = BASOP_Util_Add_Mant32Exp( temp, exp, tmp2, sub( 31, q_tmp2 ), &exp ); // 31-exp
3402 7643020 : q_intensityNorm = sub( 31, exp );
3403 :
3404 7643020 : IF( LE_32( intensityNorm, EPSILON_FX ) )
3405 : {
3406 24987 : intensityNorm = ONE_IN_Q30; // q30
3407 24987 : move32();
3408 24987 : x = ONE_IN_Q30; // q30
3409 24987 : move32();
3410 24987 : q_x = Q30;
3411 24987 : move16();
3412 24987 : y = 0;
3413 24987 : move32();
3414 24987 : q_y = Q30;
3415 24987 : move16();
3416 24987 : z = 0;
3417 24987 : move32();
3418 24987 : q_z = Q30;
3419 24987 : move16();
3420 : }
3421 : ELSE
3422 : {
3423 7618033 : temp = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q30, intensityNorm, &exp ); // Q=31-(exp-(30-q_intensityNorm))
3424 7618033 : exp = sub( exp, sub( Q30, q_intensityNorm ) );
3425 7618033 : temp = Sqrt32( temp, &exp ); // Q=31-exp
3426 7618033 : q_temp = sub( 31, exp );
3427 :
3428 7618033 : x = Mpy_32_32( x_re, temp ); /*Q=q_intensity_real+exp1+q_temp-31*/
3429 7618033 : q_x = sub( add( add( q_intensity_real, exp1 ), q_temp ), 31 );
3430 7618033 : y = Mpy_32_32( y_re, temp ); /*Q=q_intensity_real+exp2+q_temp-31*/
3431 7618033 : q_y = sub( add( add( q_intensity_real, exp2 ), q_temp ), 31 );
3432 7618033 : z = Mpy_32_32( z_re, temp ); /*Q=q_intensity_real+exp3+q_temp-31*/
3433 7618033 : q_z = sub( add( add( q_intensity_real, exp3 ), q_temp ), 31 );
3434 : }
3435 :
3436 7643020 : tmp1 = Mpy_32_32( x, x ); /*Q=2*q_x-31*/
3437 7643020 : q_tmp1 = sub( add( q_x, q_x ), 31 );
3438 :
3439 7643020 : tmp2 = Mpy_32_32( y, y ); /*Q=2*q_y-31*/
3440 7643020 : q_tmp2 = sub( add( q_y, q_y ), 31 );
3441 :
3442 7643020 : temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); // Q=31-exp
3443 7643020 : radius = Sqrt32( temp, &exp ); // Q=31-exp
3444 :
3445 7643020 : res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); /* Q13 */
3446 7643020 : res = add( s_max( -23040 /*-180 q7*/, s_min( 23040 /*180 q7*/, mult( res, _180_OVER_PI_Q9 /*180/pi q9*/ ) ) ), 64 /*0.5 q7*/ ); /* Q7 */
3447 7643020 : azimuth[k] = shr( abs_s( res ), Q7 ); /* Q0 */
3448 7643020 : move16();
3449 7643020 : IF( res < 0 )
3450 : {
3451 4641972 : azimuth[k] = negate( azimuth[k] );
3452 4641972 : move16();
3453 : }
3454 :
3455 7643020 : res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); /* Q13 */
3456 7643020 : res = add( s_max( -11520 /*-90 q7*/, s_min( 23040 /*180 q7*/, mult( res, _180_OVER_PI_Q9 /*180/pi q9*/ ) ) ), 64 /*0.5 q7*/ ); /* Q7 */
3457 7643020 : elevation[k] = shr( abs_s( res ), Q7 ); /* Q0 */
3458 7643020 : move16();
3459 7643020 : IF( res < 0 )
3460 : {
3461 3843156 : elevation[k] = negate( elevation[k] );
3462 3843156 : move16();
3463 : }
3464 : }
3465 :
3466 694820 : return;
3467 : }
3468 :
3469 :
3470 : /*-------------------------------------------------------------------------
3471 : * ivas_masa_init_stereotype_detection()
3472 : *
3473 : * Initialize stereo transport signal type detection
3474 : *------------------------------------------------------------------------*/
3475 :
3476 144 : void ivas_masa_init_stereotype_detection_fx(
3477 : MASA_STEREO_TYPE_DETECT *stereo_type_detect )
3478 : {
3479 144 : stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX;
3480 144 : move32();
3481 144 : stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX;
3482 144 : move32();
3483 144 : stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX;
3484 144 : move32();
3485 :
3486 144 : stereo_type_detect->counter = 0;
3487 144 : move16();
3488 144 : stereo_type_detect->interpolator = 0;
3489 144 : move16();
3490 :
3491 144 : stereo_type_detect->dipole_freq_range[0] = 1;
3492 144 : move16();
3493 144 : stereo_type_detect->dipole_freq_range[1] = 3;
3494 144 : move16();
3495 :
3496 144 : stereo_type_detect->left_bb_power_fx = 0; /* Broadband estimates */
3497 144 : move32();
3498 144 : stereo_type_detect->q_left_bb_power = Q31;
3499 144 : move16();
3500 144 : stereo_type_detect->right_bb_power_fx = 0;
3501 144 : move32();
3502 144 : stereo_type_detect->q_right_bb_power = Q31;
3503 144 : move16();
3504 144 : stereo_type_detect->total_bb_power_fx = 0;
3505 144 : move32();
3506 144 : stereo_type_detect->q_total_bb_power = Q31;
3507 144 : move16();
3508 :
3509 144 : stereo_type_detect->left_hi_power_fx = 0; /* High-frequency estimates */
3510 144 : move32();
3511 144 : stereo_type_detect->q_left_hi_power = Q31;
3512 144 : move16();
3513 144 : stereo_type_detect->right_hi_power_fx = 0;
3514 144 : move32();
3515 144 : stereo_type_detect->q_right_hi_power = Q31;
3516 144 : move16();
3517 144 : stereo_type_detect->total_hi_power_fx = 0;
3518 144 : move32();
3519 144 : stereo_type_detect->q_total_hi_power = Q31;
3520 144 : move16();
3521 :
3522 144 : set32_fx( stereo_type_detect->sum_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS );
3523 144 : set32_fx( stereo_type_detect->total_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS );
3524 :
3525 144 : stereo_type_detect->q_sum_power = Q31;
3526 144 : move16();
3527 144 : stereo_type_detect->q_total_power = Q31;
3528 144 : move16();
3529 :
3530 144 : stereo_type_detect->subtract_power_y_fx = 0;
3531 144 : move32();
3532 144 : stereo_type_detect->q_subtract_power_y = Q31;
3533 144 : move16();
3534 144 : stereo_type_detect->subtract_power_y_smooth_fx = 0;
3535 144 : move32();
3536 144 : stereo_type_detect->q_subtract_power_y_smooth = Q31;
3537 144 : move16();
3538 144 : stereo_type_detect->target_power_y_smooth_fx = 0;
3539 144 : move32();
3540 144 : stereo_type_detect->q_target_power_y_smooth = 31;
3541 144 : move16();
3542 :
3543 144 : stereo_type_detect->lr_total_bb_ratio_db_fx = 0;
3544 144 : move32();
3545 144 : stereo_type_detect->lr_total_hi_ratio_db_fx = 0;
3546 144 : move32();
3547 144 : stereo_type_detect->min_sum_total_ratio_db_fx = 0;
3548 144 : move32();
3549 144 : stereo_type_detect->subtract_target_ratio_db_fx = 0;
3550 144 : move32();
3551 :
3552 144 : return;
3553 : }
3554 :
3555 :
3556 : /*-------------------------------------------------------------------------
3557 : * ivas_masa_stereotype_detection()
3558 : *
3559 : * Detect the type of the transport audio signals
3560 : *------------------------------------------------------------------------*/
3561 :
3562 61933 : void ivas_masa_stereotype_detection_fx(
3563 : MASA_STEREO_TYPE_DETECT *stereo_type_detect )
3564 : {
3565 : Word32 lr_total_bb_ratio_db_fx;
3566 : Word32 lr_total_hi_ratio_db_fx;
3567 : Word32 min_sum_total_ratio_db_fx;
3568 : Word32 subtract_target_ratio_db_fx;
3569 : Word32 change_to_spaced_fx;
3570 : Word16 change_to_spaced_selection;
3571 : Word32 change_to_downmix_fx;
3572 : Word32 change_to_downmix2_fx;
3573 : Word16 change_to_downmix_selection;
3574 : Word32 subtract_temp_fx;
3575 : Word32 min_sum_temp_fx;
3576 : Word32 lr_total_bb_temp_fx;
3577 : Word32 lr_total_hi_temp_fx;
3578 : Word32 temp;
3579 :
3580 61933 : lr_total_bb_ratio_db_fx = stereo_type_detect->lr_total_bb_ratio_db_fx; // q21
3581 61933 : move32();
3582 61933 : lr_total_hi_ratio_db_fx = stereo_type_detect->lr_total_hi_ratio_db_fx; // q21
3583 61933 : move32();
3584 61933 : min_sum_total_ratio_db_fx = stereo_type_detect->min_sum_total_ratio_db_fx; // q21
3585 61933 : move32();
3586 61933 : subtract_target_ratio_db_fx = stereo_type_detect->subtract_target_ratio_db_fx; // q21
3587 61933 : move32();
3588 :
3589 : /* Determine if the determined features match the spaced mic type */
3590 61933 : change_to_spaced_selection = 0;
3591 61933 : move16();
3592 61933 : IF( LT_32( subtract_target_ratio_db_fx, -THREE_Q21 /*-3 q21*/ ) )
3593 : {
3594 : /* subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; */
3595 19564 : temp = L_sub( L_shr( -subtract_target_ratio_db_fx, 1 ), L_shr( THREE_Q21, 1 ) ); // q20
3596 19564 : subtract_temp_fx = Mpy_32_32( temp, 715827883 /* 1 / 3.0f in Q31 */ ); // q20
3597 19564 : subtract_temp_fx = L_shl( subtract_temp_fx, 1 ); /* Q21 */
3598 :
3599 : /* min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); */
3600 19564 : min_sum_temp_fx = Mpy_32_32_r( -min_sum_total_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */
3601 19564 : min_sum_temp_fx = L_max( min_sum_temp_fx, 0 ); /*q21*/
3602 :
3603 : /* lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; */
3604 19564 : lr_total_bb_temp_fx = Mpy_32_32_r( lr_total_bb_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */
3605 :
3606 19564 : change_to_spaced_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); /* Q21 */
3607 :
3608 19564 : IF( GE_32( change_to_spaced_fx, ONE_IN_Q21 ) )
3609 : {
3610 10457 : change_to_spaced_selection = 1;
3611 10457 : move16();
3612 : }
3613 : }
3614 :
3615 : /* Determine if the determined features match the downmix type, according to a metric */
3616 61933 : change_to_downmix_selection = 0;
3617 61933 : move16();
3618 61933 : IF( subtract_target_ratio_db_fx > 0 )
3619 : {
3620 : /* subtract_temp = subtract_target_ratio_db / 3.0f; */
3621 25571 : subtract_temp_fx = Mpy_32_32( subtract_target_ratio_db_fx, 715827883 /* 1 / 3.0f in Q31 */ ); /* Q21 */
3622 :
3623 : /* min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; */
3624 25571 : min_sum_temp_fx = Mpy_32_32_r( L_add( min_sum_total_ratio_db_fx, ONE_IN_Q21 ), 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */
3625 :
3626 : /* lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; */
3627 25571 : lr_total_bb_temp_fx = Mpy_32_32_r( -lr_total_bb_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */
3628 :
3629 25571 : change_to_downmix_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); /* Q21 */
3630 :
3631 25571 : IF( GE_32( change_to_downmix_fx, ONE_IN_Q21 /*1 q21*/ ) )
3632 : {
3633 13190 : change_to_downmix_selection = 1;
3634 13190 : move16();
3635 : }
3636 : }
3637 :
3638 : /* Determine if the determined features match the downmix type, according to another metric */
3639 61933 : IF( LT_32( lr_total_hi_ratio_db_fx, -25165824 ) ) // 25165824 = 12.0 in Q21
3640 : {
3641 : /* subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; */
3642 482 : subtract_temp_fx = Mpy_32_32( L_add( subtract_target_ratio_db_fx, 8388608 /* 4.0 in Q21 */ ), 715827883 /* 1 / 3.0f in Q31 */ );
3643 :
3644 : /* min_sum_temp = min_sum_total_ratio_db / 6.0f; */
3645 482 : min_sum_temp_fx = Mpy_32_32_r( min_sum_total_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ );
3646 :
3647 : /* lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; */
3648 482 : lr_total_hi_temp_fx = Mpy_32_32( L_sub( -lr_total_hi_ratio_db_fx, 25165824 /* 12.0 in Q21 */ ), 715827883 /* 1 / 3.0f in Q31 */ );
3649 :
3650 482 : change_to_downmix2_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_hi_temp_fx ); // Q21
3651 :
3652 482 : IF( GE_32( change_to_downmix2_fx, ONE_IN_Q21 /*1 q21*/ ) )
3653 : {
3654 454 : change_to_downmix_selection = 1;
3655 454 : move16();
3656 : }
3657 : }
3658 :
3659 61933 : IF( LT_16( stereo_type_detect->counter, 400 ) )
3660 : {
3661 19559 : stereo_type_detect->counter++;
3662 : }
3663 : ELSE
3664 : {
3665 42374 : IF( EQ_16( change_to_spaced_selection, 1 ) )
3666 : {
3667 8800 : stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS;
3668 8800 : move32();
3669 : }
3670 33574 : ELSE IF( EQ_16( change_to_downmix_selection, 1 ) )
3671 : {
3672 7715 : stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX;
3673 7715 : move32();
3674 : }
3675 : }
3676 :
3677 61933 : IF( stereo_type_detect->interpolator == 0 )
3678 : {
3679 61905 : IF( NE_16( stereo_type_detect->current_stereo_type, stereo_type_detect->masa_stereo_type ) )
3680 : {
3681 2 : stereo_type_detect->interpolator = 1;
3682 2 : move16();
3683 2 : stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type;
3684 2 : move32();
3685 : }
3686 : }
3687 :
3688 61933 : return;
3689 : }
3690 :
3691 :
3692 : /*-------------------------------------------------------------------------
3693 : * computeIntensityVector_dec()
3694 : *
3695 : *
3696 : *------------------------------------------------------------------------*/
3697 :
3698 694820 : void computeIntensityVector_dec_fx(
3699 : Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3700 : Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3701 : Word16 q_cldfb,
3702 : const Word16 num_frequency_bands,
3703 : Word32 *intensity_real_x_fx, /*q_intensity_real*/
3704 : Word32 *intensity_real_y_fx, /*q_intensity_real*/
3705 : Word32 *intensity_real_z_fx, /*q_intensity_real*/
3706 : Word16 *q_intensity_real )
3707 : {
3708 : /*
3709 : * W = a + ib; Y = c + id
3710 : * real(W*Y') = ac + bd
3711 : */
3712 : Word16 i;
3713 : Word32 re1, re2, im1, im2;
3714 : Word16 min_q_shift;
3715 :
3716 694820 : min_q_shift = Q31;
3717 694820 : move32();
3718 : /* calculate the max possible shift for the buffers Cldfb_RealBuffer_fx and Cldfb_ImagBuffer_fx*/
3719 3474100 : FOR( i = 0; i < 4; i++ )
3720 : {
3721 2779280 : min_q_shift = s_min( min_q_shift, s_min( L_norm_arr( Cldfb_RealBuffer_fx[i][0], num_frequency_bands ), L_norm_arr( Cldfb_ImagBuffer_fx[i][0], num_frequency_bands ) ) );
3722 : }
3723 :
3724 694820 : min_q_shift = sub( min_q_shift, 1 ); // guard bits
3725 :
3726 8337840 : FOR( i = 0; i < num_frequency_bands; ++i )
3727 : {
3728 7643020 : re1 = L_shl( Cldfb_RealBuffer_fx[0][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3729 7643020 : im1 = L_shl( Cldfb_ImagBuffer_fx[0][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3730 7643020 : re2 = L_shl( Cldfb_RealBuffer_fx[3][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3731 7643020 : im2 = L_shl( Cldfb_ImagBuffer_fx[3][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3732 :
3733 7643020 : intensity_real_x_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/
3734 7643020 : move32();
3735 :
3736 7643020 : re2 = L_shl( Cldfb_RealBuffer_fx[1][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3737 7643020 : im2 = L_shl( Cldfb_ImagBuffer_fx[1][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3738 :
3739 7643020 : intensity_real_y_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/
3740 7643020 : move32();
3741 :
3742 7643020 : re2 = L_shl( Cldfb_RealBuffer_fx[2][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3743 7643020 : im2 = L_shl( Cldfb_ImagBuffer_fx[2][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3744 :
3745 7643020 : intensity_real_z_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/
3746 7643020 : move32();
3747 : }
3748 :
3749 694820 : *q_intensity_real = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3750 694820 : move16();
3751 :
3752 694820 : return;
3753 : }
3754 :
3755 :
3756 : /*-------------------------------------------------------------------------
3757 : * ivas_lfe_synth_with_cldfb()
3758 : *
3759 : *
3760 : *------------------------------------------------------------------------*/
3761 :
3762 23440 : void ivas_lfe_synth_with_cldfb_fx(
3763 : MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth,
3764 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3765 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3766 : Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3767 : Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3768 : const Word16 slot_index,
3769 : const Word16 subframe_index,
3770 : const Word16 nchan_transport,
3771 : Word16 q_cldfb )
3772 : {
3773 : Word16 i;
3774 :
3775 : Word16 lfeGain_fx, transportGain_fx;
3776 : Word32 protoLfeReal_fx, protoLfeImag_fx;
3777 : Word32 transportEne_fx, protoLfeEne_fx, targetEneLfe_fx, targetEneTrans_fx;
3778 : Word16 transportEne_q, protoLfeEne_q, targetEneLfe_q, targetEneTrans_q;
3779 23440 : Word16 temp, temp_q = 0;
3780 : Word16 transportGain_q_fx, lfeGain_q_fx;
3781 : Word16 exp, min_q_shift;
3782 : Word32 re, im;
3783 23440 : move16(); // temp_q
3784 :
3785 23440 : exp = Q31;
3786 23440 : move16();
3787 23440 : min_q_shift = Q31;
3788 23440 : move16();
3789 :
3790 23440 : set_zero_fx( RealBufferLfe_fx[slot_index], CLDFB_NO_CHANNELS_MAX );
3791 23440 : set_zero_fx( ImagBufferLfe_fx[slot_index], CLDFB_NO_CHANNELS_MAX );
3792 :
3793 47360 : FOR( i = 0; i < nchan_transport; i++ )
3794 : {
3795 23920 : IF( RealBuffer_fx[i][0][0] )
3796 : {
3797 23908 : exp = norm_l( RealBuffer_fx[i][0][0] );
3798 : }
3799 23920 : min_q_shift = s_min( min_q_shift, exp );
3800 23920 : IF( ImagBuffer_fx[i][0][0] )
3801 : {
3802 23909 : exp = norm_l( ImagBuffer_fx[i][0][0] );
3803 : }
3804 23920 : min_q_shift = s_min( min_q_shift, exp );
3805 : }
3806 23440 : min_q_shift = sub( sub( min_q_shift, find_guarded_bits_fx( nchan_transport ) ), 1 );
3807 :
3808 23440 : re = L_shl( RealBuffer_fx[0][0][0], min_q_shift ); // q_cldfb+min_q_shift
3809 23440 : im = L_shl( ImagBuffer_fx[0][0][0], min_q_shift ); // q_cldfb+min_q_shift
3810 :
3811 23440 : protoLfeReal_fx = re; // q_cldfb+min_q_shift
3812 23440 : move32();
3813 23440 : protoLfeImag_fx = im; // q_cldfb+min_q_shift
3814 23440 : move32();
3815 23440 : transportEne_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
3816 23920 : FOR( i = 1; i < nchan_transport; i++ )
3817 : {
3818 480 : re = L_shl( RealBuffer_fx[i][0][0], min_q_shift ); // q_cldfb+min_q_shift
3819 480 : im = L_shl( ImagBuffer_fx[i][0][0], min_q_shift ); // q_cldfb+min_q_shift
3820 :
3821 480 : protoLfeReal_fx = L_add( protoLfeReal_fx, re ); // q_cldfb+min_q_shift
3822 480 : protoLfeImag_fx = L_add( protoLfeImag_fx, im ); // q_cldfb+min_q_shift
3823 480 : transportEne_fx = L_add( transportEne_fx, Madd_32_32( Mpy_32_32( re, re ), im, im ) ); // 2*(q_cldfb+min_q_shift)-31
3824 : }
3825 23440 : transportEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3826 :
3827 23440 : protoLfeEne_fx = Madd_32_32( Mpy_32_32( protoLfeReal_fx, protoLfeReal_fx ), protoLfeImag_fx, protoLfeImag_fx ); // 2*(q_cldfb+min_q_shift)-31
3828 23440 : protoLfeEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3829 :
3830 23440 : targetEneLfe_fx = Mpy_32_16_1( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ); // targetEneLfe_q+14-15
3831 23440 : targetEneLfe_q = sub( add( transportEne_q, Q14 ), 15 );
3832 :
3833 23440 : temp = s_max( sub( ONE_IN_Q14 /*1 q14*/, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 164 /*0.01 in Q14*/ ); // q14
3834 23440 : targetEneTrans_fx = Mpy_32_16_1( transportEne_fx, temp ); /*transportEne_q+Q14 -15*/
3835 23440 : targetEneTrans_q = sub( add( transportEne_q, Q14 ), 15 );
3836 :
3837 23440 : hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->transportEneSmooth_q+15-15
3838 23440 : move32();
3839 23440 : hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->protoLfeEneSmooth_q+15-15
3840 23440 : move32();
3841 23440 : hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->targetEneLfeSmooth_q+15-15
3842 23440 : move32();
3843 23440 : hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->targetEneTransSmooth_q+15-15
3844 23440 : move32();
3845 :
3846 23440 : hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( 31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( 31, transportEne_q ), &temp_q ); // 31-temp_q
3847 23440 : move32();
3848 23440 : hMasaLfeSynth->transportEneSmooth_q = sub( 31, temp_q );
3849 23440 : move16();
3850 :
3851 23440 : hMasaLfeSynth->protoLfeEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->protoLfeEneSmooth_fx, sub( 31, hMasaLfeSynth->protoLfeEneSmooth_q ), protoLfeEne_fx, sub( 31, protoLfeEne_q ), &temp_q ); // 31-temp_q
3852 23440 : move32();
3853 23440 : hMasaLfeSynth->protoLfeEneSmooth_q = sub( 31, temp_q );
3854 23440 : move16();
3855 :
3856 23440 : hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( 31, targetEneLfe_q ), &temp_q ); // 31-temp_q
3857 23440 : move32();
3858 23440 : hMasaLfeSynth->targetEneLfeSmooth_q = sub( 31, temp_q );
3859 23440 : move16();
3860 :
3861 23440 : hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( 31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( 31, targetEneTrans_q ), &temp_q ); // 31-temp_q
3862 23440 : move32();
3863 23440 : hMasaLfeSynth->targetEneTransSmooth_q = sub( 31, temp_q );
3864 23440 : move16();
3865 :
3866 23440 : temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->protoLfeEneSmooth_fx ), &temp_q ); // 15-(temp_q-(hMasaLfeSynth->targetEneLfeSmooth_q-hMasaLfeSynth->protoLfeEneSmooth_q))
3867 23440 : temp_q = add( sub( hMasaLfeSynth->targetEneLfeSmooth_q, hMasaLfeSynth->protoLfeEneSmooth_q ), sub( Q15, temp_q ) );
3868 :
3869 23440 : exp = sub( Q15, temp_q );
3870 23440 : lfeGain_fx = Sqrt16( temp, &exp ); // 15-exp
3871 23440 : lfeGain_q_fx = sub( Q15, exp );
3872 :
3873 23440 : IF( GT_32( L_shr( lfeGain_fx, sub( lfeGain_q_fx, Q14 ) ), ONE_IN_Q14 /*1 q14*/ ) )
3874 : {
3875 0 : lfeGain_fx = ONE_IN_Q14; /*1 q14*/
3876 0 : move16();
3877 0 : lfeGain_q_fx = Q14;
3878 0 : move16();
3879 : }
3880 :
3881 23440 : temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &temp_q ); // Q=15-(temp_q-(hMasaLfeSynth->targetEneTransSmooth_q-hMasaLfeSynth->transportEneSmooth_q))
3882 23440 : temp_q = add( sub( hMasaLfeSynth->targetEneTransSmooth_q, hMasaLfeSynth->transportEneSmooth_q ), sub( Q15, temp_q ) );
3883 :
3884 23440 : exp = sub( Q15, temp_q );
3885 23440 : transportGain_fx = Sqrt16( temp, &exp ); // q=15-exp
3886 23440 : transportGain_q_fx = sub( Q15, exp );
3887 :
3888 23440 : IF( GT_32( L_shr( transportGain_fx, sub( transportGain_q_fx, Q14 ) ), ONE_IN_Q14 /*1 q14*/ ) )
3889 : {
3890 0 : transportGain_fx = ONE_IN_Q14; /*1 q14*/
3891 0 : move16();
3892 0 : transportGain_q_fx = Q14;
3893 0 : move16();
3894 : }
3895 :
3896 23440 : RealBufferLfe_fx[slot_index][0] = L_shr( Mpy_32_16_1( protoLfeReal_fx, lfeGain_fx ), add( min_q_shift, sub( lfeGain_q_fx, Q15 ) ) ); // q_cldfb
3897 23440 : move32();
3898 23440 : ImagBufferLfe_fx[slot_index][0] = L_shr( Mpy_32_16_1( protoLfeImag_fx, lfeGain_fx ), add( min_q_shift, sub( lfeGain_q_fx, Q15 ) ) ); // q_cldfb
3899 23440 : move32();
3900 :
3901 23440 : RealBuffer_fx[0][0][0] = L_shr( Mpy_32_16_1( RealBuffer_fx[0][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb
3902 23440 : move32();
3903 23440 : ImagBuffer_fx[0][0][0] = L_shr( Mpy_32_16_1( ImagBuffer_fx[0][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb
3904 23440 : move32();
3905 23920 : FOR( i = 1; i < nchan_transport; i++ )
3906 : {
3907 480 : RealBuffer_fx[i][0][0] = L_shr( Mpy_32_16_1( RealBuffer_fx[i][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb
3908 480 : move32();
3909 480 : ImagBuffer_fx[i][0][0] = L_shr( Mpy_32_16_1( ImagBuffer_fx[i][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb
3910 480 : move32();
3911 : }
3912 :
3913 23440 : return;
3914 : }
3915 :
3916 :
3917 : /*-------------------------------------------------------------------------
3918 : * rotateAziEle_DirAC()
3919 : *
3920 : * Apply rotation to DirAC DOAs
3921 : *------------------------------------------------------------------------*/
3922 :
3923 147200 : void rotateAziEle_DirAC_fx(
3924 : Word16 *azi, /* i/o: array of azimuth values */
3925 : Word16 *ele, /* i/o: array of elevation values */
3926 : const Word16 band1, /* i : bands to work on (lower limit) */
3927 : const Word16 band2, /* i : bands to work on (upper bound) */
3928 : const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix q30*/
3929 : )
3930 : {
3931 : Word16 b;
3932 : Word32 dv_0_fx, dv_1_fx, dv_2_fx;
3933 : Word32 dv_r_0_fx, dv_r_1_fx, dv_r_2_fx, tmp, w_fx;
3934 : Word16 exp, temp;
3935 : Word32 *ptr_sin, *ptr_cos;
3936 :
3937 147200 : ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] q31
3938 147200 : ptr_cos = cosine_table_Q31; // q31
3939 :
3940 147200 : push_wmops( "rotateAziEle_DirAC" );
3941 :
3942 4160000 : FOR( b = band1; b < band2; b++ )
3943 : {
3944 : /*Conversion spherical to cartesian coordinates*/
3945 4012800 : IF( GT_16( abs_s( ele[b] ), 180 ) )
3946 : {
3947 : // cos(180 + x) = -cos(x)
3948 0 : w_fx = L_negate( ptr_cos[abs( ele[b] ) - 180] ); // Q31
3949 : }
3950 : ELSE
3951 : {
3952 4012800 : w_fx = ptr_cos[abs_s( ele[b] )]; // Q31
3953 4012800 : move32();
3954 : }
3955 :
3956 4012800 : IF( GT_16( abs_s( azi[b] ), 180 ) )
3957 : {
3958 : // cos(180 + x) = -cos(x)
3959 1931328 : tmp = L_negate( ptr_cos[abs( azi[b] ) - 180] ); // Q31
3960 : }
3961 : ELSE
3962 : {
3963 2081472 : tmp = ptr_cos[abs( azi[b] )]; // Q31
3964 2081472 : move32();
3965 : }
3966 :
3967 4012800 : dv_0_fx = Mpy_32_32( w_fx, tmp ); // Q31
3968 :
3969 :
3970 4012800 : IF( GT_16( azi[b], 180 ) )
3971 : {
3972 : // sin(180 + x) = -sin(x)
3973 1931328 : tmp = L_negate( ptr_sin[azi[b] - 180] ); // Q31
3974 1931328 : move32();
3975 : }
3976 2081472 : ELSE IF( LT_16( azi[b], -180 ) )
3977 : {
3978 : // sin(-(180 + x)) = sin(180 + x) = sinx
3979 0 : tmp = ptr_sin[abs( azi[b] ) - 180]; // Q31
3980 0 : move32();
3981 : }
3982 : ELSE
3983 : {
3984 2081472 : tmp = ptr_sin[azi[b]]; // Q31
3985 2081472 : move32();
3986 : }
3987 4012800 : dv_1_fx = Mpy_32_32( w_fx, tmp ); // Q31
3988 :
3989 4012800 : IF( GT_16( ele[b], 180 ) )
3990 : {
3991 : // sin(180 + x) = -sin(x)
3992 0 : dv_2_fx = L_negate( ptr_sin[ele[b] - 180] ); // Q31
3993 0 : move32();
3994 : }
3995 4012800 : ELSE IF( LT_16( ele[b], -180 ) )
3996 : {
3997 : // sin(-(180 + x)) = -sin(180 + x) = sinx
3998 0 : dv_2_fx = ptr_sin[abs( ele[b] ) - 180]; // Q31
3999 0 : move32();
4000 : }
4001 : ELSE
4002 : {
4003 4012800 : dv_2_fx = ptr_sin[ele[b]]; // Q31
4004 4012800 : move32();
4005 : }
4006 :
4007 4012800 : dv_r_0_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr( p_Rmat_fx[0], Q1 ), dv_0_fx ), L_shr( p_Rmat_fx[1], Q1 ), dv_1_fx ), L_shr( p_Rmat_fx[2], Q1 ), dv_2_fx ); // Q29
4008 4012800 : dv_r_1_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr( p_Rmat_fx[3], Q1 ), dv_0_fx ), L_shr( p_Rmat_fx[4], Q1 ), dv_1_fx ), L_shr( p_Rmat_fx[5], Q1 ), dv_2_fx ); // Q29
4009 4012800 : dv_r_2_fx = Madd_32_32( Madd_32_32( Mpy_32_32( L_shr( p_Rmat_fx[6], Q1 ), dv_0_fx ), L_shr( p_Rmat_fx[7], Q1 ), dv_1_fx ), L_shr( p_Rmat_fx[8], Q1 ), dv_2_fx ); // Q29
4010 :
4011 : /*Conversion spherical to cartesian coordinates*/
4012 4012800 : temp = BASOP_util_atan2( dv_r_1_fx, dv_r_0_fx, 0 ); // Q13
4013 4012800 : azi[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0;
4014 4012800 : move16();
4015 :
4016 4012800 : tmp = L_add( Mpy_32_32( dv_r_0_fx, dv_r_0_fx ), Mpy_32_32( dv_r_1_fx, dv_r_1_fx ) ); // Q27
4017 4012800 : exp = sub( 31, Q27 );
4018 4012800 : tmp = Sqrt32( tmp, &exp ); // q=31-exp
4019 4012800 : temp = BASOP_util_atan2( dv_r_2_fx, tmp, sub( sub( 31, 29 ), exp ) ); // Q13
4020 4012800 : ele[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0
4021 4012800 : move16();
4022 : }
4023 :
4024 147200 : pop_wmops();
4025 :
4026 147200 : return;
4027 : }
4028 :
4029 :
4030 : /* A reduced rewrite of the corresponding decoder side function */
4031 20400 : static void ivas_masa_ext_dirac_render_sf_fx(
4032 : MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */
4033 : Word32 *output_f_fx[] /* i/o: synthesized core-coder transport channels/DirAC output q11*/
4034 : )
4035 : {
4036 : Word16 i, ch, idx_in, idx_lfe;
4037 : DIRAC_REND_HANDLE hDirACRend;
4038 : Word16 subframe_idx;
4039 : Word16 slot_idx, index_slot;
4040 : Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
4041 : Word16 nchan_transport;
4042 : Word16 masa_band_mapping[MASA_FREQUENCY_BANDS + 1];
4043 :
4044 : /* local copies of azi, ele, diffuseness */
4045 : Word16 azimuth[CLDFB_NO_CHANNELS_MAX];
4046 : Word16 elevation[CLDFB_NO_CHANNELS_MAX];
4047 :
4048 : Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX];
4049 : Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
4050 : Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
4051 20400 : Word16 q_cldfb = 0;
4052 : Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX];
4053 : Word16 Q_surCohRatio, surCohRatio_exp[CLDFB_NO_CHANNELS_MAX];
4054 : Word32 dirEne_fx;
4055 : Word32 surCohEner_fx;
4056 20400 : move16();
4057 :
4058 346800 : FOR( Word16 ii = 0; ii < MAX_OUTPUT_CHANNELS; ii++ )
4059 : {
4060 1632000 : FOR( Word16 jj = 0; jj < MAX_PARAM_SPATIAL_SUBFRAMES; jj++ )
4061 : {
4062 1305600 : set_zero_fx( Cldfb_RealBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX );
4063 1305600 : set_zero_fx( Cldfb_ImagBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX );
4064 : }
4065 : }
4066 :
4067 : DIRAC_DEC_STACK_MEM DirAC_mem;
4068 :
4069 20400 : Word32 *onset_filter_fx, *onset_filter_subframe_fx, *p_onset_filter_fx = NULL;
4070 : Word32 *reference_power_smooth_fx, *reference_power_fix;
4071 : UWord16 coherence_flag;
4072 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
4073 :
4074 20400 : push_wmops( "ivas_masa_ext_dirac_render_sf" );
4075 :
4076 : /* Initialize aux buffers */
4077 20400 : hDirACRend = hMasaExtRend->hDirACRend;
4078 20400 : hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom;
4079 20400 : nchan_transport = hMasaExtRend->nchan_input;
4080 20400 : move16();
4081 :
4082 20400 : DirAC_mem = hDirACRend->stack_mem;
4083 :
4084 20400 : onset_filter_fx = DirAC_mem.onset_filter_fx; // q31
4085 20400 : reference_power_fix = DirAC_mem.reference_power_fx; // DirAC_mem.reference_power_q
4086 20400 : IF( ( DirAC_mem.reference_power_fx == NULL ) )
4087 : {
4088 3600 : reference_power_smooth_fx = NULL;
4089 : }
4090 : ELSE
4091 : {
4092 16800 : reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; // DirAC_mem.reference_power_q
4093 : }
4094 20400 : IF( ( DirAC_mem.onset_filter_fx == NULL ) )
4095 : {
4096 1200 : onset_filter_subframe_fx = NULL;
4097 : }
4098 : ELSE
4099 : {
4100 19200 : onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; // q31
4101 : }
4102 20400 : coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */
4103 20400 : move16();
4104 : /* Construct default MASA band mapping */
4105 530400 : FOR( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ )
4106 : {
4107 510000 : masa_band_mapping[i] = i;
4108 510000 : move16();
4109 : }
4110 :
4111 : /* Subframe loop */
4112 20400 : slot_idx_start = hSpatParamRendCom->slots_rendered;
4113 20400 : move16();
4114 20400 : slot_idx_start_cldfb_synth = 0;
4115 20400 : move16();
4116 :
4117 20400 : subframe_idx = hSpatParamRendCom->subframes_rendered;
4118 20400 : move16();
4119 20400 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
4120 20400 : move16();
4121 :
4122 : DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
4123 20400 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
4124 :
4125 : /* copy parameters into local buffers*/
4126 :
4127 20400 : Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands );
4128 20400 : Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands );
4129 20400 : Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); // q30
4130 :
4131 20400 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4132 : {
4133 16800 : set32_fx( reference_power_smooth_fx, 0, hSpatParamRendCom->num_freq_bands );
4134 : }
4135 : ELSE
4136 : {
4137 3600 : set32_fx( onset_filter_subframe_fx, 0, hSpatParamRendCom->num_freq_bands );
4138 : }
4139 :
4140 : /* compute response */
4141 20400 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4142 : {
4143 16800 : ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands,
4144 : diffuseness_vector_fx,
4145 16800 : hDirACRend->h_output_synthesis_psd_params.max_band_decorr,
4146 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
4147 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx );
4148 :
4149 16800 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29;
4150 16800 : move16();
4151 16800 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29;
4152 16800 : move16();
4153 :
4154 :
4155 16800 : IF( coherence_flag )
4156 : {
4157 16800 : Word16 temp_exp = MIN_16;
4158 16800 : move16();
4159 1024800 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
4160 : {
4161 1008000 : dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // 29
4162 1008000 : move32();
4163 1008000 : surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q.29
4164 1008000 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); // q29
4165 1008000 : move32();
4166 1008000 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); // q29
4167 1008000 : move32();
4168 :
4169 1008000 : surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale_newton( surCohEner_fx, L_add( L_add( 1, dirEne_fx ), surCohEner_fx ), &surCohRatio_exp[i] ); // 31-surCohRatio_exp
4170 1008000 : move32();
4171 1008000 : temp_exp = s_max( temp_exp, surCohRatio_exp[i] );
4172 : }
4173 :
4174 1024800 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
4175 : {
4176 1008000 : surCohRatio_fx[i] = L_shr( surCohRatio_fx[i], sub( temp_exp, surCohRatio_exp[i] ) ); // 31-temp_exp
4177 1008000 : move32();
4178 : }
4179 16800 : Q_surCohRatio = sub( 31, temp_exp );
4180 : }
4181 : ELSE
4182 : {
4183 0 : set32_fx( surCohRatio_fx, 0, hSpatParamRendCom->num_freq_bands );
4184 0 : Q_surCohRatio = 31;
4185 0 : move16();
4186 : }
4187 : }
4188 : ELSE
4189 : {
4190 3600 : ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands,
4191 3600 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
4192 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
4193 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx,
4194 : &hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q,
4195 : &hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q );
4196 3600 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q );
4197 3600 : move16();
4198 3600 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( 31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q );
4199 3600 : move16();
4200 3600 : IF( coherence_flag )
4201 : {
4202 219600 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
4203 : {
4204 216000 : surCohRatio_fx[i] = L_deposit_h( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // q31
4205 216000 : move32();
4206 : }
4207 : }
4208 : ELSE
4209 : {
4210 0 : set32_fx( surCohRatio_fx, 0, hSpatParamRendCom->num_freq_bands );
4211 : }
4212 :
4213 3600 : Q_surCohRatio = Q31;
4214 3600 : move16();
4215 : }
4216 :
4217 20400 : ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom,
4218 : hDirACRend,
4219 : hMasaExtRend->hVBAPdata,
4220 : masa_band_mapping,
4221 : NULL,
4222 : azimuth,
4223 : elevation,
4224 : md_idx,
4225 : surCohRatio_fx,
4226 : Q_surCohRatio,
4227 : 0,
4228 : NULL,
4229 : 0 );
4230 :
4231 : Word16 proto_direct_buffer_f_temp_q[60];
4232 : Word16 temp_proto_frame_q;
4233 :
4234 102000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4235 : {
4236 81600 : index_slot = add( slot_idx_start, slot_idx );
4237 81600 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
4238 81600 : move16();
4239 81600 : proto_direct_buffer_f_temp_q[slot_idx] = MAX_16;
4240 81600 : move16();
4241 :
4242 : /* CLDFB Analysis*/
4243 206400 : FOR( ch = 0; ch < nchan_transport; ch++ )
4244 : {
4245 124800 : q_cldfb = 11;
4246 124800 : move16();
4247 124800 : hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = q_cldfb;
4248 124800 : move16();
4249 124800 : cldfbAnalysis_ts_fx_fixed_q( &( output_f_fx[ch][hSpatParamRendCom->num_freq_bands * index_slot] ),
4250 124800 : Cldfb_RealBuffer_fx[ch][0],
4251 124800 : Cldfb_ImagBuffer_fx[ch][0],
4252 124800 : hSpatParamRendCom->num_freq_bands,
4253 : hMasaExtRend->cldfbAnaRend[ch], &q_cldfb );
4254 : }
4255 :
4256 81600 : IF( EQ_16( nchan_transport, 1 ) )
4257 : {
4258 : /* Need to set second CLDFB channel to zero as further processing assumes CNA content in it */
4259 38400 : set32_fx( Cldfb_RealBuffer_fx[1][0], 0, hSpatParamRendCom->num_freq_bands );
4260 38400 : set32_fx( Cldfb_ImagBuffer_fx[1][0], 0, hSpatParamRendCom->num_freq_bands );
4261 : }
4262 : /*-----------------------------------------------------------------*
4263 : * prototype signal computation
4264 : *-----------------------------------------------------------------*/
4265 :
4266 81600 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4267 : {
4268 14400 : protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
4269 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
4270 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
4271 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
4272 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
4273 : #ifdef FIX_867_CLDFB_NRG_SCALE
4274 : reference_power_fix, DirAC_mem.reference_power_q, slot_idx, nchan_transport,
4275 : #else
4276 : reference_power_fix, &DirAC_mem.reference_power_q, slot_idx, nchan_transport,
4277 : #endif
4278 14400 : hDirACRend->num_outputs_diff,
4279 14400 : hSpatParamRendCom->num_freq_bands,
4280 : 0, q_cldfb );
4281 :
4282 14400 : proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
4283 14400 : move16();
4284 : }
4285 67200 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
4286 : {
4287 4800 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx, &hDirACRend->proto_frame_f_q,
4288 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
4289 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
4290 : #ifdef FIX_867_CLDFB_NRG_SCALE
4291 : reference_power_fix, DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4292 4800 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4293 : #else
4294 : reference_power_fix, &DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4295 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4296 : #endif
4297 4800 : 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect, q_cldfb );
4298 :
4299 4800 : proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
4300 4800 : move16();
4301 : #ifdef FIX_867_CLDFB_NRG_SCALE
4302 4800 : IF( LT_16( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) )
4303 : {
4304 2784 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4305 : {
4306 1392 : Scale_sig32( reference_power_fix + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) ); // DirAC_mem.reference_power_q
4307 : }
4308 1392 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4309 1392 : move16();
4310 : }
4311 : ELSE
4312 : {
4313 3408 : Scale_sig32( reference_power_fix, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( DirAC_mem.reference_power_smooth_q[0], DirAC_mem.reference_power_q[0] ) ); // DirAC_mem.reference_power_smooth_q
4314 3408 : DirAC_mem.reference_power_q[0] = DirAC_mem.reference_power_smooth_q[0];
4315 3408 : move16();
4316 : }
4317 4800 : IF( LT_16( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) )
4318 : {
4319 2652 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4320 : {
4321 1326 : Scale_sig32( reference_power_fix + CLDFB_NO_CHANNELS_HALF + i, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) ); // DirAC_mem.reference_power_q
4322 : }
4323 1326 : DirAC_mem.reference_power_smooth_q[1] = DirAC_mem.reference_power_q[1];
4324 1326 : move16();
4325 : }
4326 : ELSE
4327 : {
4328 3474 : Scale_sig32( reference_power_fix + CLDFB_NO_CHANNELS_HALF, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_smooth_q[1], DirAC_mem.reference_power_q[1] ) ); // DirAC_mem.reference_power_smooth_q
4329 3474 : DirAC_mem.reference_power_q[1] = DirAC_mem.reference_power_smooth_q[1];
4330 3474 : move16();
4331 : }
4332 : #else
4333 : IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) )
4334 : {
4335 : Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); // DirAC_mem.reference_power_q
4336 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4337 : move16();
4338 : }
4339 : ELSE
4340 : {
4341 : Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); // DirAC_mem.reference_power_smooth_q
4342 : DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q;
4343 : move16();
4344 : }
4345 : #endif
4346 4800 : temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 );
4347 4800 : Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q
4348 4800 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q );
4349 4800 : move16();
4350 : }
4351 : ELSE
4352 : {
4353 62400 : SWITCH( nchan_transport )
4354 : {
4355 38400 : case 2:
4356 38400 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
4357 : hDirACRend->proto_frame_f_fx,
4358 : &hDirACRend->proto_frame_f_q,
4359 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
4360 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
4361 : #ifdef FIX_867_CLDFB_NRG_SCALE
4362 : reference_power_fix, DirAC_mem.reference_power_q,
4363 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4364 38400 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4365 : #else
4366 : reference_power_fix, &DirAC_mem.reference_power_q,
4367 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4368 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4369 : #endif
4370 38400 : hDirACRend->hOutSetup.is_loudspeaker_setup,
4371 : slot_idx,
4372 38400 : hSpatParamRendCom->num_freq_bands,
4373 : hDirACRend->masa_stereo_type_detect, q_cldfb );
4374 :
4375 38400 : proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
4376 38400 : move16();
4377 : #ifdef FIX_867_CLDFB_NRG_SCALE
4378 38400 : IF( LT_16( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) )
4379 : {
4380 22272 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4381 : {
4382 11136 : Scale_sig32( reference_power_fix + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) ); // DirAC_mem.reference_power_q
4383 : }
4384 11136 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4385 11136 : move16();
4386 : }
4387 : ELSE
4388 : {
4389 27264 : Scale_sig32( reference_power_fix, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( DirAC_mem.reference_power_smooth_q[0], DirAC_mem.reference_power_q[0] ) ); // DirAC_mem.reference_power_smooth_q
4390 27264 : DirAC_mem.reference_power_q[0] = DirAC_mem.reference_power_smooth_q[0];
4391 27264 : move16();
4392 : }
4393 38400 : IF( LT_16( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) )
4394 : {
4395 21216 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4396 : {
4397 10608 : Scale_sig32( reference_power_fix + CLDFB_NO_CHANNELS_HALF + i, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) ); // DirAC_mem.reference_power_q
4398 : }
4399 10608 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[1];
4400 10608 : move16();
4401 : }
4402 : ELSE
4403 : {
4404 27792 : Scale_sig32( reference_power_fix, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_smooth_q[1], DirAC_mem.reference_power_q[1] ) ); // DirAC_mem.reference_power_smooth_q
4405 27792 : DirAC_mem.reference_power_q[1] = DirAC_mem.reference_power_smooth_q[1];
4406 27792 : move16();
4407 : }
4408 :
4409 : #else
4410 : IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) )
4411 : {
4412 : Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); // DirAC_mem.reference_power_q
4413 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4414 : move16();
4415 : }
4416 : ELSE
4417 : {
4418 : Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); // DirAC_mem.reference_power_smooth_q
4419 : DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q;
4420 : move16();
4421 : }
4422 : #endif
4423 38400 : temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 );
4424 38400 : Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q
4425 38400 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q );
4426 38400 : move16();
4427 :
4428 38400 : BREAK;
4429 24000 : case 1:
4430 24000 : protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
4431 : hDirACRend->proto_frame_f_fx,
4432 : &hDirACRend->proto_frame_f_q,
4433 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
4434 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
4435 : #ifdef FIX_867_CLDFB_NRG_SCALE
4436 : reference_power_fix, DirAC_mem.reference_power_q,
4437 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4438 24000 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4439 : #else
4440 : reference_power_fix, &DirAC_mem.reference_power_q,
4441 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4442 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4443 : #endif
4444 : slot_idx,
4445 24000 : hDirACRend->num_protos_diff,
4446 24000 : hSpatParamRendCom->num_freq_bands, q_cldfb );
4447 :
4448 24000 : proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
4449 24000 : move16();
4450 :
4451 : #ifdef FIX_867_CLDFB_NRG_SCALE
4452 24000 : IF( LT_16( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) )
4453 : {
4454 15420 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4455 : {
4456 7710 : Scale_sig32( reference_power_fix + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) ); // DirAC_mem.reference_power_q
4457 : }
4458 7710 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4459 7710 : move16();
4460 : }
4461 : ELSE
4462 : {
4463 16290 : Scale_sig32( reference_power_fix, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( DirAC_mem.reference_power_smooth_q[0], DirAC_mem.reference_power_q[0] ) ); // DirAC_mem.reference_power_smooth_q
4464 16290 : DirAC_mem.reference_power_q[0] = DirAC_mem.reference_power_smooth_q[0];
4465 16290 : move16();
4466 : }
4467 24000 : IF( LT_16( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) )
4468 : {
4469 15420 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4470 : {
4471 7710 : Scale_sig32( reference_power_fix + CLDFB_NO_CHANNELS_HALF + i, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) ); // DirAC_mem.reference_power_q
4472 : }
4473 7710 : DirAC_mem.reference_power_smooth_q[1] = DirAC_mem.reference_power_q[1];
4474 7710 : move16();
4475 : }
4476 : ELSE
4477 : {
4478 16290 : Scale_sig32( reference_power_fix, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_smooth_q[1], DirAC_mem.reference_power_q[1] ) ); // DirAC_mem.reference_power_smooth_q
4479 16290 : DirAC_mem.reference_power_q[1] = DirAC_mem.reference_power_smooth_q[1];
4480 16290 : move16();
4481 : }
4482 : #else
4483 : IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) )
4484 : {
4485 : Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); // DirAC_mem.reference_power_q
4486 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4487 : move16();
4488 : }
4489 : ELSE
4490 : {
4491 : Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); // DirAC_mem.reference_power_smooth_q
4492 : DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q;
4493 : move16();
4494 : }
4495 : #endif
4496 :
4497 24000 : temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 );
4498 24000 : Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q
4499 24000 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q );
4500 24000 : move16();
4501 :
4502 24000 : BREAK;
4503 0 : default:
4504 0 : return;
4505 : }
4506 : }
4507 :
4508 : /*-----------------------------------------------------------------*
4509 : * frequency domain decorrelation
4510 : *-----------------------------------------------------------------*/
4511 81600 : IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) )
4512 : {
4513 : /* decorrelate prototype frame */
4514 76800 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4515 : {
4516 28800 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
4517 14400 : hDirACRend->num_outputs_diff,
4518 14400 : hDirACRend->num_protos_diff,
4519 : hDirACRend->synthesisConf,
4520 : nchan_transport,
4521 14400 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff,
4522 14400 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
4523 14400 : hDirACRend->num_protos_diff,
4524 14400 : hDirACRend->proto_index_diff,
4525 14400 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * s_min( 4, nchan_transport ),
4526 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
4527 : onset_filter_fx,
4528 : hDirACRend->h_freq_domain_decorr_ap_params,
4529 : hDirACRend->h_freq_domain_decorr_ap_state );
4530 :
4531 14400 : v_multc_fixed( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
4532 : #ifdef VEC_ARITH_OPT_v1
4533 14400 : v_add_fixed_no_hdrm( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
4534 : #else /* VEC_ARITH_OPT_v1 */
4535 : v_add_fixed( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands, 0 ); /* Q31 */
4536 : #endif /* VEC_ARITH_OPT_v1 */
4537 14400 : p_onset_filter_fx = onset_filter_subframe_fx; /*q31*/
4538 : }
4539 : ELSE
4540 : {
4541 62400 : set_zero_fx( DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f_len );
4542 :
4543 62400 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
4544 62400 : hDirACRend->num_outputs_diff,
4545 62400 : hDirACRend->num_protos_diff,
4546 : hDirACRend->synthesisConf,
4547 : nchan_transport,
4548 62400 : hDirACRend->proto_frame_f_fx,
4549 62400 : hDirACRend->proto_frame_f_q,
4550 62400 : hDirACRend->num_protos_diff,
4551 62400 : hDirACRend->proto_index_diff,
4552 : DirAC_mem.frame_dec_f_fx,
4553 : &DirAC_mem.frame_dec_f_q,
4554 : onset_filter_fx,
4555 : hDirACRend->h_freq_domain_decorr_ap_params,
4556 : hDirACRend->h_freq_domain_decorr_ap_state );
4557 :
4558 62400 : hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx; // DirAC_mem.frame_dec_f_q
4559 62400 : hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q;
4560 62400 : move16();
4561 62400 : p_onset_filter_fx = onset_filter_fx; // q31
4562 : }
4563 : }
4564 : ELSE
4565 : {
4566 4800 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4567 : {
4568 0 : set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands ); // q31
4569 0 : p_onset_filter_fx = onset_filter_subframe_fx; // q31
4570 : }
4571 : ELSE
4572 : {
4573 : /* no frequency domain decorrelation: use prototype frame */
4574 4800 : hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx; // q31
4575 4800 : hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q;
4576 4800 : p_onset_filter_fx = NULL;
4577 : }
4578 : }
4579 :
4580 : /*-----------------------------------------------------------------*
4581 : * output synthesis
4582 : *-----------------------------------------------------------------*/
4583 :
4584 81600 : test();
4585 81600 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
4586 : {
4587 : /* Compute diffuse prototypes */
4588 62400 : ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx );
4589 : }
4590 81600 : Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // q31
4591 81600 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
4592 81600 : move16();
4593 :
4594 81600 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // q31
4595 81600 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31;
4596 81600 : move16();
4597 :
4598 81600 : ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fix,
4599 : DirAC_mem.reference_power_q,
4600 : p_onset_filter_fx,
4601 : azimuth,
4602 : elevation,
4603 81600 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
4604 81600 : hSpatParamRendCom->q_diffuseness_vector,
4605 : hSpatParamRendCom,
4606 : hDirACRend,
4607 : 0,
4608 : 0,
4609 : hMasaExtRend->hVBAPdata,
4610 : hDirACRend->hOutSetup,
4611 : nchan_transport,
4612 : md_idx,
4613 : 0,
4614 : 0 );
4615 :
4616 81600 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4617 : {
4618 67200 : Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1 ); // DirAC_mem.reference_power_q-1
4619 : #ifdef FIX_867_CLDFB_NRG_SCALE
4620 67200 : DirAC_mem.reference_power_q[0] = sub( DirAC_mem.reference_power_q[0], 1 );
4621 67200 : DirAC_mem.reference_power_q[1] = sub( DirAC_mem.reference_power_q[1], 1 );
4622 67200 : move16();
4623 67200 : move16();
4624 67200 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4625 67200 : DirAC_mem.reference_power_smooth_q[1] = DirAC_mem.reference_power_q[1];
4626 67200 : move16();
4627 67200 : move16();
4628 : #else
4629 : DirAC_mem.reference_power_q = sub( DirAC_mem.reference_power_q, 1 );
4630 : move16();
4631 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4632 : move16();
4633 : #endif
4634 : #ifdef VEC_ARITH_OPT_v1
4635 67200 : v_add_fixed_no_hdrm( reference_power_fix, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); // DirAC_mem.reference_power_smooth_q
4636 : #else /* VEC_ARITH_OPT_v1 */
4637 : v_add_fixed( reference_power_fix, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, 0 ); // DirAC_mem.reference_power_smooth_q
4638 : #endif /* VEC_ARITH_OPT_v1 */
4639 : }
4640 : }
4641 : /*Rescaling proto_direct_buffer_f*/
4642 20400 : Word16 temp = MAX_16;
4643 20400 : move16();
4644 :
4645 102000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4646 : {
4647 81600 : temp = s_min( temp, proto_direct_buffer_f_temp_q[slot_idx] );
4648 : }
4649 :
4650 20400 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
4651 : {
4652 66000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4653 : {
4654 52800 : Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[( slot_idx * ( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len / hSpatParamRendCom->subframe_nbslots[subframe_idx] ) )], idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), sub( temp, proto_direct_buffer_f_temp_q[slot_idx] ) ); // temp
4655 : }
4656 : }
4657 : ELSE
4658 : {
4659 36000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4660 : {
4661 28800 : Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[( slot_idx * ( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len / hSpatParamRendCom->subframe_nbslots[subframe_idx] ) )], idiv1616( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), sub( temp, proto_direct_buffer_f_temp_q[slot_idx] ) ); // temp
4662 : }
4663 : }
4664 20400 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = temp;
4665 20400 : move16();
4666 :
4667 :
4668 20400 : ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4669 :
4670 : /*Memories Scaling*/
4671 20400 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // q31
4672 20400 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31;
4673 20400 : move16();
4674 20400 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // q31
4675 20400 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31;
4676 20400 : move16();
4677 20400 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // q31
4678 20400 : hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31;
4679 20400 : move16();
4680 :
4681 20400 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4682 : {
4683 38400 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
4684 : {
4685 174000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4686 : {
4687 139200 : Scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx],
4688 139200 : hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); // q6
4689 139200 : Scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx],
4690 139200 : hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); // q6
4691 : }
4692 : }
4693 3600 : q_cldfb = 6;
4694 3600 : move16();
4695 :
4696 3600 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // q26
4697 3600 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26;
4698 3600 : move16();
4699 :
4700 3600 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); // q26
4701 3600 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26;
4702 3600 : move16();
4703 :
4704 3600 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // q26
4705 3600 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26;
4706 3600 : move16();
4707 :
4708 3600 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, sub( 26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // q26
4709 3600 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26;
4710 3600 : move16();
4711 :
4712 3600 : ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx,
4713 : Cldfb_ImagBuffer_fx,
4714 : hSpatParamRendCom,
4715 : hDirACRend,
4716 : nchan_transport,
4717 3600 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
4718 : p_onset_filter_fx,
4719 : diffuseness_vector_fx,
4720 : 0,
4721 : 0,
4722 : &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev,
4723 : &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev );
4724 3600 : q_cldfb = -1;
4725 3600 : move16();
4726 3600 : hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev;
4727 3600 : move16();
4728 3600 : hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev;
4729 3600 : move16();
4730 : }
4731 : ELSE
4732 : {
4733 16800 : IF( hDirACRend->proto_signal_decorr_on )
4734 : {
4735 15600 : Word16 new_proto_diffuse_buffer_f_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len );
4736 15600 : Word16 new_proto_direct_buffer_f_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len );
4737 :
4738 15600 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, new_proto_diffuse_buffer_f_q ); // hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q + new_proto_diffuse_buffer_f_q
4739 15600 : scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, new_proto_direct_buffer_f_q ); // hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q + new_proto_direct_buffer_f_q
4740 15600 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, new_proto_direct_buffer_f_q );
4741 15600 : move16();
4742 15600 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = add( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, new_proto_diffuse_buffer_f_q );
4743 15600 : move16();
4744 : }
4745 :
4746 16800 : Word16 reference_power_temp_q = getScaleFactor32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len );
4747 16800 : scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, reference_power_temp_q ); /*DirAC_mem.reference_power_q + reference_power_temp_q*/
4748 : #ifdef FIX_867_CLDFB_NRG_SCALE
4749 16800 : DirAC_mem.reference_power_q[0] = add( DirAC_mem.reference_power_q[0], reference_power_temp_q );
4750 16800 : DirAC_mem.reference_power_q[1] = add( DirAC_mem.reference_power_q[1], reference_power_temp_q );
4751 16800 : move16();
4752 16800 : DirAC_mem.reference_power_smooth_q[0] = add( DirAC_mem.reference_power_q[0], reference_power_temp_q );
4753 16800 : DirAC_mem.reference_power_smooth_q[1] = add( DirAC_mem.reference_power_q[1], reference_power_temp_q );
4754 16800 : move16();
4755 : #else
4756 : DirAC_mem.reference_power_q = add( DirAC_mem.reference_power_q, reference_power_temp_q );
4757 : move16();
4758 : DirAC_mem.reference_power_smooth_q = add( DirAC_mem.reference_power_q, reference_power_temp_q );
4759 : move16();
4760 : #endif
4761 :
4762 16800 : Word16 q_cy_auto_diff_smooth = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len );
4763 16800 : Scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth+ q_cy_auto_diff_smooth
4764 16800 : h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth );
4765 16800 : move16();
4766 :
4767 16800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); // q31
4768 16800 : hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31;
4769 16800 : move16();
4770 16800 : Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // q31
4771 16800 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
4772 16800 : move16();
4773 16800 : Scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); // q31
4774 16800 : h_dirac_output_synthesis_state->direct_responses_q = Q31;
4775 16800 : move16();
4776 :
4777 : /*Q-adjustment*/
4778 16800 : IF( hDirACRend->masa_stereo_type_detect )
4779 : {
4780 4800 : hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); // s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y )
4781 4800 : move32();
4782 4800 : hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shl( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ), hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); // s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y )
4783 4800 : move32();
4784 :
4785 4800 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y );
4786 4800 : move16();
4787 4800 : hDirACRend->masa_stereo_type_detect->q_subtract_power_y = s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y );
4788 4800 : move16();
4789 : }
4790 :
4791 : #ifdef FIX_867_CLDFB_NRG_SCALE
4792 147600 : FOR( i = 0; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4793 : {
4794 130800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q )
4795 : }
4796 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] );
4797 16800 : move16();
4798 147600 : FOR( i = 0; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4799 : {
4800 130800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx + CLDFB_NO_CHANNELS_HALF + i, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q )
4801 : }
4802 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] );
4803 16800 : move16();
4804 :
4805 50400 : FOR( i = 0; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4806 : {
4807 33600 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0] ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q )
4808 : }
4809 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[0], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[0] );
4810 16800 : move16();
4811 147600 : FOR( i = 0; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4812 : {
4813 130800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF + i, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1] ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q )
4814 : }
4815 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q[1], hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q[1] );
4816 16800 : move16();
4817 : #else
4818 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q )
4819 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q );
4820 : move16();
4821 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q )
4822 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q );
4823 : move16();
4824 : #endif
4825 :
4826 16800 : Word16 proto_power_diff_smooth_prev_temp_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len );
4827 16800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, proto_power_diff_smooth_prev_temp_q ); // hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q + proto_power_diff_smooth_prev_temp_q
4828 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, proto_power_diff_smooth_prev_temp_q );
4829 16800 : move16();
4830 :
4831 16800 : Word16 proto_power_diff_smooth_temp_q = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len );
4832 16800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, proto_power_diff_smooth_temp_q ); // hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + proto_power_diff_smooth_temp_q
4833 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, proto_power_diff_smooth_temp_q );
4834 16800 : move16();
4835 :
4836 16800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q )
4837 16800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ), hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q )
4838 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q );
4839 16800 : move16();
4840 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q );
4841 16800 : move16();
4842 :
4843 16800 : Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, 1 );
4844 :
4845 : /*Buffer rescaling*/
4846 :
4847 : #ifdef FIX_867_CLDFB_NRG_SCALE
4848 16800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0], DirAC_mem.reference_power_q[0] ), hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q )
4849 16800 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx + CLDFB_NO_CHANNELS_HALF, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1], DirAC_mem.reference_power_q[1] ), hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q )
4850 50400 : FOR( i = 0; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4851 : {
4852 33600 : Scale_sig32( DirAC_mem.reference_power_fx + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0], DirAC_mem.reference_power_q[0] ), DirAC_mem.reference_power_q[0] ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q )
4853 33600 : Scale_sig32( DirAC_mem.reference_power_fx + CLDFB_NO_CHANNELS_HALF + i, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1], DirAC_mem.reference_power_q[1] ), DirAC_mem.reference_power_q[1] ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q )
4854 : }
4855 16800 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0], DirAC_mem.reference_power_q[0] );
4856 16800 : move16();
4857 16800 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1], DirAC_mem.reference_power_q[1] );
4858 16800 : move16();
4859 16800 : DirAC_mem.reference_power_q[0] = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0], DirAC_mem.reference_power_q[0] );
4860 16800 : move16();
4861 16800 : DirAC_mem.reference_power_q[1] = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1], DirAC_mem.reference_power_q[1] );
4862 16800 : move16();
4863 16800 : DirAC_mem.reference_power_smooth_q[0] = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0], DirAC_mem.reference_power_q[0] );
4864 16800 : move16();
4865 16800 : DirAC_mem.reference_power_smooth_q[1] = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1], DirAC_mem.reference_power_q[1] );
4866 16800 : move16();
4867 : #else
4868 : Scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q )
4869 : Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, sub( s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ), DirAC_mem.reference_power_q ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q )
4870 :
4871 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q );
4872 : move16();
4873 : DirAC_mem.reference_power_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q );
4874 : move16();
4875 : DirAC_mem.reference_power_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q );
4876 : move16();
4877 : #endif
4878 :
4879 16800 : ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx,
4880 : Cldfb_ImagBuffer_fx,
4881 : hSpatParamRendCom,
4882 : hDirACRend,
4883 16800 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
4884 : diffuseness_vector_fx,
4885 : reference_power_smooth_fx,
4886 : #ifdef FIX_867_CLDFB_NRG_SCALE
4887 : DirAC_mem.reference_power_smooth_q,
4888 : #else
4889 : &DirAC_mem.reference_power_smooth_q,
4890 : #endif
4891 : ONE_IN_Q31,
4892 : 0, &q_cldfb );
4893 :
4894 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q;
4895 16800 : move16();
4896 : #ifdef FIX_867_CLDFB_NRG_SCALE
4897 16800 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] = DirAC_mem.reference_power_smooth_q[0];
4898 16800 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] = DirAC_mem.reference_power_smooth_q[1];
4899 16800 : move16();
4900 16800 : IF( LT_16( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) )
4901 : {
4902 0 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4903 : {
4904 0 : Scale_sig32( reference_power_fix + i, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) ); // DirAC_mem.reference_power_q
4905 : }
4906 0 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4907 0 : move16();
4908 : }
4909 : ELSE
4910 : {
4911 16800 : Scale_sig32( reference_power_fix, s_min( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ), sub( DirAC_mem.reference_power_smooth_q[0], DirAC_mem.reference_power_q[0] ) ); // DirAC_mem.reference_power_smooth_q
4912 16800 : DirAC_mem.reference_power_q[0] = DirAC_mem.reference_power_smooth_q[0];
4913 16800 : move16();
4914 : }
4915 16800 : IF( LT_16( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) )
4916 : {
4917 0 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4918 : {
4919 0 : Scale_sig32( reference_power_fix + CLDFB_NO_CHANNELS_HALF + i, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) ); // DirAC_mem.reference_power_q
4920 : }
4921 0 : DirAC_mem.reference_power_smooth_q[1] = DirAC_mem.reference_power_q[1];
4922 0 : move16();
4923 : }
4924 : ELSE
4925 : {
4926 16800 : Scale_sig32( reference_power_fix + CLDFB_NO_CHANNELS_HALF, s_min( 0, sub( hSpatParamRendCom->num_freq_bands, CLDFB_NO_CHANNELS_HALF ) ), sub( DirAC_mem.reference_power_smooth_q[1], DirAC_mem.reference_power_q[1] ) ); // DirAC_mem.reference_power_smooth_q
4927 16800 : DirAC_mem.reference_power_q[1] = DirAC_mem.reference_power_smooth_q[1];
4928 16800 : move16();
4929 : }
4930 : #else
4931 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = DirAC_mem.reference_power_smooth_q;
4932 : move16();
4933 : IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) )
4934 : {
4935 : Scale_sig32( reference_power_fix + hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands ), sub( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) ); // DirAC_mem.reference_power_q
4936 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4937 : move16();
4938 : }
4939 : ELSE
4940 : {
4941 : Scale_sig32( reference_power_fix, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q ) ); // DirAC_mem.reference_power_smooth_q
4942 : DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q;
4943 : move16();
4944 : }
4945 : #endif
4946 : }
4947 :
4948 : /*-----------------------------------------------------------------*
4949 : * CLDFB synthesis (and binaural rendering)
4950 : *-----------------------------------------------------------------*/
4951 :
4952 20400 : index_slot = slot_idx_start_cldfb_synth;
4953 20400 : move16();
4954 :
4955 : {
4956 : Word16 outchannels;
4957 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4958 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4959 20400 : Word16 scale_factor = 31;
4960 20400 : move16();
4961 :
4962 186000 : FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
4963 : {
4964 828000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4965 : {
4966 662400 : scale_factor = s_min( scale_factor, getScaleFactor32( Cldfb_RealBuffer_fx[ch][slot_idx],
4967 662400 : hSpatParamRendCom->num_freq_bands ) );
4968 662400 : scale_factor = s_min( scale_factor, getScaleFactor32( Cldfb_ImagBuffer_fx[ch][slot_idx],
4969 662400 : hSpatParamRendCom->num_freq_bands ) );
4970 : }
4971 : }
4972 20400 : scale_factor = sub( scale_factor, find_guarded_bits_fx( hSpatParamRendCom->num_freq_bands ) ); // guard bits
4973 :
4974 186000 : FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
4975 : {
4976 828000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4977 : {
4978 662400 : scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx],
4979 662400 : hSpatParamRendCom->num_freq_bands, scale_factor ); // q_cldfb+scale_factor
4980 662400 : scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx],
4981 662400 : hSpatParamRendCom->num_freq_bands, scale_factor ); // q_cldfb+scale_factor
4982 : }
4983 : }
4984 20400 : q_cldfb = add( q_cldfb, scale_factor );
4985 :
4986 20400 : idx_in = 0;
4987 20400 : move16();
4988 20400 : idx_lfe = 0;
4989 20400 : move16();
4990 :
4991 20400 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
4992 :
4993 : /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */
4994 196800 : FOR( ch = 0; ch < outchannels; ch++ )
4995 : {
4996 176400 : test();
4997 176400 : IF( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) )
4998 : {
4999 : /* No LFE for MASA rendering */
5000 12000 : set32_fx( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) );
5001 :
5002 12000 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
5003 : {
5004 0 : idx_lfe = add( idx_lfe, 1 );
5005 : }
5006 : }
5007 : ELSE
5008 : {
5009 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
5010 : /* cldfb_state_fx should be in 1 less q-factor compared to cld buffers for cldfbSynthesis_ivas_fx function */
5011 164400 : Word16 q_out = sub( q_cldfb, 1 );
5012 164400 : Word16 max_shift = L_norm_arr( hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_length );
5013 164400 : IF( GT_16( max_shift, sub( q_out, hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state ) ) )
5014 : {
5015 164400 : scale_sig32( hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_length, sub( q_out, hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state ) ); // q_out
5016 164400 : hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state = q_out;
5017 164400 : move16();
5018 : }
5019 : ELSE
5020 : {
5021 0 : scale_sig32( Cldfb_RealBuffer_fx[idx_in][i], hSpatParamRendCom->num_freq_bands, sub( hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state, q_out ) );
5022 0 : scale_sig32( Cldfb_ImagBuffer_fx[idx_in][i], hSpatParamRendCom->num_freq_bands, sub( hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state, q_out ) );
5023 : }
5024 822000 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
5025 : {
5026 657600 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // q_cldfb
5027 657600 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // q_cldfb
5028 : }
5029 164400 : Word16 out_size = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
5030 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
5031 164400 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, 0, 0, hMasaExtRend->cldfbSynRend[idx_in] );
5032 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
5033 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, 0, hMasaExtRend->cldfbSynRend[idx_in] );
5034 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
5035 164400 : scale_sig32( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, sub( 11, q_out ) ); // q11
5036 164400 : idx_in++;
5037 : }
5038 : }
5039 : }
5040 20400 : hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slots_rendered );
5041 20400 : move16();
5042 20400 : hSpatParamRendCom->subframes_rendered++;
5043 :
5044 20400 : pop_wmops();
5045 :
5046 20400 : return;
5047 : }
5048 :
5049 :
5050 12750 : void ivas_masa_ext_dirac_render_fx(
5051 : MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */
5052 : Word32 *output_f[], /* i/o: input/output signals in time domain q11*/
5053 : const Word16 num_subframes /* i : number of subframes to render */
5054 : )
5055 : {
5056 : Word16 subframe_idx;
5057 : Word32 *output_f_local[MAX_OUTPUT_CHANNELS];
5058 : Word16 n, n_samples_sf;
5059 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
5060 :
5061 12750 : hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom;
5062 :
5063 12750 : n_samples_sf = i_mult( JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->slot_size );
5064 :
5065 216750 : FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
5066 : {
5067 204000 : output_f_local[n] = output_f[n]; // q11
5068 : }
5069 :
5070 12750 : hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx;
5071 12750 : move16();
5072 :
5073 33150 : FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ )
5074 : {
5075 20400 : hSpatParamRendCom->slots_rendered = 0;
5076 20400 : move16();
5077 20400 : ivas_masa_ext_dirac_render_sf_fx( hMasaExtRend, output_f_local );
5078 346800 : FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
5079 : {
5080 326400 : output_f_local[n] += n_samples_sf;
5081 : }
5082 :
5083 20400 : hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
5084 20400 : move16();
5085 : }
5086 :
5087 12750 : return;
5088 : }
|