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 4560700 : 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 4560700 : move32();
1662 4560700 : proto_power_smooth_fx_q[qidx] = reference_power_q[qidx];
1663 4560700 : move16();
1664 : }
1665 : ELSE
1666 : {
1667 3144740 : 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 3144740 : move32();
1669 3144740 : proto_power_smooth_fx_q[qidx] = proto_power_smooth_q[qidx];
1670 3144740 : 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, Total_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 61933 : Word16 exp_left_hi_power = 0, exp_right_hi_power = 0, exp_total_hi_power = 0, exp_temppp;
2124 61933 : move16();
2125 61933 : move16();
2126 61933 : move16();
2127 3337973 : FOR( l = 0; l < num_freq_bands; l++ )
2128 : {
2129 : #ifdef FIX_867_CLDFB_NRG_SCALE
2130 3276040 : Word16 qidx = s_min( 1, s_max( 0, sub( l, CLDFB_NO_CHANNELS_HALF - 1 ) ) );
2131 3276040 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2132 3276040 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2133 3276040 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2134 3276040 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+min_q_shift
2135 : #else
2136 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
2137 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift
2138 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift
2139 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift
2140 : #endif
2141 :
2142 : /* Compute sum signal */
2143 3276040 : Real_aux_fx = L_add( re1, re2 ); // q_cldfb+min_q_shift
2144 3276040 : Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+min_q_shift
2145 :
2146 : /* Compute reference power */
2147 : // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 );
2148 3276040 : W_tmp1 = W_add( W_mult0_32_32( re1, re1 ), W_mult0_32_32( im1, im1 ) ); // 2*(q_cldfb+min_q_shift)
2149 3276040 : Left_power_fx = W_extract_h( W_shl( W_tmp1, head_room ) ); // q_Left_Right_power
2150 :
2151 : // Right_power_fx = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 );
2152 3276040 : W_tmp2 = W_add( W_mult0_32_32( re2, re2 ), W_mult0_32_32( im2, im2 ) ); // 2*(q_cldfb+min_q_shift)
2153 3276040 : Right_power_fx = W_extract_h( W_shl( W_tmp2, head_room ) ); // q_Left_Right_power
2154 :
2155 : // reference_power_fx[l] = L_add( Left_power_fx, Right_power_fx );
2156 3276040 : reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift)
2157 3276040 : move64();
2158 :
2159 : #ifdef FIX_867_CLDFB_NRG_SCALE
2160 3276040 : Left_power_fx = L_shr( Left_power_fx, total_shift[qidx] );
2161 3276040 : Right_power_fx = L_shr( Right_power_fx, total_shift[qidx] );
2162 3276040 : left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); // q_Left_Right_power
2163 3276040 : right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); // q_Left_Right_power
2164 : // total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] );
2165 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
2166 : #else
2167 : left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); // q_Left_Right_power
2168 : right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); // q_Left_Right_power
2169 : // total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] );
2170 : 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
2171 : #endif
2172 3276040 : IF( GT_16( l, MASA_HI_FREQ_START_BIN ) )
2173 : {
2174 2347045 : W_tmp1 = W_add( W_mult0_32_32( RealBuffer_fx[0][0][l], RealBuffer_fx[0][0][l] ), W_mult0_32_32( ImagBuffer_fx[0][0][l], ImagBuffer_fx[0][0][l] ) );
2175 2347045 : q_shift = W_norm( W_tmp1 );
2176 2347045 : Left_power_fx = W_extract_h( W_shl( W_tmp1, q_shift ) );
2177 2347045 : exp_temppp = sub( 31, sub( add( shl( q_cldfb, 1 ), q_shift ), 32 ) );
2178 :
2179 2347045 : left_hi_power_fx = BASOP_Util_Add_Mant32Exp( left_hi_power_fx, exp_left_hi_power, Left_power_fx, exp_temppp, &exp_left_hi_power ); // exp:exp_left_hi_power
2180 :
2181 2347045 : W_tmp2 = W_add( W_mult0_32_32( RealBuffer_fx[1][0][l], RealBuffer_fx[1][0][l] ), W_mult0_32_32( ImagBuffer_fx[1][0][l], ImagBuffer_fx[1][0][l] ) );
2182 2347045 : q_shift = W_norm( W_tmp2 );
2183 2347045 : Right_power_fx = W_extract_h( W_shl( W_tmp2, q_shift ) );
2184 2347045 : exp_temppp = sub( 31, sub( add( shl( q_cldfb, 1 ), q_shift ), 32 ) );
2185 :
2186 2347045 : right_hi_power_fx = BASOP_Util_Add_Mant32Exp( right_hi_power_fx, exp_right_hi_power, Right_power_fx, exp_temppp, &exp_right_hi_power ); // exp:exp_right_hi_power
2187 :
2188 2347045 : W_tmp2 = W_add( W_tmp1, W_tmp2 );
2189 2347045 : q_shift = W_norm( W_tmp2 );
2190 2347045 : Total_power_fx = W_extract_h( W_shl( W_tmp2, q_shift ) );
2191 2347045 : exp_temppp = sub( 31, sub( add( shl( q_cldfb, 1 ), q_shift ), 32 ) );
2192 :
2193 2347045 : total_hi_power_fx = BASOP_Util_Add_Mant32Exp( total_hi_power_fx, exp_total_hi_power, Total_power_fx, exp_temppp, &exp_total_hi_power ); // exp:exp_total_hi_power
2194 : }
2195 :
2196 3276040 : IF( LT_16( l, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) )
2197 : {
2198 : #ifdef FIX_867_CLDFB_NRG_SCALE
2199 1524325 : re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift[0] ) ); // q_cldfb+temp_q_shift
2200 1524325 : im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift[0] ) ); // q_cldfb+temp_q_shift
2201 : #else
2202 : re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift
2203 : im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift
2204 : #endif
2205 :
2206 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
2207 1524325 : temp = Mpy_32_32( a_fx, sum_power_fx ); // 2*(q_cldfb+temp_q_shift)-31
2208 :
2209 1524325 : IF( LT_16( q_temp2, stereo_type_detect->q_sum_power ) )
2210 : {
2211 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
2212 11600 : move32();
2213 : }
2214 : ELSE
2215 : {
2216 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
2217 1512725 : move32();
2218 : }
2219 :
2220 : #ifdef FIX_867_CLDFB_NRG_SCALE
2221 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
2222 1524325 : IF( LT_16( q_temp_total, stereo_type_detect->q_total_power ) )
2223 : {
2224 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
2225 11645 : move32();
2226 : }
2227 : ELSE
2228 : {
2229 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
2230 1512680 : move32();
2231 : }
2232 : #else
2233 : temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31
2234 : IF( LT_16( q_temp, stereo_type_detect->q_total_power ) )
2235 : {
2236 : 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
2237 : move32();
2238 : }
2239 : ELSE
2240 : {
2241 : 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
2242 : move32();
2243 : }
2244 : #endif
2245 :
2246 1524325 : test();
2247 1524325 : IF( ( stereo_type_detect->sum_power_fx[l] == 0 ) && ( stereo_type_detect->total_power_fx[l] == 0 ) )
2248 : {
2249 2663 : sum_total_ratio_fx[l] = MAX_32; // q15
2250 2663 : move32();
2251 : }
2252 1521662 : ELSE IF( stereo_type_detect->total_power_fx[l] == 0 )
2253 : {
2254 516136 : sum_total_ratio_fx[l] = MAX_32; // q15
2255 516136 : move32();
2256 : }
2257 : ELSE
2258 : {
2259 1005526 : 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 ))
2260 1005526 : move32();
2261 : #ifdef FIX_867_CLDFB_NRG_SCALE
2262 1005526 : 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 ) ) );
2263 : #else
2264 : 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 ) ) );
2265 : #endif
2266 1005526 : sum_total_ratio_fx[l] = L_shl( sum_total_ratio_fx[l], sub( Q15, q_sum_total_ratio ) ); // q15
2267 1005526 : move32();
2268 : }
2269 : }
2270 :
2271 3276040 : IF( l == 0 )
2272 : {
2273 61933 : RealSubtract_fx = L_sub( re1, re2 ); // q_cldfb+min_q_shift
2274 61933 : ImagSubtract_fx = L_sub( im1, im2 ); // q_cldfb+min_q_shift
2275 :
2276 61933 : temp = Madd_32_32( Mpy_32_32( RealSubtract_fx, RealSubtract_fx ), ImagSubtract_fx, ImagSubtract_fx ); // 2*(q_cldfb+min_q_shift)-31
2277 : #ifdef FIX_867_CLDFB_NRG_SCALE
2278 61933 : assert( qidx == 0 );
2279 61933 : IF( LT_16( q_temp[qidx], stereo_type_detect->q_subtract_power_y ) )
2280 : {
2281 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
2282 23770 : move32();
2283 23770 : stereo_type_detect->q_subtract_power_y = q_temp[qidx];
2284 23770 : move16();
2285 : }
2286 : ELSE
2287 : {
2288 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
2289 38163 : move32();
2290 : }
2291 :
2292 : #else
2293 : IF( LT_16( q_temp, stereo_type_detect->q_subtract_power_y ) )
2294 : {
2295 : 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
2296 : move32();
2297 : stereo_type_detect->q_subtract_power_y = q_temp;
2298 : move16();
2299 : }
2300 : ELSE
2301 : {
2302 : 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
2303 : move32();
2304 : }
2305 : #endif
2306 : }
2307 :
2308 : /* Compute protos (and their power) for direct sound rendering */
2309 :
2310 : /* W prototype */
2311 3276040 : IF( stereo_type_detect->interpolator > 0 )
2312 : {
2313 1800 : IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) )
2314 : {
2315 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
2316 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
2317 :
2318 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
2319 : #ifdef FIX_867_CLDFB_NRG_SCALE
2320 1650 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2321 : #else
2322 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2323 : #endif
2324 : {
2325 : #ifdef FIX_867_CLDFB_NRG_SCALE
2326 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
2327 : #else
2328 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2329 : #endif
2330 1650 : move32();
2331 : }
2332 : ELSE
2333 : {
2334 : #ifdef FIX_867_CLDFB_NRG_SCALE
2335 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
2336 : #else
2337 : 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
2338 : #endif
2339 0 : move32();
2340 : }
2341 :
2342 1650 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2343 1650 : move32();
2344 1650 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2345 1650 : move32();
2346 : }
2347 : ELSE
2348 : {
2349 150 : tempSpaced_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31
2350 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
2351 :
2352 150 : temp = Madd_32_16( Mpy_32_16_1( tempSpaced_fx, interpolatorSpaced_fx ), tempDmx_fx, interpolatorDmx_fx ); // 2*(q_cldfb+min_q_shift)-31
2353 : #ifdef FIX_867_CLDFB_NRG_SCALE
2354 150 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2355 : #else
2356 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2357 : #endif
2358 : {
2359 : #ifdef FIX_867_CLDFB_NRG_SCALE
2360 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
2361 : #else
2362 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2363 : #endif
2364 150 : move32();
2365 : }
2366 : ELSE
2367 : {
2368 : #ifdef FIX_867_CLDFB_NRG_SCALE
2369 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
2370 : #else
2371 : 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
2372 : #endif
2373 0 : move32();
2374 : }
2375 :
2376 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
2377 150 : move32();
2378 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
2379 150 : move32();
2380 : }
2381 : }
2382 3274240 : ELSE IF( EQ_16( stereo_type_detect->masa_stereo_type, MASA_STEREO_SPACED_MICS ) )
2383 : {
2384 526080 : IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) )
2385 : {
2386 482240 : Real_aux_fx = L_shr( Real_aux_fx, 1 ); // q_cldfb+min_q_shift
2387 482240 : Imag_aux_fx = L_shr( Imag_aux_fx, 1 ); // q_cldfb+min_q_shift
2388 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
2389 : #ifdef FIX_867_CLDFB_NRG_SCALE
2390 482240 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2391 : #else
2392 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2393 : #endif
2394 : {
2395 : #ifdef FIX_867_CLDFB_NRG_SCALE
2396 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
2397 : #else
2398 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2399 : #endif
2400 482240 : move32();
2401 : }
2402 : ELSE
2403 : {
2404 : #ifdef FIX_867_CLDFB_NRG_SCALE
2405 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
2406 : #else
2407 : 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
2408 : #endif
2409 0 : move32();
2410 : }
2411 :
2412 482240 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2413 482240 : move32();
2414 482240 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2415 482240 : move32();
2416 : }
2417 : ELSE
2418 : {
2419 43840 : temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31
2420 : #ifdef FIX_867_CLDFB_NRG_SCALE
2421 43840 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2422 : #else
2423 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2424 : #endif
2425 : {
2426 : #ifdef FIX_867_CLDFB_NRG_SCALE
2427 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
2428 : #else
2429 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2430 : #endif
2431 43840 : move32();
2432 : }
2433 : ELSE
2434 : {
2435 : #ifdef FIX_867_CLDFB_NRG_SCALE
2436 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
2437 : #else
2438 : 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
2439 : #endif
2440 0 : move32();
2441 : }
2442 :
2443 43840 : p_proto_buffer_fx[2 * l] = re1; // q_cldfb+min_q_shift
2444 43840 : move32();
2445 43840 : p_proto_buffer_fx[2 * l + 1] = im1; // q_cldfb+min_q_shift
2446 43840 : move32();
2447 : }
2448 : }
2449 : ELSE
2450 : {
2451 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
2452 : #ifdef FIX_867_CLDFB_NRG_SCALE
2453 2748160 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2454 : #else
2455 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2456 : #endif
2457 : {
2458 : #ifdef FIX_867_CLDFB_NRG_SCALE
2459 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
2460 : #else
2461 : proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp
2462 : #endif
2463 2747650 : move32();
2464 : }
2465 : ELSE
2466 : {
2467 : #ifdef FIX_867_CLDFB_NRG_SCALE
2468 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
2469 : #else
2470 : 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
2471 : #endif
2472 510 : move32();
2473 : }
2474 :
2475 2748160 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2476 2748160 : move32();
2477 2748160 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2478 2748160 : move32();
2479 : }
2480 :
2481 : /* Y prototype */
2482 3276040 : IF( stereo_type_detect->interpolator > 0 )
2483 : {
2484 1800 : IF( LT_16( l, dipole_freq_range[0] ) )
2485 : {
2486 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
2487 30 : move32();
2488 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
2489 30 : move32();
2490 : }
2491 1770 : ELSE IF( LT_16( l, dipole_freq_range[1] ) )
2492 : {
2493 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
2494 60 : move32();
2495 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
2496 60 : move32();
2497 : }
2498 : ELSE
2499 : {
2500 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
2501 1710 : move32();
2502 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
2503 1710 : move32();
2504 : }
2505 :
2506 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
2507 : #ifdef FIX_867_CLDFB_NRG_SCALE
2508 1800 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2509 : #else
2510 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2511 : #endif
2512 : {
2513 : #ifdef FIX_867_CLDFB_NRG_SCALE
2514 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
2515 : #else
2516 : 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
2517 : #endif
2518 1800 : move32();
2519 : }
2520 : ELSE
2521 : {
2522 : #ifdef FIX_867_CLDFB_NRG_SCALE
2523 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
2524 : #else
2525 : 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
2526 : #endif
2527 0 : move32();
2528 : }
2529 : }
2530 3274240 : ELSE IF( EQ_16( stereo_type_detect->masa_stereo_type, MASA_STEREO_SPACED_MICS ) )
2531 : {
2532 526080 : IF( LT_16( l, dipole_freq_range[0] ) ) /* proto = W */
2533 : {
2534 8768 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = p_proto_buffer_fx[2 * l]; // q_cldfb+min_q_shift
2535 8768 : move32();
2536 8768 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = p_proto_buffer_fx[2 * l + 1]; // q_cldfb+min_q_shift
2537 8768 : move32();
2538 8768 : proto_power_smooth_fx[l + num_freq_bands] = proto_power_smooth_fx[l];
2539 8768 : move32();
2540 : }
2541 517312 : ELSE IF( LT_16( l, dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */
2542 : {
2543 17536 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( im1, im2 ); // q_cldfb+min_q_shift
2544 17536 : move32();
2545 17536 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = -L_sub( re1, re2 ); // q_cldfb+min_q_shift
2546 17536 : move32();
2547 :
2548 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
2549 : #ifdef FIX_867_CLDFB_NRG_SCALE
2550 17536 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2551 : #else
2552 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2553 : #endif
2554 : {
2555 : #ifdef FIX_867_CLDFB_NRG_SCALE
2556 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
2557 : #else
2558 : 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
2559 : #endif
2560 17536 : move32();
2561 : }
2562 : ELSE
2563 : {
2564 : #ifdef FIX_867_CLDFB_NRG_SCALE
2565 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
2566 : #else
2567 : 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
2568 : #endif
2569 0 : move32();
2570 : }
2571 : }
2572 : ELSE /* proto = W */
2573 : {
2574 499776 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = p_proto_buffer_fx[2 * l]; // q_cldfb+min_q_shift
2575 499776 : move32();
2576 499776 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = p_proto_buffer_fx[2 * l + 1]; // q_cldfb+min_q_shift
2577 499776 : move32();
2578 499776 : proto_power_smooth_fx[l + num_freq_bands] = proto_power_smooth_fx[l]; // min( q_temp, *q_proto_power_smooth )
2579 499776 : move32();
2580 : }
2581 : }
2582 : ELSE
2583 : {
2584 2748160 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( re1, re2 ); // q_cldfb+min_q_shift
2585 2748160 : move32();
2586 2748160 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_sub( im1, im2 ); // q_cldfb+min_q_shift
2587 2748160 : move32();
2588 :
2589 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
2590 : #ifdef FIX_867_CLDFB_NRG_SCALE
2591 2748160 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2592 : #else
2593 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2594 : #endif
2595 : {
2596 : #ifdef FIX_867_CLDFB_NRG_SCALE
2597 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
2598 : #else
2599 : 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
2600 : #endif
2601 2747650 : move32();
2602 : }
2603 : ELSE
2604 : {
2605 : #ifdef FIX_867_CLDFB_NRG_SCALE
2606 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
2607 : #else
2608 : 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
2609 : #endif
2610 510 : move32();
2611 : }
2612 : }
2613 :
2614 : /* Compute protos for decorrelation */
2615 3276040 : proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift
2616 3276040 : move32();
2617 3276040 : proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift
2618 3276040 : move32();
2619 3276040 : proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+min_q_shift
2620 3276040 : move32();
2621 3276040 : proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+min_q_shift
2622 3276040 : move32();
2623 3276040 : proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift
2624 3276040 : move32();
2625 3276040 : proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift
2626 3276040 : move32();
2627 : }
2628 :
2629 61933 : stereo_type_detect->q_sum_power = s_min( stereo_type_detect->q_sum_power, q_temp2 );
2630 61933 : move16();
2631 : #ifdef FIX_867_CLDFB_NRG_SCALE
2632 61933 : stereo_type_detect->q_total_power = s_min( stereo_type_detect->q_total_power, q_temp_total );
2633 61933 : move16();
2634 : #else
2635 : stereo_type_detect->q_total_power = s_min( stereo_type_detect->q_total_power, q_temp );
2636 : move16();
2637 : #endif
2638 61933 : q_sum_total_ratio = Q15;
2639 61933 : move16();
2640 :
2641 61933 : IF( stereo_type_detect->interpolator > 0 )
2642 : {
2643 30 : stereo_type_detect->interpolator++;
2644 30 : IF( EQ_16( stereo_type_detect->interpolator, MASA_STEREO_INTERPOLATION_SLOTS ) )
2645 : {
2646 2 : stereo_type_detect->interpolator = 0;
2647 2 : move16();
2648 2 : stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction;
2649 2 : move32();
2650 : }
2651 : }
2652 :
2653 61933 : temp = Mpy_32_32( a_fx, left_bb_power_fx ); // q_Left_Right_power
2654 61933 : IF( LT_16( q_Left_Right_power, stereo_type_detect->q_left_bb_power ) )
2655 : {
2656 610 : 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
2657 610 : move32();
2658 610 : stereo_type_detect->q_left_bb_power = q_Left_Right_power;
2659 610 : move16();
2660 : }
2661 : ELSE
2662 : {
2663 61323 : 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
2664 61323 : move32();
2665 : }
2666 :
2667 61933 : temp = Mpy_32_32( a_fx, right_bb_power_fx ); // q_Left_Right_power
2668 61933 : IF( LT_16( q_Left_Right_power, stereo_type_detect->q_right_bb_power ) )
2669 : {
2670 610 : 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
2671 610 : move32();
2672 610 : stereo_type_detect->q_right_bb_power = q_Left_Right_power;
2673 610 : move16();
2674 : }
2675 : ELSE
2676 : {
2677 61323 : 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
2678 61323 : move32();
2679 : }
2680 :
2681 61933 : temp = Mpy_32_32( a_fx, total_bb_power_fx ); // q_Left_Right_power
2682 61933 : IF( LT_16( q_Left_Right_power, stereo_type_detect->q_total_bb_power ) )
2683 : {
2684 610 : 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
2685 610 : move32();
2686 610 : stereo_type_detect->q_total_bb_power = q_Left_Right_power;
2687 610 : move16();
2688 : }
2689 : ELSE
2690 : {
2691 61323 : 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
2692 61323 : move32();
2693 : }
2694 :
2695 61933 : IF( LT_16( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) )
2696 : {
2697 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
2698 0 : move32();
2699 0 : q_lr_bb_power = stereo_type_detect->q_left_bb_power;
2700 0 : move16();
2701 : }
2702 : ELSE
2703 : {
2704 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
2705 61933 : move32();
2706 61933 : q_lr_bb_power = stereo_type_detect->q_right_bb_power;
2707 61933 : move16();
2708 : }
2709 61933 : q_lr_bb_power = sub( q_lr_bb_power, 1 ); /* = (lr_bb_power_fx * 2) */
2710 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))
2711 61933 : exp = sub( 31, add( sub( 31, exp ), sub( q_lr_bb_power, stereo_type_detect->q_total_bb_power ) ) );
2712 61933 : temp = BASOP_Util_Log2( temp ); // q25
2713 61933 : IF( NE_32( temp, MIN_32 ) )
2714 : {
2715 61926 : temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25
2716 : }
2717 : // 20480 = 10 in Q11
2718 61933 : lr_total_bb_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21
2719 :
2720 : #ifdef FIX_867_CLDFB_NRG_SCALE
2721 61933 : stereo_type_detect->left_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, left_hi_power_fx ), exp_left_hi_power, 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 );
2722 61933 : move32();
2723 61933 : stereo_type_detect->q_left_hi_power = sub( 31, stereo_type_detect->q_left_hi_power );
2724 61933 : move16();
2725 :
2726 61933 : stereo_type_detect->right_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, right_hi_power_fx ), exp_right_hi_power, 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 );
2727 61933 : move32();
2728 61933 : stereo_type_detect->q_right_hi_power = sub( 31, stereo_type_detect->q_right_hi_power );
2729 61933 : move16();
2730 61933 : stereo_type_detect->total_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, total_hi_power_fx ), exp_total_hi_power, 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 );
2731 61933 : move32();
2732 : #else
2733 : 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 );
2734 : move32();
2735 : stereo_type_detect->q_left_hi_power = sub( 31, stereo_type_detect->q_left_hi_power );
2736 : move16();
2737 : 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 );
2738 : move32();
2739 : stereo_type_detect->q_right_hi_power = sub( 31, stereo_type_detect->q_right_hi_power );
2740 : move16();
2741 : 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 );
2742 : move32();
2743 : #endif
2744 61933 : stereo_type_detect->q_total_hi_power = sub( 31, stereo_type_detect->q_total_hi_power );
2745 61933 : move16();
2746 :
2747 61933 : IF( LT_16( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) )
2748 : {
2749 22676 : 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
2750 22676 : move32();
2751 22676 : q_lr_hi_power = stereo_type_detect->q_left_hi_power;
2752 : }
2753 : ELSE
2754 : {
2755 39257 : 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
2756 39257 : move32();
2757 39257 : q_lr_hi_power = stereo_type_detect->q_right_hi_power;
2758 : }
2759 61933 : q_lr_hi_power = sub( q_lr_hi_power, 1 ); /* = (q_lr_hi_power * 2) */
2760 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)
2761 61933 : exp = sub( 31, add( sub( 31, exp ), sub( q_lr_hi_power, stereo_type_detect->q_total_hi_power ) ) );
2762 61933 : temp = BASOP_Util_Log2( temp ); // q25
2763 61933 : IF( NE_32( temp, MIN_32 ) )
2764 : {
2765 61926 : temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25
2766 : }
2767 : // 20480 = 10 in Q11
2768 61933 : lr_total_hi_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21
2769 :
2770 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
2771 61933 : exp = sub( 31, q_sum_total_ratio );
2772 61933 : temp = BASOP_Util_Log2( min_sum_total_ratio_fx ); // q25
2773 61933 : IF( NE_32( temp, MIN_32 ) )
2774 : {
2775 61933 : temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25
2776 : }
2777 : // 20480 = 10 in Q11
2778 61933 : min_sum_total_ratio_db_fx = Mpy_32_16_1( temp, 20480 ); // Q21
2779 :
2780 61933 : stereo_type_detect->lr_total_bb_ratio_db_fx = lr_total_bb_ratio_fx; // Q21
2781 61933 : move32();
2782 61933 : stereo_type_detect->lr_total_hi_ratio_db_fx = lr_total_hi_ratio_fx; // Q21
2783 61933 : move32();
2784 61933 : stereo_type_detect->min_sum_total_ratio_db_fx = min_sum_total_ratio_db_fx; // Q21
2785 61933 : move32();
2786 :
2787 61933 : ivas_masa_stereotype_detection_fx( stereo_type_detect );
2788 : }
2789 : ELSE
2790 : {
2791 19244 : p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * num_freq_bands * 4 ); // q_proto_direct_buffer_f
2792 :
2793 : #ifdef FIX_867_CLDFB_NRG_SCALE
2794 19244 : q_temp[0] = sub( add( add( q_cldfb, min_q_shift[0] ), add( q_cldfb, min_q_shift[0] ) ), 31 );
2795 19244 : q_temp[1] = sub( add( add( q_cldfb, min_q_shift[1] ), add( q_cldfb, min_q_shift[1] ) ), 31 );
2796 : #else
2797 : q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
2798 : #endif
2799 :
2800 1077884 : FOR( l = 0; l < num_freq_bands; l++ )
2801 : {
2802 : #ifdef FIX_867_CLDFB_NRG_SCALE
2803 1058640 : Word16 qidx = s_min( 1, s_max( 0, sub( l, CLDFB_NO_CHANNELS_HALF - 1 ) ) );
2804 1058640 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+ min_q_shift
2805 1058640 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+ min_q_shift
2806 1058640 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift[qidx] ); // q_cldfb+ min_q_shift
2807 1058640 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift[qidx] ); // q_cldfb+ min_q_shift
2808 : #else
2809 : re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+ min_q_shift
2810 : re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+ min_q_shift
2811 : im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+ min_q_shift
2812 : im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+ min_q_shift
2813 : #endif
2814 :
2815 1058640 : Real_aux_fx = L_add( re1, re2 ); // q_cldfb+ min_q_shift
2816 1058640 : Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+ min_q_shift
2817 :
2818 : // reference_power_fx[l] = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx );
2819 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
2820 1058640 : move64();
2821 :
2822 : #ifdef FIX_867_CLDFB_NRG_SCALE
2823 1058640 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2824 : #else
2825 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2826 : #endif
2827 : {
2828 : #ifdef FIX_867_CLDFB_NRG_SCALE
2829 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
2830 : #else
2831 : 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
2832 : #endif
2833 741660 : move32();
2834 : }
2835 : ELSE
2836 : {
2837 : #ifdef FIX_867_CLDFB_NRG_SCALE
2838 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
2839 : #else
2840 : 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
2841 : #endif
2842 316980 : move32();
2843 : }
2844 :
2845 1058640 : p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+ min_q_shift
2846 1058640 : move32();
2847 1058640 : p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+ min_q_shift
2848 1058640 : move32();
2849 :
2850 1058640 : p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( re1, re2 ); // q_cldfb+ min_q_shift
2851 1058640 : move32();
2852 1058640 : p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_sub( im1, im2 ); // q_cldfb+ min_q_shift
2853 1058640 : move32();
2854 :
2855 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
2856 : #ifdef FIX_867_CLDFB_NRG_SCALE
2857 1058640 : IF( LT_16( q_temp[qidx], q_proto_power_smooth[qidx] ) )
2858 : #else
2859 : IF( LT_16( q_temp, *q_proto_power_smooth ) )
2860 : #endif
2861 : {
2862 : #ifdef FIX_867_CLDFB_NRG_SCALE
2863 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
2864 : #else
2865 : 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
2866 : #endif
2867 741660 : move32();
2868 : }
2869 : ELSE
2870 : {
2871 : #ifdef FIX_867_CLDFB_NRG_SCALE
2872 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
2873 : #else
2874 : 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
2875 : #endif
2876 316980 : move32();
2877 : }
2878 :
2879 1058640 : proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+ min_q_shift
2880 1058640 : move32();
2881 1058640 : proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+ min_q_shift
2882 1058640 : move32();
2883 :
2884 1058640 : proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+ min_q_shift
2885 1058640 : move32();
2886 1058640 : proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+ min_q_shift
2887 1058640 : move32();
2888 1058640 : proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+ min_q_shift
2889 1058640 : move32();
2890 1058640 : proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+ min_q_shift
2891 1058640 : move32();
2892 : }
2893 : }
2894 : #ifdef FIX_867_CLDFB_NRG_SCALE
2895 175029 : q_reference_power_64fx = shl( add( q_cldfb, min_q_shift[0] ), 1 );
2896 :
2897 175029 : Word16 norm_shift = 63;
2898 175029 : move16();
2899 5353899 : FOR( l = 0; l < s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ); l++ )
2900 : {
2901 5178870 : IF( reference_power_64fx[l] )
2902 : {
2903 5177551 : norm_shift = s_min( norm_shift, W_norm( reference_power_64fx[l] ) );
2904 : }
2905 : }
2906 5353899 : FOR( l = 0; l < s_min( num_freq_bands, CLDFB_NO_CHANNELS_HALF ); l++ )
2907 : {
2908 5178870 : reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); // q_reference_power_64fx+norm_shift-32
2909 5178870 : move32();
2910 : }
2911 175029 : q_reference_power[0] = sub( add( q_reference_power_64fx, norm_shift ), 32 );
2912 175029 : move16();
2913 :
2914 175029 : q_reference_power_64fx = shl( add( q_cldfb, min_q_shift[1] ), 1 );
2915 175029 : norm_shift = 63;
2916 175029 : move16();
2917 4865959 : FOR( l = CLDFB_NO_CHANNELS_HALF; l < num_freq_bands; l++ )
2918 : {
2919 4690930 : IF( reference_power_64fx[l] )
2920 : {
2921 4689684 : norm_shift = s_min( norm_shift, W_norm( reference_power_64fx[l] ) );
2922 : }
2923 : }
2924 4865959 : FOR( l = CLDFB_NO_CHANNELS_HALF; l < num_freq_bands; l++ )
2925 : {
2926 4690930 : reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); // q_reference_power_64fx+norm_shift-32
2927 4690930 : move32();
2928 : }
2929 175029 : q_reference_power[1] = sub( add( q_reference_power_64fx, norm_shift ), 32 );
2930 175029 : move16();
2931 : #else
2932 : q_reference_power_64fx = shl( add( q_cldfb, min_q_shift ), 1 );
2933 : Word16 norm_shift = 63;
2934 : move16();
2935 : FOR( l = 0; l < num_freq_bands; l++ )
2936 : {
2937 : IF( reference_power_64fx[l] )
2938 : {
2939 : norm_shift = s_min( norm_shift, W_norm( reference_power_64fx[l] ) );
2940 : }
2941 : }
2942 : FOR( l = 0; l < num_freq_bands; l++ )
2943 : {
2944 : reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); // q_reference_power_64fx+norm_shift-32
2945 : move32();
2946 : }
2947 : *q_reference_power = sub( add( q_reference_power_64fx, norm_shift ), 32 );
2948 : move16();
2949 : #endif
2950 :
2951 : #ifdef FIX_867_CLDFB_NRG_SCALE
2952 175029 : IF( GT_16( min_q_shift[0], min_q_shift[1] ) )
2953 : {
2954 8 : FOR( l = 0; l < i_mult( num_proto, num_freq_bands ); l += num_freq_bands )
2955 : {
2956 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] ) );
2957 : }
2958 2 : *q_proto_frame_f = add( q_cldfb, min_q_shift[1] );
2959 2 : move16();
2960 : }
2961 : ELSE
2962 : {
2963 618931 : FOR( l = 0; l < i_mult( num_proto, num_freq_bands ); l += num_freq_bands )
2964 : {
2965 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] ) );
2966 : }
2967 175027 : *q_proto_frame_f = add( q_cldfb, min_q_shift[0] );
2968 175027 : move16();
2969 : }
2970 175029 : IF( GT_16( min_q_shift[0], min_q_shift[1] ) )
2971 : {
2972 8 : FOR( l = 0; l < i_mult( num_proto, num_freq_bands ); l += num_freq_bands )
2973 : {
2974 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] ) );
2975 : }
2976 2 : *q_proto_direct_buffer_f = add( q_cldfb, min_q_shift[1] );
2977 2 : move16();
2978 : }
2979 : ELSE
2980 : {
2981 618931 : FOR( l = 0; l < i_mult( num_proto, num_freq_bands ); l += num_freq_bands )
2982 : {
2983 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] ) );
2984 : }
2985 175027 : *q_proto_direct_buffer_f = add( q_cldfb, min_q_shift[0] );
2986 175027 : move16();
2987 : }
2988 : #else
2989 : *q_proto_frame_f = add( q_cldfb, min_q_shift );
2990 : move16();
2991 : *q_proto_direct_buffer_f = add( q_cldfb, min_q_shift );
2992 : move16();
2993 : #endif
2994 : #ifdef FIX_867_CLDFB_NRG_SCALE
2995 175029 : q_proto_power_smooth[0] = s_min( q_proto_power_smooth[0], q_temp[0] );
2996 175029 : q_proto_power_smooth[1] = s_min( q_proto_power_smooth[1], q_temp[1] );
2997 175029 : move16();
2998 175029 : move16();
2999 : #else
3000 : *q_proto_power_smooth = s_min( *q_proto_power_smooth, q_temp );
3001 : move16();
3002 : #endif
3003 :
3004 175029 : return;
3005 : }
3006 :
3007 :
3008 : /*-------------------------------------------------------------------------
3009 : * protoSignalComputation4()
3010 : *
3011 : *
3012 : *-------------------------------------------------------------------------*/
3013 :
3014 72000 : void protoSignalComputation4_fx(
3015 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3016 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3017 : Word32 *proto_frame_f_fx, /*proto_frame_f_q*/
3018 : Word16 *proto_frame_f_q,
3019 : Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/
3020 : Word16 *proto_direct_buffer_f_q,
3021 : Word32 *reference_power_fx, /*reference_power_q*/
3022 : Word16 *reference_power_q,
3023 : Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/
3024 : Word16 *proto_power_smooth_q,
3025 : const Word16 slot_index,
3026 : const Word16 num_outputs_diff,
3027 : const Word16 num_freq_bands,
3028 : const Word32 *mtx_hoa_decoder, /*q29*/
3029 : const Word16 nchan_transport,
3030 : const Word16 *sba_map_tc_ind,
3031 : Word16 q_cldfb )
3032 : {
3033 : Word16 k, l, idx, idx2;
3034 : Word16 n, offset;
3035 : Word32 sq_tmp_fx;
3036 : Word32 *p_proto_buffer_fx;
3037 : Word16 min_q_shift, q_shift;
3038 : #ifdef FIX_867_CLDFB_NRG_SCALE
3039 : Word16 min_q_shift2, q_shift2;
3040 : #endif
3041 : Word32 re, im;
3042 : Word16 proto_power_smooth_fx_q, sq_tmp_q;
3043 :
3044 72000 : min_q_shift = Q31;
3045 72000 : move16();
3046 72000 : q_shift = Q31;
3047 72000 : move16();
3048 : #ifdef FIX_867_CLDFB_NRG_SCALE
3049 72000 : min_q_shift2 = Q31;
3050 72000 : move16();
3051 72000 : q_shift2 = Q31;
3052 72000 : move16();
3053 : #endif
3054 72000 : sq_tmp_q = 0;
3055 72000 : move16();
3056 :
3057 72000 : set_zero_fx( reference_power_fx, num_freq_bands );
3058 :
3059 : /* calculate the shift possible for both RealBuffer_fx and ImagBuffer_fx buffers*/
3060 367040 : FOR( k = 0; k < s_max( 4, nchan_transport ); k++ )
3061 : {
3062 : #ifdef FIX_867_CLDFB_NRG_SCALE
3063 295040 : q_shift = L_norm_arr( RealBuffer_fx[k][0], s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ) );
3064 295040 : min_q_shift = s_min( q_shift, min_q_shift );
3065 295040 : q_shift = L_norm_arr( ImagBuffer_fx[k][0], s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ) );
3066 295040 : min_q_shift = s_min( q_shift, min_q_shift );
3067 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 ) ) );
3068 295040 : min_q_shift2 = s_min( q_shift2, min_q_shift2 );
3069 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 ) ) );
3070 295040 : min_q_shift2 = s_min( q_shift2, min_q_shift2 );
3071 : #else
3072 : q_shift = L_norm_arr( RealBuffer_fx[k][0], num_freq_bands );
3073 : min_q_shift = s_min( q_shift, min_q_shift );
3074 : q_shift = L_norm_arr( ImagBuffer_fx[k][0], num_freq_bands );
3075 : min_q_shift = s_min( q_shift, min_q_shift );
3076 : #endif
3077 : }
3078 72000 : q_shift = min_q_shift;
3079 72000 : min_q_shift = sub( min_q_shift, find_guarded_bits_fx( i_mult( 2, 4 ) ) );
3080 : #ifdef FIX_867_CLDFB_NRG_SCALE
3081 72000 : q_shift2 = min_q_shift2;
3082 72000 : min_q_shift2 = sub( min_q_shift2, find_guarded_bits_fx( i_mult( 2, 4 ) ) );
3083 : #endif
3084 :
3085 360000 : FOR( k = 0; k < 4; k++ )
3086 : {
3087 : #ifdef FIX_867_CLDFB_NRG_SCALE
3088 8928000 : FOR( l = 0; l < s_min( CLDFB_NO_CHANNELS_HALF, num_freq_bands ); l++ )
3089 : {
3090 8640000 : re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
3091 8640000 : im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
3092 :
3093 8640000 : sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
3094 :
3095 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
3096 8640000 : move32();
3097 : }
3098 8928000 : FOR( l = CLDFB_NO_CHANNELS_HALF; l < num_freq_bands; l++ )
3099 : {
3100 8640000 : re = L_shl( RealBuffer_fx[k][0][l], min_q_shift2 ); // q_cldfb+min_q_shift
3101 8640000 : im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift2 ); // q_cldfb+min_q_shift
3102 :
3103 8640000 : sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
3104 :
3105 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
3106 8640000 : move32();
3107 : }
3108 : #else
3109 : FOR( l = 0; l < num_freq_bands; l++ )
3110 : {
3111 : re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
3112 : im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift
3113 :
3114 : sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
3115 :
3116 : 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
3117 : move32();
3118 : }
3119 : #endif
3120 : }
3121 : #ifdef FIX_867_CLDFB_NRG_SCALE
3122 72000 : sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3123 72000 : reference_power_q[0] = sq_tmp_q;
3124 72000 : move16();
3125 72000 : sq_tmp_q = sub( add( add( q_cldfb, min_q_shift2 ), add( q_cldfb, min_q_shift2 ) ), 31 );
3126 72000 : reference_power_q[1] = sq_tmp_q;
3127 72000 : move16();
3128 :
3129 72000 : min_q_shift = sub( s_min( q_shift, q_shift2 ), find_guarded_bits_fx( 2 ) );
3130 : #else
3131 : sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3132 : *reference_power_q = sub( add( sq_tmp_q, Q15 ), 15 );
3133 : move16();
3134 :
3135 : min_q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) );
3136 : #endif
3137 :
3138 : /*For decorrelated diffuseness*/
3139 784000 : FOR( l = 0; l < num_outputs_diff; l++ )
3140 : {
3141 43432000 : FOR( k = 0; k < num_freq_bands; k++ )
3142 : {
3143 42720000 : idx = add( i_mult( i_mult( 2, l ), num_freq_bands ), i_mult( 2, k ) );
3144 42720000 : proto_frame_f_fx[idx] = 0;
3145 42720000 : move32();
3146 42720000 : proto_frame_f_fx[idx + 1] = 0;
3147 42720000 : move32();
3148 218246400 : FOR( n = 0; n < nchan_transport; n++ )
3149 : {
3150 175526400 : idx2 = add( i_mult( l, 16 ), sba_map_tc_ind[n] );
3151 :
3152 175526400 : re = L_shl( RealBuffer_fx[n][0][k], min_q_shift ); // q_cldfb+min_q_shift
3153 175526400 : im = L_shl( ImagBuffer_fx[n][0][k], min_q_shift ); // q_cldfb+min_q_shift
3154 :
3155 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
3156 175526400 : move32();
3157 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
3158 175526400 : move32();
3159 : }
3160 : }
3161 : }
3162 72000 : *proto_frame_f_q = sub( add( add( min_q_shift, q_cldfb ), Q29 ), 31 );
3163 72000 : move16();
3164 :
3165 : /* calculate the shift possible to up scale the buffer proto_power_smooth_fx*/
3166 72000 : min_q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ) );
3167 72000 : min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) );
3168 :
3169 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
3170 72000 : *proto_power_smooth_q = add( *proto_power_smooth_q, min_q_shift );
3171 72000 : move16();
3172 72000 : proto_power_smooth_fx_q = *proto_power_smooth_q;
3173 72000 : move16();
3174 :
3175 : /* calculate the shift possible to up scale the values of the buffer proto_frame_f_fx*/
3176 72000 : min_q_shift = getScaleFactor32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ) );
3177 72000 : min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) );
3178 :
3179 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
3180 72000 : *proto_frame_f_q = add( *proto_frame_f_q, min_q_shift );
3181 72000 : move16();
3182 :
3183 72000 : offset = i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) );
3184 72000 : p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; // proto_direct_buffer_f_q
3185 :
3186 784000 : FOR( k = 0; k < num_outputs_diff; k++ )
3187 : {
3188 43432000 : FOR( l = 0; l < num_freq_bands; l++ )
3189 : {
3190 42720000 : idx = 2 * ( k * num_freq_bands + l );
3191 :
3192 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
3193 42720000 : sq_tmp_q = sub( add( *proto_frame_f_q, *proto_frame_f_q ), 31 );
3194 :
3195 42720000 : IF( LT_16( *proto_power_smooth_q, sq_tmp_q ) )
3196 : {
3197 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
3198 8328480 : move32();
3199 8328480 : proto_power_smooth_fx_q = *proto_power_smooth_q;
3200 8328480 : move16();
3201 : }
3202 : ELSE
3203 : {
3204 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
3205 34391520 : move32();
3206 34391520 : proto_power_smooth_fx_q = sq_tmp_q;
3207 34391520 : move16();
3208 : }
3209 :
3210 42720000 : p_proto_buffer_fx[idx] = proto_frame_f_fx[idx]; // proto_frame_f_q
3211 42720000 : move32();
3212 42720000 : p_proto_buffer_fx[idx + 1] = proto_frame_f_fx[idx + 1]; // proto_frame_f_q
3213 42720000 : move32();
3214 : }
3215 : }
3216 :
3217 72000 : *proto_direct_buffer_f_q = *proto_frame_f_q;
3218 72000 : move16();
3219 : #ifdef FIX_867_CLDFB_NRG_SCALE
3220 72000 : proto_power_smooth_q[0] = proto_power_smooth_fx_q;
3221 72000 : proto_power_smooth_q[1] = proto_power_smooth_fx_q;
3222 72000 : move16();
3223 72000 : move16();
3224 : #else
3225 : *proto_power_smooth_q = proto_power_smooth_fx_q;
3226 : move16();
3227 : #endif
3228 :
3229 72000 : return;
3230 : }
3231 :
3232 :
3233 : /*-------------------------------------------------------------------------
3234 : * ivas_dirac_dec_compute_diffuse_proto()
3235 : *
3236 : * Compute diffuse prototype buffer and smooth power, only for decorrelated bands
3237 : *------------------------------------------------------------------------*/
3238 :
3239 346064 : void ivas_dirac_dec_compute_diffuse_proto_fx(
3240 : DIRAC_REND_HANDLE hDirACRend,
3241 : const Word16 num_freq_bands,
3242 : const Word16 slot_idx /* i : slot index */
3243 : )
3244 : {
3245 : Word16 k, l;
3246 : Word16 num_freq_bands_diff;
3247 : DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params;
3248 : DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
3249 : Word16 m;
3250 :
3251 : Word32 *proto_frame_dec_f_fx;
3252 : Word32 *p_diff_buffer_fx, *p_diff_buffer_1_fx;
3253 : Word32 *p_proto_diff_fx, *p_power_smooth_fx;
3254 : Word32 *p_hoa_enc_fx;
3255 :
3256 346064 : proto_frame_dec_f_fx = hDirACRend->proto_frame_dec_f_fx; // hDirACRend->proto_frame_dec_f_q
3257 346064 : h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params );
3258 346064 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
3259 :
3260 346064 : num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr;
3261 346064 : move16();
3262 :
3263 346064 : IF( num_freq_bands_diff == 0 )
3264 : {
3265 72000 : return;
3266 : }
3267 :
3268 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
3269 274064 : p_diff_buffer_1_fx = p_diff_buffer_fx + 1;
3270 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
3271 :
3272 274064 : Word16 diffuse_start = imult1616( slot_idx, shl( imult1616( num_freq_bands_diff, hDirACRend->hOutSetup.nchan_out_woLFE ), 1 ) );
3273 : Word16 diff_e, smooth_e, proto_e, max_e;
3274 : Word32 diff_square, diff_square_1, diff_square_sum;
3275 : Word16 diff_square_e;
3276 : Word16 old_diff_e;
3277 274064 : diff_e = sub( 31, h_dirac_output_synthesis_state->proto_diffuse_buffer_f_q );
3278 274064 : old_diff_e = diff_e;
3279 274064 : move16();
3280 274064 : smooth_e = sub( 31, h_dirac_output_synthesis_state->proto_power_diff_smooth_q );
3281 274064 : proto_e = sub( 31, hDirACRend->proto_frame_dec_f_q );
3282 :
3283 274064 : IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
3284 : {
3285 209936 : diff_square_e = add( shl( proto_e, 1 ), 1 );
3286 209936 : max_e = add( s_max( diff_square_e, smooth_e ), 1 );
3287 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
3288 1682192 : FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ )
3289 : {
3290 1472256 : p_proto_diff_fx = proto_frame_dec_f_fx + shl( imult1616( k, num_freq_bands ), 1 ); // hDirACRend->proto_frame_dec_f_q
3291 23556096 : FOR( l = 0; l < num_freq_bands_diff; l++ )
3292 : {
3293 22083840 : *p_diff_buffer_fx = *( p_proto_diff_fx++ ); // hDirACRend->proto_frame_dec_f_q
3294 22083840 : move32();
3295 22083840 : *p_diff_buffer_1_fx = *( p_proto_diff_fx++ ); // hDirACRend->proto_frame_dec_f_q
3296 22083840 : move32();
3297 :
3298 22083840 : diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2 * proto_e + 1
3299 22083840 : diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2 * proto_e + 1
3300 22083840 : diff_square_sum = L_add( diff_square, diff_square_1 ); // Q(31- diff_square_e)
3301 22083840 : diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); // Q(31-max_e)
3302 22083840 : *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); // Q(31-max_e)
3303 22083840 : move32();
3304 :
3305 22083840 : p_power_smooth_fx++;
3306 22083840 : p_diff_buffer_fx += 2;
3307 22083840 : p_diff_buffer_1_fx += 2;
3308 : }
3309 : }
3310 209936 : diff_e = proto_e;
3311 209936 : move16();
3312 : }
3313 : ELSE
3314 : {
3315 : /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/
3316 64128 : Word16 gb = find_guarded_bits_fx( hDirACRend->num_outputs_diff );
3317 64128 : diff_square_e = add( shl( add( proto_e, gb ), 1 ), 1 );
3318 64128 : max_e = add( s_max( diff_square_e, smooth_e ), 1 );
3319 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
3320 587040 : FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ )
3321 : {
3322 8366592 : FOR( l = 0; l < num_freq_bands_diff; l++ )
3323 : {
3324 7843680 : p_hoa_enc_fx = hDirACRend->hoa_encoder_fx + k; // q31
3325 7843680 : p_proto_diff_fx = proto_frame_dec_f_fx + shl( l, 1 ); // hDirACRend->proto_frame_dec_f_q
3326 :
3327 7843680 : *p_diff_buffer_fx = 0;
3328 7843680 : move32();
3329 7843680 : *p_diff_buffer_1_fx = 0;
3330 7843680 : move32();
3331 :
3332 : /*LS to HOA*/
3333 70593120 : FOR( m = 0; m < hDirACRend->num_outputs_diff; m++ )
3334 : {
3335 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
3336 62749440 : move32();
3337 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
3338 62749440 : move32();
3339 62749440 : p_hoa_enc_fx += hDirACRend->hOutSetup.nchan_out_woLFE;
3340 62749440 : p_proto_diff_fx += shl( num_freq_bands, 1 );
3341 : }
3342 :
3343 7843680 : diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2*( proto_e + gb) + 1
3344 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
3345 7843680 : diff_square_sum = L_add( diff_square, diff_square_1 ); // 2*( proto_e + gb) + 1
3346 7843680 : diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); // 31-max_e
3347 7843680 : *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); // 31-max_e
3348 7843680 : move32();
3349 :
3350 7843680 : p_power_smooth_fx++;
3351 :
3352 7843680 : p_diff_buffer_fx += 2;
3353 7843680 : p_diff_buffer_1_fx += 2;
3354 : }
3355 : }
3356 64128 : diff_e = add( proto_e, gb );
3357 : }
3358 274064 : h_dirac_output_synthesis_state->proto_power_diff_smooth_q = sub( 31, max_e );
3359 274064 : move16();
3360 :
3361 274064 : Word16 new_diff_e = s_max( diff_e, old_diff_e );
3362 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
3363 274064 : Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start,
3364 274064 : i_mult( shl( num_freq_bands_diff, 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ), sub( diff_e, new_diff_e ) ); // 31-new_diff_e
3365 274064 : h_dirac_output_synthesis_state->proto_diffuse_buffer_f_q = sub( 31, new_diff_e );
3366 274064 : move16();
3367 :
3368 274064 : return;
3369 : }
3370 :
3371 :
3372 : /*-------------------------------------------------------------------------
3373 : * computeDirectionAngles()
3374 : *
3375 : *------------------------------------------------------------------------*/
3376 :
3377 694820 : void computeDirectionAngles_fx(
3378 : Word32 *intensity_real_x_fx, /*q_intensity_real*/
3379 : Word32 *intensity_real_y_fx, /*q_intensity_real*/
3380 : Word32 *intensity_real_z_fx, /*q_intensity_real*/
3381 : Word16 q_intensity_real,
3382 : const Word16 num_frequency_bands,
3383 : Word16 *azimuth,
3384 : Word16 *elevation )
3385 : {
3386 : Word16 k;
3387 : Word32 intensityNorm;
3388 : Word32 x, y, z, radius;
3389 : Word32 temp;
3390 : Word16 res, q_intensityNorm, exp, q_temp;
3391 : Word16 q_x, q_y, q_z, exp1, exp2, exp3, q_tmp1, q_tmp2;
3392 : Word32 x_re, y_re, z_re, tmp1, tmp2;
3393 :
3394 694820 : exp = 0;
3395 694820 : move16();
3396 :
3397 8337840 : FOR( k = 0; k < num_frequency_bands; ++k )
3398 : {
3399 7643020 : exp1 = norm_l( intensity_real_x_fx[k] );
3400 7643020 : exp2 = norm_l( intensity_real_y_fx[k] );
3401 7643020 : exp3 = norm_l( intensity_real_z_fx[k] );
3402 7643020 : x_re = L_shl( intensity_real_x_fx[k], exp1 ); /*q_intensity_real+exp1*/
3403 7643020 : y_re = L_shl( intensity_real_y_fx[k], exp2 ); /*q_intensity_real+exp2*/
3404 7643020 : z_re = L_shl( intensity_real_z_fx[k], exp3 ); /*q_intensity_real+exp3*/
3405 :
3406 7643020 : tmp1 = Mpy_32_32( x_re, x_re ); /*2*(q_intensity_real+exp1)-31*/
3407 7643020 : q_tmp1 = sub( add( add( q_intensity_real, exp1 ), add( q_intensity_real, exp1 ) ), 31 );
3408 7643020 : tmp2 = Mpy_32_32( y_re, y_re ); /*2*(q_intensity_real+exp2)-31*/
3409 7643020 : q_tmp2 = sub( add( add( q_intensity_real, exp2 ), add( q_intensity_real, exp2 ) ), 31 );
3410 :
3411 7643020 : temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); // 31-exp
3412 :
3413 7643020 : tmp2 = Mpy_32_32( z_re, z_re ); /*2*(q_intensity_real+exp3)-31*/
3414 7643020 : q_tmp2 = sub( add( add( q_intensity_real, exp3 ), add( q_intensity_real, exp3 ) ), 31 );
3415 :
3416 7643020 : intensityNorm = BASOP_Util_Add_Mant32Exp( temp, exp, tmp2, sub( 31, q_tmp2 ), &exp ); // 31-exp
3417 7643020 : q_intensityNorm = sub( 31, exp );
3418 :
3419 7643020 : IF( LE_32( intensityNorm, EPSILON_FX ) )
3420 : {
3421 24987 : intensityNorm = ONE_IN_Q30; // q30
3422 24987 : move32();
3423 24987 : x = ONE_IN_Q30; // q30
3424 24987 : move32();
3425 24987 : q_x = Q30;
3426 24987 : move16();
3427 24987 : y = 0;
3428 24987 : move32();
3429 24987 : q_y = Q30;
3430 24987 : move16();
3431 24987 : z = 0;
3432 24987 : move32();
3433 24987 : q_z = Q30;
3434 24987 : move16();
3435 : }
3436 : ELSE
3437 : {
3438 7618033 : temp = BASOP_Util_Divide3232_Scale_newton( ONE_IN_Q30, intensityNorm, &exp ); // Q=31-(exp-(30-q_intensityNorm))
3439 7618033 : exp = sub( exp, sub( Q30, q_intensityNorm ) );
3440 7618033 : temp = Sqrt32( temp, &exp ); // Q=31-exp
3441 7618033 : q_temp = sub( 31, exp );
3442 :
3443 7618033 : x = Mpy_32_32( x_re, temp ); /*Q=q_intensity_real+exp1+q_temp-31*/
3444 7618033 : q_x = sub( add( add( q_intensity_real, exp1 ), q_temp ), 31 );
3445 7618033 : y = Mpy_32_32( y_re, temp ); /*Q=q_intensity_real+exp2+q_temp-31*/
3446 7618033 : q_y = sub( add( add( q_intensity_real, exp2 ), q_temp ), 31 );
3447 7618033 : z = Mpy_32_32( z_re, temp ); /*Q=q_intensity_real+exp3+q_temp-31*/
3448 7618033 : q_z = sub( add( add( q_intensity_real, exp3 ), q_temp ), 31 );
3449 : }
3450 :
3451 7643020 : tmp1 = Mpy_32_32( x, x ); /*Q=2*q_x-31*/
3452 7643020 : q_tmp1 = sub( add( q_x, q_x ), 31 );
3453 :
3454 7643020 : tmp2 = Mpy_32_32( y, y ); /*Q=2*q_y-31*/
3455 7643020 : q_tmp2 = sub( add( q_y, q_y ), 31 );
3456 :
3457 7643020 : temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); // Q=31-exp
3458 7643020 : radius = Sqrt32( temp, &exp ); // Q=31-exp
3459 :
3460 7643020 : res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); /* Q13 */
3461 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 */
3462 7643020 : azimuth[k] = shr( abs_s( res ), Q7 ); /* Q0 */
3463 7643020 : move16();
3464 7643020 : IF( res < 0 )
3465 : {
3466 4641975 : azimuth[k] = negate( azimuth[k] );
3467 4641975 : move16();
3468 : }
3469 :
3470 7643020 : res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); /* Q13 */
3471 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 */
3472 7643020 : elevation[k] = shr( abs_s( res ), Q7 ); /* Q0 */
3473 7643020 : move16();
3474 7643020 : IF( res < 0 )
3475 : {
3476 3843157 : elevation[k] = negate( elevation[k] );
3477 3843157 : move16();
3478 : }
3479 : }
3480 :
3481 694820 : return;
3482 : }
3483 :
3484 :
3485 : /*-------------------------------------------------------------------------
3486 : * ivas_masa_init_stereotype_detection()
3487 : *
3488 : * Initialize stereo transport signal type detection
3489 : *------------------------------------------------------------------------*/
3490 :
3491 144 : void ivas_masa_init_stereotype_detection_fx(
3492 : MASA_STEREO_TYPE_DETECT *stereo_type_detect )
3493 : {
3494 144 : stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX;
3495 144 : move32();
3496 144 : stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX;
3497 144 : move32();
3498 144 : stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX;
3499 144 : move32();
3500 :
3501 144 : stereo_type_detect->counter = 0;
3502 144 : move16();
3503 144 : stereo_type_detect->interpolator = 0;
3504 144 : move16();
3505 :
3506 144 : stereo_type_detect->dipole_freq_range[0] = 1;
3507 144 : move16();
3508 144 : stereo_type_detect->dipole_freq_range[1] = 3;
3509 144 : move16();
3510 :
3511 144 : stereo_type_detect->left_bb_power_fx = 0; /* Broadband estimates */
3512 144 : move32();
3513 144 : stereo_type_detect->q_left_bb_power = Q31;
3514 144 : move16();
3515 144 : stereo_type_detect->right_bb_power_fx = 0;
3516 144 : move32();
3517 144 : stereo_type_detect->q_right_bb_power = Q31;
3518 144 : move16();
3519 144 : stereo_type_detect->total_bb_power_fx = 0;
3520 144 : move32();
3521 144 : stereo_type_detect->q_total_bb_power = Q31;
3522 144 : move16();
3523 :
3524 144 : stereo_type_detect->left_hi_power_fx = 0; /* High-frequency estimates */
3525 144 : move32();
3526 144 : stereo_type_detect->q_left_hi_power = Q31;
3527 144 : move16();
3528 144 : stereo_type_detect->right_hi_power_fx = 0;
3529 144 : move32();
3530 144 : stereo_type_detect->q_right_hi_power = Q31;
3531 144 : move16();
3532 144 : stereo_type_detect->total_hi_power_fx = 0;
3533 144 : move32();
3534 144 : stereo_type_detect->q_total_hi_power = Q31;
3535 144 : move16();
3536 :
3537 144 : set32_fx( stereo_type_detect->sum_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS );
3538 144 : set32_fx( stereo_type_detect->total_power_fx, 0, MASA_SUM_FREQ_RANGE_BINS );
3539 :
3540 144 : stereo_type_detect->q_sum_power = Q31;
3541 144 : move16();
3542 144 : stereo_type_detect->q_total_power = Q31;
3543 144 : move16();
3544 :
3545 144 : stereo_type_detect->subtract_power_y_fx = 0;
3546 144 : move32();
3547 144 : stereo_type_detect->q_subtract_power_y = Q31;
3548 144 : move16();
3549 144 : stereo_type_detect->subtract_power_y_smooth_fx = 0;
3550 144 : move32();
3551 144 : stereo_type_detect->q_subtract_power_y_smooth = Q31;
3552 144 : move16();
3553 144 : stereo_type_detect->target_power_y_smooth_fx = 0;
3554 144 : move32();
3555 144 : stereo_type_detect->q_target_power_y_smooth = 31;
3556 144 : move16();
3557 :
3558 144 : stereo_type_detect->lr_total_bb_ratio_db_fx = 0;
3559 144 : move32();
3560 144 : stereo_type_detect->lr_total_hi_ratio_db_fx = 0;
3561 144 : move32();
3562 144 : stereo_type_detect->min_sum_total_ratio_db_fx = 0;
3563 144 : move32();
3564 144 : stereo_type_detect->subtract_target_ratio_db_fx = 0;
3565 144 : move32();
3566 :
3567 144 : return;
3568 : }
3569 :
3570 :
3571 : /*-------------------------------------------------------------------------
3572 : * ivas_masa_stereotype_detection()
3573 : *
3574 : * Detect the type of the transport audio signals
3575 : *------------------------------------------------------------------------*/
3576 :
3577 61933 : void ivas_masa_stereotype_detection_fx(
3578 : MASA_STEREO_TYPE_DETECT *stereo_type_detect )
3579 : {
3580 : Word32 lr_total_bb_ratio_db_fx;
3581 : Word32 lr_total_hi_ratio_db_fx;
3582 : Word32 min_sum_total_ratio_db_fx;
3583 : Word32 subtract_target_ratio_db_fx;
3584 : Word32 change_to_spaced_fx;
3585 : Word16 change_to_spaced_selection;
3586 : Word32 change_to_downmix_fx;
3587 : Word32 change_to_downmix2_fx;
3588 : Word16 change_to_downmix_selection;
3589 : Word32 subtract_temp_fx;
3590 : Word32 min_sum_temp_fx;
3591 : Word32 lr_total_bb_temp_fx;
3592 : Word32 lr_total_hi_temp_fx;
3593 : Word32 temp;
3594 :
3595 61933 : lr_total_bb_ratio_db_fx = stereo_type_detect->lr_total_bb_ratio_db_fx; // q21
3596 61933 : move32();
3597 61933 : lr_total_hi_ratio_db_fx = stereo_type_detect->lr_total_hi_ratio_db_fx; // q21
3598 61933 : move32();
3599 61933 : min_sum_total_ratio_db_fx = stereo_type_detect->min_sum_total_ratio_db_fx; // q21
3600 61933 : move32();
3601 61933 : subtract_target_ratio_db_fx = stereo_type_detect->subtract_target_ratio_db_fx; // q21
3602 61933 : move32();
3603 :
3604 : /* Determine if the determined features match the spaced mic type */
3605 61933 : change_to_spaced_selection = 0;
3606 61933 : move16();
3607 61933 : IF( LT_32( subtract_target_ratio_db_fx, -THREE_Q21 /*-3 q21*/ ) )
3608 : {
3609 : /* subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; */
3610 19564 : temp = L_sub( L_shr( -subtract_target_ratio_db_fx, 1 ), L_shr( THREE_Q21, 1 ) ); // q20
3611 19564 : subtract_temp_fx = Mpy_32_32( temp, 715827883 /* 1 / 3.0f in Q31 */ ); // q20
3612 19564 : subtract_temp_fx = L_shl( subtract_temp_fx, 1 ); /* Q21 */
3613 :
3614 : /* min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); */
3615 19564 : min_sum_temp_fx = Mpy_32_32_r( -min_sum_total_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */
3616 19564 : min_sum_temp_fx = L_max( min_sum_temp_fx, 0 ); /*q21*/
3617 :
3618 : /* lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; */
3619 19564 : lr_total_bb_temp_fx = Mpy_32_32_r( lr_total_bb_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */
3620 :
3621 19564 : change_to_spaced_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); /* Q21 */
3622 :
3623 19564 : IF( GE_32( change_to_spaced_fx, ONE_IN_Q21 ) )
3624 : {
3625 10458 : change_to_spaced_selection = 1;
3626 10458 : move16();
3627 : }
3628 : }
3629 :
3630 : /* Determine if the determined features match the downmix type, according to a metric */
3631 61933 : change_to_downmix_selection = 0;
3632 61933 : move16();
3633 61933 : IF( subtract_target_ratio_db_fx > 0 )
3634 : {
3635 : /* subtract_temp = subtract_target_ratio_db / 3.0f; */
3636 25583 : subtract_temp_fx = Mpy_32_32( subtract_target_ratio_db_fx, 715827883 /* 1 / 3.0f in Q31 */ ); /* Q21 */
3637 :
3638 : /* min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; */
3639 25583 : 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 */
3640 :
3641 : /* lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; */
3642 25583 : lr_total_bb_temp_fx = Mpy_32_32_r( -lr_total_bb_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */
3643 :
3644 25583 : change_to_downmix_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); /* Q21 */
3645 :
3646 25583 : IF( GE_32( change_to_downmix_fx, ONE_IN_Q21 /*1 q21*/ ) )
3647 : {
3648 13190 : change_to_downmix_selection = 1;
3649 13190 : move16();
3650 : }
3651 : }
3652 :
3653 : /* Determine if the determined features match the downmix type, according to another metric */
3654 61933 : IF( LT_32( lr_total_hi_ratio_db_fx, -25165824 ) ) // 25165824 = 12.0 in Q21
3655 : {
3656 : /* subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; */
3657 408 : subtract_temp_fx = Mpy_32_32( L_add( subtract_target_ratio_db_fx, 8388608 /* 4.0 in Q21 */ ), 715827883 /* 1 / 3.0f in Q31 */ );
3658 :
3659 : /* min_sum_temp = min_sum_total_ratio_db / 6.0f; */
3660 408 : min_sum_temp_fx = Mpy_32_32_r( min_sum_total_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ );
3661 :
3662 : /* lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; */
3663 408 : 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 */ );
3664 :
3665 408 : change_to_downmix2_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_hi_temp_fx ); // Q21
3666 :
3667 408 : IF( GE_32( change_to_downmix2_fx, ONE_IN_Q21 /*1 q21*/ ) )
3668 : {
3669 373 : change_to_downmix_selection = 1;
3670 373 : move16();
3671 : }
3672 : }
3673 :
3674 61933 : IF( LT_16( stereo_type_detect->counter, 400 ) )
3675 : {
3676 19559 : stereo_type_detect->counter++;
3677 : }
3678 : ELSE
3679 : {
3680 42374 : IF( EQ_16( change_to_spaced_selection, 1 ) )
3681 : {
3682 8800 : stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS;
3683 8800 : move32();
3684 : }
3685 33574 : ELSE IF( EQ_16( change_to_downmix_selection, 1 ) )
3686 : {
3687 7713 : stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX;
3688 7713 : move32();
3689 : }
3690 : }
3691 :
3692 61933 : IF( stereo_type_detect->interpolator == 0 )
3693 : {
3694 61905 : IF( NE_16( stereo_type_detect->current_stereo_type, stereo_type_detect->masa_stereo_type ) )
3695 : {
3696 2 : stereo_type_detect->interpolator = 1;
3697 2 : move16();
3698 2 : stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type;
3699 2 : move32();
3700 : }
3701 : }
3702 :
3703 61933 : return;
3704 : }
3705 :
3706 :
3707 : /*-------------------------------------------------------------------------
3708 : * computeIntensityVector_dec()
3709 : *
3710 : *
3711 : *------------------------------------------------------------------------*/
3712 :
3713 694820 : void computeIntensityVector_dec_fx(
3714 : Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3715 : Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3716 : Word16 q_cldfb,
3717 : const Word16 num_frequency_bands,
3718 : Word32 *intensity_real_x_fx, /*q_intensity_real*/
3719 : Word32 *intensity_real_y_fx, /*q_intensity_real*/
3720 : Word32 *intensity_real_z_fx, /*q_intensity_real*/
3721 : Word16 *q_intensity_real )
3722 : {
3723 : /*
3724 : * W = a + ib; Y = c + id
3725 : * real(W*Y') = ac + bd
3726 : */
3727 : Word16 i;
3728 : Word32 re1, re2, im1, im2;
3729 : Word16 min_q_shift;
3730 :
3731 694820 : min_q_shift = Q31;
3732 694820 : move32();
3733 : /* calculate the max possible shift for the buffers Cldfb_RealBuffer_fx and Cldfb_ImagBuffer_fx*/
3734 3474100 : FOR( i = 0; i < 4; i++ )
3735 : {
3736 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 ) ) );
3737 : }
3738 :
3739 694820 : min_q_shift = sub( min_q_shift, 1 ); // guard bits
3740 :
3741 8337840 : FOR( i = 0; i < num_frequency_bands; ++i )
3742 : {
3743 7643020 : re1 = L_shl( Cldfb_RealBuffer_fx[0][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3744 7643020 : im1 = L_shl( Cldfb_ImagBuffer_fx[0][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3745 7643020 : re2 = L_shl( Cldfb_RealBuffer_fx[3][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3746 7643020 : im2 = L_shl( Cldfb_ImagBuffer_fx[3][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3747 :
3748 7643020 : intensity_real_x_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/
3749 7643020 : move32();
3750 :
3751 7643020 : re2 = L_shl( Cldfb_RealBuffer_fx[1][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3752 7643020 : im2 = L_shl( Cldfb_ImagBuffer_fx[1][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3753 :
3754 7643020 : intensity_real_y_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/
3755 7643020 : move32();
3756 :
3757 7643020 : re2 = L_shl( Cldfb_RealBuffer_fx[2][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3758 7643020 : im2 = L_shl( Cldfb_ImagBuffer_fx[2][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/
3759 :
3760 7643020 : intensity_real_z_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/
3761 7643020 : move32();
3762 : }
3763 :
3764 694820 : *q_intensity_real = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3765 694820 : move16();
3766 :
3767 694820 : return;
3768 : }
3769 :
3770 :
3771 : /*-------------------------------------------------------------------------
3772 : * ivas_lfe_synth_with_cldfb()
3773 : *
3774 : *
3775 : *------------------------------------------------------------------------*/
3776 :
3777 23440 : void ivas_lfe_synth_with_cldfb_fx(
3778 : MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth,
3779 : Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3780 : Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3781 : Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3782 : Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/
3783 : const Word16 slot_index,
3784 : const Word16 subframe_index,
3785 : const Word16 nchan_transport,
3786 : Word16 q_cldfb )
3787 : {
3788 : Word16 i;
3789 :
3790 : Word16 lfeGain_fx, transportGain_fx;
3791 : Word32 protoLfeReal_fx, protoLfeImag_fx;
3792 : Word32 transportEne_fx, protoLfeEne_fx, targetEneLfe_fx, targetEneTrans_fx;
3793 : Word16 transportEne_q, protoLfeEne_q, targetEneLfe_q, targetEneTrans_q;
3794 23440 : Word16 temp, temp_q = 0;
3795 : Word16 transportGain_q_fx, lfeGain_q_fx;
3796 : Word16 exp, min_q_shift;
3797 : Word32 re, im;
3798 23440 : move16(); // temp_q
3799 :
3800 23440 : exp = Q31;
3801 23440 : move16();
3802 23440 : min_q_shift = Q31;
3803 23440 : move16();
3804 :
3805 23440 : set_zero_fx( RealBufferLfe_fx[slot_index], CLDFB_NO_CHANNELS_MAX );
3806 23440 : set_zero_fx( ImagBufferLfe_fx[slot_index], CLDFB_NO_CHANNELS_MAX );
3807 :
3808 47360 : FOR( i = 0; i < nchan_transport; i++ )
3809 : {
3810 23920 : IF( RealBuffer_fx[i][0][0] )
3811 : {
3812 23908 : exp = norm_l( RealBuffer_fx[i][0][0] );
3813 : }
3814 23920 : min_q_shift = s_min( min_q_shift, exp );
3815 23920 : IF( ImagBuffer_fx[i][0][0] )
3816 : {
3817 23909 : exp = norm_l( ImagBuffer_fx[i][0][0] );
3818 : }
3819 23920 : min_q_shift = s_min( min_q_shift, exp );
3820 : }
3821 23440 : min_q_shift = sub( sub( min_q_shift, find_guarded_bits_fx( nchan_transport ) ), 1 );
3822 :
3823 23440 : re = L_shl( RealBuffer_fx[0][0][0], min_q_shift ); // q_cldfb+min_q_shift
3824 23440 : im = L_shl( ImagBuffer_fx[0][0][0], min_q_shift ); // q_cldfb+min_q_shift
3825 :
3826 23440 : protoLfeReal_fx = re; // q_cldfb+min_q_shift
3827 23440 : move32();
3828 23440 : protoLfeImag_fx = im; // q_cldfb+min_q_shift
3829 23440 : move32();
3830 23440 : transportEne_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31
3831 23920 : FOR( i = 1; i < nchan_transport; i++ )
3832 : {
3833 480 : re = L_shl( RealBuffer_fx[i][0][0], min_q_shift ); // q_cldfb+min_q_shift
3834 480 : im = L_shl( ImagBuffer_fx[i][0][0], min_q_shift ); // q_cldfb+min_q_shift
3835 :
3836 480 : protoLfeReal_fx = L_add( protoLfeReal_fx, re ); // q_cldfb+min_q_shift
3837 480 : protoLfeImag_fx = L_add( protoLfeImag_fx, im ); // q_cldfb+min_q_shift
3838 480 : transportEne_fx = L_add( transportEne_fx, Madd_32_32( Mpy_32_32( re, re ), im, im ) ); // 2*(q_cldfb+min_q_shift)-31
3839 : }
3840 23440 : transportEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3841 :
3842 23440 : protoLfeEne_fx = Madd_32_32( Mpy_32_32( protoLfeReal_fx, protoLfeReal_fx ), protoLfeImag_fx, protoLfeImag_fx ); // 2*(q_cldfb+min_q_shift)-31
3843 23440 : protoLfeEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 );
3844 :
3845 23440 : targetEneLfe_fx = Mpy_32_16_1( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ); // targetEneLfe_q+14-15
3846 23440 : targetEneLfe_q = sub( add( transportEne_q, Q14 ), 15 );
3847 :
3848 23440 : temp = s_max( sub( ONE_IN_Q14 /*1 q14*/, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 164 /*0.01 in Q14*/ ); // q14
3849 23440 : targetEneTrans_fx = Mpy_32_16_1( transportEne_fx, temp ); /*transportEne_q+Q14 -15*/
3850 23440 : targetEneTrans_q = sub( add( transportEne_q, Q14 ), 15 );
3851 :
3852 23440 : hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->transportEneSmooth_q+15-15
3853 23440 : move32();
3854 23440 : hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->protoLfeEneSmooth_q+15-15
3855 23440 : move32();
3856 23440 : hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->targetEneLfeSmooth_q+15-15
3857 23440 : move32();
3858 23440 : hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->targetEneTransSmooth_q+15-15
3859 23440 : move32();
3860 :
3861 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
3862 23440 : move32();
3863 23440 : hMasaLfeSynth->transportEneSmooth_q = sub( 31, temp_q );
3864 23440 : move16();
3865 :
3866 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
3867 23440 : move32();
3868 23440 : hMasaLfeSynth->protoLfeEneSmooth_q = sub( 31, temp_q );
3869 23440 : move16();
3870 :
3871 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
3872 23440 : move32();
3873 23440 : hMasaLfeSynth->targetEneLfeSmooth_q = sub( 31, temp_q );
3874 23440 : move16();
3875 :
3876 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
3877 23440 : move32();
3878 23440 : hMasaLfeSynth->targetEneTransSmooth_q = sub( 31, temp_q );
3879 23440 : move16();
3880 :
3881 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))
3882 23440 : temp_q = add( sub( hMasaLfeSynth->targetEneLfeSmooth_q, hMasaLfeSynth->protoLfeEneSmooth_q ), sub( Q15, temp_q ) );
3883 :
3884 23440 : exp = sub( Q15, temp_q );
3885 23440 : lfeGain_fx = Sqrt16( temp, &exp ); // 15-exp
3886 23440 : lfeGain_q_fx = sub( Q15, exp );
3887 :
3888 23440 : IF( GT_32( L_shr( lfeGain_fx, sub( lfeGain_q_fx, Q14 ) ), ONE_IN_Q14 /*1 q14*/ ) )
3889 : {
3890 0 : lfeGain_fx = ONE_IN_Q14; /*1 q14*/
3891 0 : move16();
3892 0 : lfeGain_q_fx = Q14;
3893 0 : move16();
3894 : }
3895 :
3896 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))
3897 23440 : temp_q = add( sub( hMasaLfeSynth->targetEneTransSmooth_q, hMasaLfeSynth->transportEneSmooth_q ), sub( Q15, temp_q ) );
3898 :
3899 23440 : exp = sub( Q15, temp_q );
3900 23440 : transportGain_fx = Sqrt16( temp, &exp ); // q=15-exp
3901 23440 : transportGain_q_fx = sub( Q15, exp );
3902 :
3903 23440 : IF( GT_32( L_shr( transportGain_fx, sub( transportGain_q_fx, Q14 ) ), ONE_IN_Q14 /*1 q14*/ ) )
3904 : {
3905 0 : transportGain_fx = ONE_IN_Q14; /*1 q14*/
3906 0 : move16();
3907 0 : transportGain_q_fx = Q14;
3908 0 : move16();
3909 : }
3910 :
3911 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
3912 23440 : move32();
3913 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
3914 23440 : move32();
3915 :
3916 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
3917 23440 : move32();
3918 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
3919 23440 : move32();
3920 23920 : FOR( i = 1; i < nchan_transport; i++ )
3921 : {
3922 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
3923 480 : move32();
3924 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
3925 480 : move32();
3926 : }
3927 :
3928 23440 : return;
3929 : }
3930 :
3931 :
3932 : /*-------------------------------------------------------------------------
3933 : * rotateAziEle_DirAC()
3934 : *
3935 : * Apply rotation to DirAC DOAs
3936 : *------------------------------------------------------------------------*/
3937 :
3938 147200 : void rotateAziEle_DirAC_fx(
3939 : Word16 *azi, /* i/o: array of azimuth values */
3940 : Word16 *ele, /* i/o: array of elevation values */
3941 : const Word16 band1, /* i : bands to work on (lower limit) */
3942 : const Word16 band2, /* i : bands to work on (upper bound) */
3943 : const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix q30*/
3944 : )
3945 : {
3946 : Word16 b;
3947 : Word32 dv_0_fx, dv_1_fx, dv_2_fx;
3948 : Word32 dv_r_0_fx, dv_r_1_fx, dv_r_2_fx, tmp, w_fx;
3949 : Word16 exp, temp;
3950 : Word32 *ptr_sin, *ptr_cos;
3951 :
3952 147200 : ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] q31
3953 147200 : ptr_cos = cosine_table_Q31; // q31
3954 :
3955 147200 : push_wmops( "rotateAziEle_DirAC" );
3956 :
3957 4160000 : FOR( b = band1; b < band2; b++ )
3958 : {
3959 : /*Conversion spherical to cartesian coordinates*/
3960 4012800 : IF( GT_16( abs_s( ele[b] ), 180 ) )
3961 : {
3962 : // cos(180 + x) = -cos(x)
3963 0 : w_fx = L_negate( ptr_cos[abs( ele[b] ) - 180] ); // Q31
3964 : }
3965 : ELSE
3966 : {
3967 4012800 : w_fx = ptr_cos[abs_s( ele[b] )]; // Q31
3968 4012800 : move32();
3969 : }
3970 :
3971 4012800 : IF( GT_16( abs_s( azi[b] ), 180 ) )
3972 : {
3973 : // cos(180 + x) = -cos(x)
3974 1931328 : tmp = L_negate( ptr_cos[abs( azi[b] ) - 180] ); // Q31
3975 : }
3976 : ELSE
3977 : {
3978 2081472 : tmp = ptr_cos[abs( azi[b] )]; // Q31
3979 2081472 : move32();
3980 : }
3981 :
3982 4012800 : dv_0_fx = Mpy_32_32( w_fx, tmp ); // Q31
3983 :
3984 :
3985 4012800 : IF( GT_16( azi[b], 180 ) )
3986 : {
3987 : // sin(180 + x) = -sin(x)
3988 1931328 : tmp = L_negate( ptr_sin[azi[b] - 180] ); // Q31
3989 1931328 : move32();
3990 : }
3991 2081472 : ELSE IF( LT_16( azi[b], -180 ) )
3992 : {
3993 : // sin(-(180 + x)) = sin(180 + x) = sinx
3994 0 : tmp = ptr_sin[abs( azi[b] ) - 180]; // Q31
3995 0 : move32();
3996 : }
3997 : ELSE
3998 : {
3999 2081472 : tmp = ptr_sin[azi[b]]; // Q31
4000 2081472 : move32();
4001 : }
4002 4012800 : dv_1_fx = Mpy_32_32( w_fx, tmp ); // Q31
4003 :
4004 4012800 : IF( GT_16( ele[b], 180 ) )
4005 : {
4006 : // sin(180 + x) = -sin(x)
4007 0 : dv_2_fx = L_negate( ptr_sin[ele[b] - 180] ); // Q31
4008 0 : move32();
4009 : }
4010 4012800 : ELSE IF( LT_16( ele[b], -180 ) )
4011 : {
4012 : // sin(-(180 + x)) = -sin(180 + x) = sinx
4013 0 : dv_2_fx = ptr_sin[abs( ele[b] ) - 180]; // Q31
4014 0 : move32();
4015 : }
4016 : ELSE
4017 : {
4018 4012800 : dv_2_fx = ptr_sin[ele[b]]; // Q31
4019 4012800 : move32();
4020 : }
4021 :
4022 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
4023 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
4024 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
4025 :
4026 : /*Conversion spherical to cartesian coordinates*/
4027 4012800 : temp = BASOP_util_atan2( dv_r_1_fx, dv_r_0_fx, 0 ); // Q13
4028 4012800 : azi[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0;
4029 4012800 : move16();
4030 :
4031 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
4032 4012800 : exp = sub( 31, Q27 );
4033 4012800 : tmp = Sqrt32( tmp, &exp ); // q=31-exp
4034 4012800 : temp = BASOP_util_atan2( dv_r_2_fx, tmp, sub( sub( 31, 29 ), exp ) ); // Q13
4035 4012800 : ele[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0
4036 4012800 : move16();
4037 : }
4038 :
4039 147200 : pop_wmops();
4040 :
4041 147200 : return;
4042 : }
4043 :
4044 :
4045 : /* A reduced rewrite of the corresponding decoder side function */
4046 20400 : static void ivas_masa_ext_dirac_render_sf_fx(
4047 : MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */
4048 : Word32 *output_f_fx[] /* i/o: synthesized core-coder transport channels/DirAC output q11*/
4049 : )
4050 : {
4051 : Word16 i, ch, idx_in, idx_lfe;
4052 : DIRAC_REND_HANDLE hDirACRend;
4053 : Word16 subframe_idx;
4054 : Word16 slot_idx, index_slot;
4055 : Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx;
4056 : Word16 nchan_transport;
4057 : Word16 masa_band_mapping[MASA_FREQUENCY_BANDS + 1];
4058 :
4059 : /* local copies of azi, ele, diffuseness */
4060 : Word16 azimuth[CLDFB_NO_CHANNELS_MAX];
4061 : Word16 elevation[CLDFB_NO_CHANNELS_MAX];
4062 :
4063 : Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX];
4064 : Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
4065 : Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
4066 20400 : Word16 q_cldfb = 0;
4067 : Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX];
4068 : Word16 Q_surCohRatio, surCohRatio_exp[CLDFB_NO_CHANNELS_MAX];
4069 : Word32 dirEne_fx;
4070 : Word32 surCohEner_fx;
4071 20400 : move16();
4072 :
4073 346800 : FOR( Word16 ii = 0; ii < MAX_OUTPUT_CHANNELS; ii++ )
4074 : {
4075 1632000 : FOR( Word16 jj = 0; jj < MAX_PARAM_SPATIAL_SUBFRAMES; jj++ )
4076 : {
4077 1305600 : set_zero_fx( Cldfb_RealBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX );
4078 1305600 : set_zero_fx( Cldfb_ImagBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX );
4079 : }
4080 : }
4081 :
4082 : DIRAC_DEC_STACK_MEM DirAC_mem;
4083 :
4084 20400 : Word32 *onset_filter_fx, *onset_filter_subframe_fx, *p_onset_filter_fx = NULL;
4085 : Word32 *reference_power_smooth_fx, *reference_power_fix;
4086 : UWord16 coherence_flag;
4087 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
4088 :
4089 20400 : push_wmops( "ivas_masa_ext_dirac_render_sf" );
4090 :
4091 : /* Initialize aux buffers */
4092 20400 : hDirACRend = hMasaExtRend->hDirACRend;
4093 20400 : hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom;
4094 20400 : nchan_transport = hMasaExtRend->nchan_input;
4095 20400 : move16();
4096 :
4097 20400 : DirAC_mem = hDirACRend->stack_mem;
4098 :
4099 20400 : onset_filter_fx = DirAC_mem.onset_filter_fx; // q31
4100 20400 : reference_power_fix = DirAC_mem.reference_power_fx; // DirAC_mem.reference_power_q
4101 20400 : IF( ( DirAC_mem.reference_power_fx == NULL ) )
4102 : {
4103 3600 : reference_power_smooth_fx = NULL;
4104 : }
4105 : ELSE
4106 : {
4107 16800 : reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; // DirAC_mem.reference_power_q
4108 : }
4109 20400 : IF( ( DirAC_mem.onset_filter_fx == NULL ) )
4110 : {
4111 1200 : onset_filter_subframe_fx = NULL;
4112 : }
4113 : ELSE
4114 : {
4115 19200 : onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; // q31
4116 : }
4117 20400 : coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */
4118 20400 : move16();
4119 : /* Construct default MASA band mapping */
4120 530400 : FOR( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ )
4121 : {
4122 510000 : masa_band_mapping[i] = i;
4123 510000 : move16();
4124 : }
4125 :
4126 : /* Subframe loop */
4127 20400 : slot_idx_start = hSpatParamRendCom->slots_rendered;
4128 20400 : move16();
4129 20400 : slot_idx_start_cldfb_synth = 0;
4130 20400 : move16();
4131 :
4132 20400 : subframe_idx = hSpatParamRendCom->subframes_rendered;
4133 20400 : move16();
4134 20400 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
4135 20400 : move16();
4136 :
4137 : DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state;
4138 20400 : h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state );
4139 :
4140 : /* copy parameters into local buffers*/
4141 :
4142 20400 : Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands );
4143 20400 : Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands );
4144 20400 : Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); // q30
4145 :
4146 20400 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4147 : {
4148 16800 : set32_fx( reference_power_smooth_fx, 0, hSpatParamRendCom->num_freq_bands );
4149 : }
4150 : ELSE
4151 : {
4152 3600 : set32_fx( onset_filter_subframe_fx, 0, hSpatParamRendCom->num_freq_bands );
4153 : }
4154 :
4155 : /* compute response */
4156 20400 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4157 : {
4158 16800 : ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands,
4159 : diffuseness_vector_fx,
4160 16800 : hDirACRend->h_output_synthesis_psd_params.max_band_decorr,
4161 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
4162 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx );
4163 :
4164 16800 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29;
4165 16800 : move16();
4166 16800 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29;
4167 16800 : move16();
4168 :
4169 :
4170 16800 : IF( coherence_flag )
4171 : {
4172 16800 : Word16 temp_exp = MIN_16;
4173 16800 : move16();
4174 1024800 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
4175 : {
4176 1008000 : dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // 29
4177 1008000 : move32();
4178 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
4179 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
4180 1008000 : move32();
4181 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
4182 1008000 : move32();
4183 :
4184 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
4185 1008000 : move32();
4186 1008000 : temp_exp = s_max( temp_exp, surCohRatio_exp[i] );
4187 : }
4188 :
4189 1024800 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
4190 : {
4191 1008000 : surCohRatio_fx[i] = L_shr( surCohRatio_fx[i], sub( temp_exp, surCohRatio_exp[i] ) ); // 31-temp_exp
4192 1008000 : move32();
4193 : }
4194 16800 : Q_surCohRatio = sub( 31, temp_exp );
4195 : }
4196 : ELSE
4197 : {
4198 0 : set32_fx( surCohRatio_fx, 0, hSpatParamRendCom->num_freq_bands );
4199 0 : Q_surCohRatio = 31;
4200 0 : move16();
4201 : }
4202 : }
4203 : ELSE
4204 : {
4205 3600 : ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands,
4206 3600 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
4207 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx,
4208 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx,
4209 : &hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q,
4210 : &hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q );
4211 3600 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( 31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q );
4212 3600 : move16();
4213 3600 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( 31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q );
4214 3600 : move16();
4215 3600 : IF( coherence_flag )
4216 : {
4217 219600 : FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ )
4218 : {
4219 216000 : surCohRatio_fx[i] = L_deposit_h( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // q31
4220 216000 : move32();
4221 : }
4222 : }
4223 : ELSE
4224 : {
4225 0 : set32_fx( surCohRatio_fx, 0, hSpatParamRendCom->num_freq_bands );
4226 : }
4227 :
4228 3600 : Q_surCohRatio = Q31;
4229 3600 : move16();
4230 : }
4231 :
4232 20400 : ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom,
4233 : hDirACRend,
4234 : hMasaExtRend->hVBAPdata,
4235 : masa_band_mapping,
4236 : NULL,
4237 : azimuth,
4238 : elevation,
4239 : md_idx,
4240 : surCohRatio_fx,
4241 : Q_surCohRatio,
4242 : 0,
4243 : NULL,
4244 : 0 );
4245 :
4246 : Word16 proto_direct_buffer_f_temp_q[60];
4247 : Word16 temp_proto_frame_q;
4248 :
4249 102000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4250 : {
4251 81600 : index_slot = add( slot_idx_start, slot_idx );
4252 81600 : md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx];
4253 81600 : move16();
4254 81600 : proto_direct_buffer_f_temp_q[slot_idx] = MAX_16;
4255 81600 : move16();
4256 :
4257 : /* CLDFB Analysis*/
4258 206400 : FOR( ch = 0; ch < nchan_transport; ch++ )
4259 : {
4260 124800 : q_cldfb = 11;
4261 124800 : move16();
4262 124800 : hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = q_cldfb;
4263 124800 : move16();
4264 124800 : cldfbAnalysis_ts_fx_fixed_q( &( output_f_fx[ch][hSpatParamRendCom->num_freq_bands * index_slot] ),
4265 124800 : Cldfb_RealBuffer_fx[ch][0],
4266 124800 : Cldfb_ImagBuffer_fx[ch][0],
4267 124800 : hSpatParamRendCom->num_freq_bands,
4268 : hMasaExtRend->cldfbAnaRend[ch], &q_cldfb );
4269 : }
4270 :
4271 81600 : IF( EQ_16( nchan_transport, 1 ) )
4272 : {
4273 : /* Need to set second CLDFB channel to zero as further processing assumes CNA content in it */
4274 38400 : set32_fx( Cldfb_RealBuffer_fx[1][0], 0, hSpatParamRendCom->num_freq_bands );
4275 38400 : set32_fx( Cldfb_ImagBuffer_fx[1][0], 0, hSpatParamRendCom->num_freq_bands );
4276 : }
4277 : /*-----------------------------------------------------------------*
4278 : * prototype signal computation
4279 : *-----------------------------------------------------------------*/
4280 :
4281 81600 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4282 : {
4283 14400 : protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
4284 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
4285 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
4286 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx,
4287 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
4288 : #ifdef FIX_867_CLDFB_NRG_SCALE
4289 : reference_power_fix, DirAC_mem.reference_power_q, slot_idx, nchan_transport,
4290 : #else
4291 : reference_power_fix, &DirAC_mem.reference_power_q, slot_idx, nchan_transport,
4292 : #endif
4293 14400 : hDirACRend->num_outputs_diff,
4294 14400 : hSpatParamRendCom->num_freq_bands,
4295 : 0, q_cldfb );
4296 :
4297 14400 : proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
4298 14400 : move16();
4299 : }
4300 67200 : ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) )
4301 : {
4302 4800 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx, &hDirACRend->proto_frame_f_q,
4303 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
4304 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
4305 : #ifdef FIX_867_CLDFB_NRG_SCALE
4306 : reference_power_fix, DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4307 4800 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4308 : #else
4309 : reference_power_fix, &DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4310 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4311 : #endif
4312 4800 : 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect, q_cldfb );
4313 :
4314 4800 : proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
4315 4800 : move16();
4316 : #ifdef FIX_867_CLDFB_NRG_SCALE
4317 4800 : IF( LT_16( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) )
4318 : {
4319 2784 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4320 : {
4321 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
4322 : }
4323 1392 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4324 1392 : move16();
4325 : }
4326 : ELSE
4327 : {
4328 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
4329 3408 : DirAC_mem.reference_power_q[0] = DirAC_mem.reference_power_smooth_q[0];
4330 3408 : move16();
4331 : }
4332 4800 : IF( LT_16( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) )
4333 : {
4334 2652 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4335 : {
4336 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
4337 : }
4338 1326 : DirAC_mem.reference_power_smooth_q[1] = DirAC_mem.reference_power_q[1];
4339 1326 : move16();
4340 : }
4341 : ELSE
4342 : {
4343 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
4344 3474 : DirAC_mem.reference_power_q[1] = DirAC_mem.reference_power_smooth_q[1];
4345 3474 : move16();
4346 : }
4347 : #else
4348 : IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) )
4349 : {
4350 : 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
4351 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4352 : move16();
4353 : }
4354 : ELSE
4355 : {
4356 : 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
4357 : DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q;
4358 : move16();
4359 : }
4360 : #endif
4361 4800 : temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 );
4362 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
4363 4800 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q );
4364 4800 : move16();
4365 : }
4366 : ELSE
4367 : {
4368 62400 : SWITCH( nchan_transport )
4369 : {
4370 38400 : case 2:
4371 38400 : protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
4372 : hDirACRend->proto_frame_f_fx,
4373 : &hDirACRend->proto_frame_f_q,
4374 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
4375 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
4376 : #ifdef FIX_867_CLDFB_NRG_SCALE
4377 : reference_power_fix, DirAC_mem.reference_power_q,
4378 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4379 38400 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4380 : #else
4381 : reference_power_fix, &DirAC_mem.reference_power_q,
4382 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4383 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4384 : #endif
4385 38400 : hDirACRend->hOutSetup.is_loudspeaker_setup,
4386 : slot_idx,
4387 38400 : hSpatParamRendCom->num_freq_bands,
4388 : hDirACRend->masa_stereo_type_detect, q_cldfb );
4389 :
4390 38400 : proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
4391 38400 : move16();
4392 : #ifdef FIX_867_CLDFB_NRG_SCALE
4393 38400 : IF( LT_16( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) )
4394 : {
4395 22272 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4396 : {
4397 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
4398 : }
4399 11136 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4400 11136 : move16();
4401 : }
4402 : ELSE
4403 : {
4404 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
4405 27264 : DirAC_mem.reference_power_q[0] = DirAC_mem.reference_power_smooth_q[0];
4406 27264 : move16();
4407 : }
4408 38400 : IF( LT_16( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) )
4409 : {
4410 21216 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4411 : {
4412 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
4413 : }
4414 10608 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[1];
4415 10608 : move16();
4416 : }
4417 : ELSE
4418 : {
4419 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
4420 27792 : DirAC_mem.reference_power_q[1] = DirAC_mem.reference_power_smooth_q[1];
4421 27792 : move16();
4422 : }
4423 :
4424 : #else
4425 : IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) )
4426 : {
4427 : 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
4428 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4429 : move16();
4430 : }
4431 : ELSE
4432 : {
4433 : 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
4434 : DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q;
4435 : move16();
4436 : }
4437 : #endif
4438 38400 : temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 );
4439 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
4440 38400 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q );
4441 38400 : move16();
4442 :
4443 38400 : BREAK;
4444 24000 : case 1:
4445 24000 : protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx,
4446 : hDirACRend->proto_frame_f_fx,
4447 : &hDirACRend->proto_frame_f_q,
4448 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx,
4449 : &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q,
4450 : #ifdef FIX_867_CLDFB_NRG_SCALE
4451 : reference_power_fix, DirAC_mem.reference_power_q,
4452 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4453 24000 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4454 : #else
4455 : reference_power_fix, &DirAC_mem.reference_power_q,
4456 : hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx,
4457 : &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q,
4458 : #endif
4459 : slot_idx,
4460 24000 : hDirACRend->num_protos_diff,
4461 24000 : hSpatParamRendCom->num_freq_bands, q_cldfb );
4462 :
4463 24000 : proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q;
4464 24000 : move16();
4465 :
4466 : #ifdef FIX_867_CLDFB_NRG_SCALE
4467 24000 : IF( LT_16( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) )
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 + 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
4472 : }
4473 7710 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4474 7710 : move16();
4475 : }
4476 : ELSE
4477 : {
4478 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
4479 16290 : DirAC_mem.reference_power_q[0] = DirAC_mem.reference_power_smooth_q[0];
4480 16290 : move16();
4481 : }
4482 24000 : IF( LT_16( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) )
4483 : {
4484 15420 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4485 : {
4486 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
4487 : }
4488 7710 : DirAC_mem.reference_power_smooth_q[1] = DirAC_mem.reference_power_q[1];
4489 7710 : move16();
4490 : }
4491 : ELSE
4492 : {
4493 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
4494 16290 : DirAC_mem.reference_power_q[1] = DirAC_mem.reference_power_smooth_q[1];
4495 16290 : move16();
4496 : }
4497 : #else
4498 : IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) )
4499 : {
4500 : 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
4501 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4502 : move16();
4503 : }
4504 : ELSE
4505 : {
4506 : 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
4507 : DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q;
4508 : move16();
4509 : }
4510 : #endif
4511 :
4512 24000 : temp_proto_frame_q = sub( getScaleFactor32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len ), 2 );
4513 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
4514 24000 : hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q );
4515 24000 : move16();
4516 :
4517 24000 : BREAK;
4518 0 : default:
4519 0 : return;
4520 : }
4521 : }
4522 :
4523 : /*-----------------------------------------------------------------*
4524 : * frequency domain decorrelation
4525 : *-----------------------------------------------------------------*/
4526 81600 : IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) )
4527 : {
4528 : /* decorrelate prototype frame */
4529 76800 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4530 : {
4531 28800 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
4532 14400 : hDirACRend->num_outputs_diff,
4533 14400 : hDirACRend->num_protos_diff,
4534 : hDirACRend->synthesisConf,
4535 : nchan_transport,
4536 14400 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff,
4537 14400 : hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
4538 14400 : hDirACRend->num_protos_diff,
4539 14400 : hDirACRend->proto_index_diff,
4540 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 ),
4541 : &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q,
4542 : onset_filter_fx,
4543 : hDirACRend->h_freq_domain_decorr_ap_params,
4544 : hDirACRend->h_freq_domain_decorr_ap_state );
4545 :
4546 14400 : v_multc_fixed( onset_filter_fx, 536870912 /* 0.25f in Q31 */, onset_filter_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
4547 : #ifdef VEC_ARITH_OPT_v1
4548 14400 : v_add_fixed_no_hdrm( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); /* Q31 */
4549 : #else /* VEC_ARITH_OPT_v1 */
4550 : v_add_fixed( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands, 0 ); /* Q31 */
4551 : #endif /* VEC_ARITH_OPT_v1 */
4552 14400 : p_onset_filter_fx = onset_filter_subframe_fx; /*q31*/
4553 : }
4554 : ELSE
4555 : {
4556 62400 : set_zero_fx( DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f_len );
4557 :
4558 62400 : ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands,
4559 62400 : hDirACRend->num_outputs_diff,
4560 62400 : hDirACRend->num_protos_diff,
4561 : hDirACRend->synthesisConf,
4562 : nchan_transport,
4563 62400 : hDirACRend->proto_frame_f_fx,
4564 62400 : hDirACRend->proto_frame_f_q,
4565 62400 : hDirACRend->num_protos_diff,
4566 62400 : hDirACRend->proto_index_diff,
4567 : DirAC_mem.frame_dec_f_fx,
4568 : &DirAC_mem.frame_dec_f_q,
4569 : onset_filter_fx,
4570 : hDirACRend->h_freq_domain_decorr_ap_params,
4571 : hDirACRend->h_freq_domain_decorr_ap_state );
4572 :
4573 62400 : hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx; // DirAC_mem.frame_dec_f_q
4574 62400 : hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q;
4575 62400 : move16();
4576 62400 : p_onset_filter_fx = onset_filter_fx; // q31
4577 : }
4578 : }
4579 : ELSE
4580 : {
4581 4800 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4582 : {
4583 0 : set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands ); // q31
4584 0 : p_onset_filter_fx = onset_filter_subframe_fx; // q31
4585 : }
4586 : ELSE
4587 : {
4588 : /* no frequency domain decorrelation: use prototype frame */
4589 4800 : hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx; // q31
4590 4800 : hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q;
4591 4800 : p_onset_filter_fx = NULL;
4592 : }
4593 : }
4594 :
4595 : /*-----------------------------------------------------------------*
4596 : * output synthesis
4597 : *-----------------------------------------------------------------*/
4598 :
4599 81600 : test();
4600 81600 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) )
4601 : {
4602 : /* Compute diffuse prototypes */
4603 62400 : ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx );
4604 : }
4605 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
4606 81600 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
4607 81600 : move16();
4608 :
4609 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
4610 81600 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31;
4611 81600 : move16();
4612 :
4613 81600 : ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fix,
4614 : DirAC_mem.reference_power_q,
4615 : p_onset_filter_fx,
4616 : azimuth,
4617 : elevation,
4618 81600 : hSpatParamRendCom->diffuseness_vector_fx[md_idx],
4619 81600 : hSpatParamRendCom->q_diffuseness_vector,
4620 : hSpatParamRendCom,
4621 : hDirACRend,
4622 : 0,
4623 : 0,
4624 : hMasaExtRend->hVBAPdata,
4625 : hDirACRend->hOutSetup,
4626 : nchan_transport,
4627 : md_idx,
4628 : 0,
4629 : 0 );
4630 :
4631 81600 : IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4632 : {
4633 67200 : Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1 ); // DirAC_mem.reference_power_q-1
4634 : #ifdef FIX_867_CLDFB_NRG_SCALE
4635 67200 : DirAC_mem.reference_power_q[0] = sub( DirAC_mem.reference_power_q[0], 1 );
4636 67200 : DirAC_mem.reference_power_q[1] = sub( DirAC_mem.reference_power_q[1], 1 );
4637 67200 : move16();
4638 67200 : move16();
4639 67200 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4640 67200 : DirAC_mem.reference_power_smooth_q[1] = DirAC_mem.reference_power_q[1];
4641 67200 : move16();
4642 67200 : move16();
4643 : #else
4644 : DirAC_mem.reference_power_q = sub( DirAC_mem.reference_power_q, 1 );
4645 : move16();
4646 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4647 : move16();
4648 : #endif
4649 : #ifdef VEC_ARITH_OPT_v1
4650 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
4651 : #else /* VEC_ARITH_OPT_v1 */
4652 : 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
4653 : #endif /* VEC_ARITH_OPT_v1 */
4654 : }
4655 : }
4656 : /*Rescaling proto_direct_buffer_f*/
4657 20400 : Word16 temp = MAX_16;
4658 20400 : move16();
4659 :
4660 102000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4661 : {
4662 81600 : temp = s_min( temp, proto_direct_buffer_f_temp_q[slot_idx] );
4663 : }
4664 :
4665 20400 : IF( hDirACRend->hOutSetup.is_loudspeaker_setup )
4666 : {
4667 66000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4668 : {
4669 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
4670 : }
4671 : }
4672 : ELSE
4673 : {
4674 36000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4675 : {
4676 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
4677 : }
4678 : }
4679 20400 : hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = temp;
4680 20400 : move16();
4681 :
4682 :
4683 20400 : ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
4684 :
4685 : /*Memories Scaling*/
4686 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
4687 20400 : hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31;
4688 20400 : move16();
4689 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
4690 20400 : hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31;
4691 20400 : move16();
4692 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
4693 20400 : hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31;
4694 20400 : move16();
4695 :
4696 20400 : IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) )
4697 : {
4698 38400 : FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ )
4699 : {
4700 174000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4701 : {
4702 139200 : Scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx],
4703 139200 : hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); // q6
4704 139200 : Scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx],
4705 139200 : hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); // q6
4706 : }
4707 : }
4708 3600 : q_cldfb = 6;
4709 3600 : move16();
4710 :
4711 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
4712 3600 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26;
4713 3600 : move16();
4714 :
4715 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
4716 3600 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26;
4717 3600 : move16();
4718 :
4719 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
4720 3600 : hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26;
4721 3600 : move16();
4722 :
4723 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
4724 3600 : hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26;
4725 3600 : move16();
4726 :
4727 3600 : ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx,
4728 : Cldfb_ImagBuffer_fx,
4729 : hSpatParamRendCom,
4730 : hDirACRend,
4731 : nchan_transport,
4732 3600 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
4733 : p_onset_filter_fx,
4734 : diffuseness_vector_fx,
4735 : 0,
4736 : 0,
4737 : &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev,
4738 : &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev );
4739 3600 : q_cldfb = -1;
4740 3600 : move16();
4741 3600 : hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev;
4742 3600 : move16();
4743 3600 : hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev;
4744 3600 : move16();
4745 : }
4746 : ELSE
4747 : {
4748 16800 : IF( hDirACRend->proto_signal_decorr_on )
4749 : {
4750 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 );
4751 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 );
4752 :
4753 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
4754 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
4755 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 );
4756 15600 : move16();
4757 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 );
4758 15600 : move16();
4759 : }
4760 :
4761 16800 : Word16 reference_power_temp_q = getScaleFactor32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len );
4762 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*/
4763 : #ifdef FIX_867_CLDFB_NRG_SCALE
4764 16800 : DirAC_mem.reference_power_q[0] = add( DirAC_mem.reference_power_q[0], reference_power_temp_q );
4765 16800 : DirAC_mem.reference_power_q[1] = add( DirAC_mem.reference_power_q[1], reference_power_temp_q );
4766 16800 : move16();
4767 16800 : DirAC_mem.reference_power_smooth_q[0] = add( DirAC_mem.reference_power_q[0], reference_power_temp_q );
4768 16800 : DirAC_mem.reference_power_smooth_q[1] = add( DirAC_mem.reference_power_q[1], reference_power_temp_q );
4769 16800 : move16();
4770 : #else
4771 : DirAC_mem.reference_power_q = add( DirAC_mem.reference_power_q, reference_power_temp_q );
4772 : move16();
4773 : DirAC_mem.reference_power_smooth_q = add( DirAC_mem.reference_power_q, reference_power_temp_q );
4774 : move16();
4775 : #endif
4776 :
4777 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 );
4778 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
4779 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 );
4780 16800 : move16();
4781 :
4782 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
4783 16800 : hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31;
4784 16800 : move16();
4785 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
4786 16800 : h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31;
4787 16800 : move16();
4788 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
4789 16800 : h_dirac_output_synthesis_state->direct_responses_q = Q31;
4790 16800 : move16();
4791 :
4792 : /*Q-adjustment*/
4793 16800 : IF( hDirACRend->masa_stereo_type_detect )
4794 : {
4795 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 )
4796 4800 : move32();
4797 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 )
4798 4800 : move32();
4799 :
4800 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 );
4801 4800 : move16();
4802 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 );
4803 4800 : move16();
4804 : }
4805 :
4806 : #ifdef FIX_867_CLDFB_NRG_SCALE
4807 147600 : FOR( i = 0; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4808 : {
4809 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 )
4810 : }
4811 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] );
4812 16800 : move16();
4813 147600 : FOR( i = 0; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4814 : {
4815 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 )
4816 : }
4817 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] );
4818 16800 : move16();
4819 :
4820 50400 : FOR( i = 0; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4821 : {
4822 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 )
4823 : }
4824 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] );
4825 16800 : move16();
4826 147600 : FOR( i = 0; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4827 : {
4828 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 )
4829 : }
4830 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] );
4831 16800 : move16();
4832 : #else
4833 : 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 )
4834 : 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 );
4835 : move16();
4836 : 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 )
4837 : 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 );
4838 : move16();
4839 : #endif
4840 :
4841 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 );
4842 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
4843 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 );
4844 16800 : move16();
4845 :
4846 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 );
4847 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
4848 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 );
4849 16800 : move16();
4850 :
4851 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 )
4852 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 )
4853 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 );
4854 16800 : move16();
4855 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 );
4856 16800 : move16();
4857 :
4858 16800 : Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, 1 );
4859 :
4860 : /*Buffer rescaling*/
4861 :
4862 : #ifdef FIX_867_CLDFB_NRG_SCALE
4863 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 )
4864 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 )
4865 50400 : FOR( i = 0; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4866 : {
4867 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 )
4868 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 )
4869 : }
4870 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] );
4871 16800 : move16();
4872 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] );
4873 16800 : move16();
4874 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] );
4875 16800 : move16();
4876 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] );
4877 16800 : move16();
4878 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] );
4879 16800 : move16();
4880 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] );
4881 16800 : move16();
4882 : #else
4883 : 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 )
4884 : 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 )
4885 :
4886 : 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 );
4887 : move16();
4888 : DirAC_mem.reference_power_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q );
4889 : move16();
4890 : DirAC_mem.reference_power_smooth_q = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q );
4891 : move16();
4892 : #endif
4893 :
4894 16800 : ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx,
4895 : Cldfb_ImagBuffer_fx,
4896 : hSpatParamRendCom,
4897 : hDirACRend,
4898 16800 : hSpatParamRendCom->subframe_nbslots[subframe_idx],
4899 : diffuseness_vector_fx,
4900 : reference_power_smooth_fx,
4901 : #ifdef FIX_867_CLDFB_NRG_SCALE
4902 : DirAC_mem.reference_power_smooth_q,
4903 : #else
4904 : &DirAC_mem.reference_power_smooth_q,
4905 : #endif
4906 : ONE_IN_Q31,
4907 : 0, &q_cldfb );
4908 :
4909 16800 : hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q;
4910 16800 : move16();
4911 : #ifdef FIX_867_CLDFB_NRG_SCALE
4912 16800 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[0] = DirAC_mem.reference_power_smooth_q[0];
4913 16800 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q[1] = DirAC_mem.reference_power_smooth_q[1];
4914 16800 : move16();
4915 16800 : IF( LT_16( DirAC_mem.reference_power_q[0], DirAC_mem.reference_power_smooth_q[0] ) )
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 + 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
4920 : }
4921 0 : DirAC_mem.reference_power_smooth_q[0] = DirAC_mem.reference_power_q[0];
4922 0 : move16();
4923 : }
4924 : ELSE
4925 : {
4926 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
4927 16800 : DirAC_mem.reference_power_q[0] = DirAC_mem.reference_power_smooth_q[0];
4928 16800 : move16();
4929 : }
4930 16800 : IF( LT_16( DirAC_mem.reference_power_q[1], DirAC_mem.reference_power_smooth_q[1] ) )
4931 : {
4932 0 : FOR( i = hSpatParamRendCom->num_freq_bands; DirAC_mem.reference_power_len > i; i = add( i, hSpatParamRendCom->num_freq_bands ) )
4933 : {
4934 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
4935 : }
4936 0 : DirAC_mem.reference_power_smooth_q[1] = DirAC_mem.reference_power_q[1];
4937 0 : move16();
4938 : }
4939 : ELSE
4940 : {
4941 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
4942 16800 : DirAC_mem.reference_power_q[1] = DirAC_mem.reference_power_smooth_q[1];
4943 16800 : move16();
4944 : }
4945 : #else
4946 : hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = DirAC_mem.reference_power_smooth_q;
4947 : move16();
4948 : IF( LT_16( DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q ) )
4949 : {
4950 : 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
4951 : DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q;
4952 : move16();
4953 : }
4954 : ELSE
4955 : {
4956 : 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
4957 : DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q;
4958 : move16();
4959 : }
4960 : #endif
4961 : }
4962 :
4963 : /*-----------------------------------------------------------------*
4964 : * CLDFB synthesis (and binaural rendering)
4965 : *-----------------------------------------------------------------*/
4966 :
4967 20400 : index_slot = slot_idx_start_cldfb_synth;
4968 20400 : move16();
4969 :
4970 : {
4971 : Word16 outchannels;
4972 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4973 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
4974 20400 : Word16 scale_factor = 31;
4975 20400 : move16();
4976 :
4977 186000 : FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
4978 : {
4979 828000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4980 : {
4981 662400 : scale_factor = s_min( scale_factor, getScaleFactor32( Cldfb_RealBuffer_fx[ch][slot_idx],
4982 662400 : hSpatParamRendCom->num_freq_bands ) );
4983 662400 : scale_factor = s_min( scale_factor, getScaleFactor32( Cldfb_ImagBuffer_fx[ch][slot_idx],
4984 662400 : hSpatParamRendCom->num_freq_bands ) );
4985 : }
4986 : }
4987 20400 : scale_factor = sub( scale_factor, find_guarded_bits_fx( hSpatParamRendCom->num_freq_bands ) ); // guard bits
4988 :
4989 186000 : FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ )
4990 : {
4991 828000 : FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ )
4992 : {
4993 662400 : scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx],
4994 662400 : hSpatParamRendCom->num_freq_bands, scale_factor ); // q_cldfb+scale_factor
4995 662400 : scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx],
4996 662400 : hSpatParamRendCom->num_freq_bands, scale_factor ); // q_cldfb+scale_factor
4997 : }
4998 : }
4999 20400 : q_cldfb = add( q_cldfb, scale_factor );
5000 :
5001 20400 : idx_in = 0;
5002 20400 : move16();
5003 20400 : idx_lfe = 0;
5004 20400 : move16();
5005 :
5006 20400 : outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe );
5007 :
5008 : /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */
5009 196800 : FOR( ch = 0; ch < outchannels; ch++ )
5010 : {
5011 176400 : test();
5012 176400 : IF( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) )
5013 : {
5014 : /* No LFE for MASA rendering */
5015 12000 : set32_fx( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) );
5016 :
5017 12000 : IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) )
5018 : {
5019 0 : idx_lfe = add( idx_lfe, 1 );
5020 : }
5021 : }
5022 : ELSE
5023 : {
5024 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */
5025 : /* cldfb_state_fx should be in 1 less q-factor compared to cld buffers for cldfbSynthesis_ivas_fx function */
5026 164400 : Word16 q_out = sub( q_cldfb, 1 );
5027 164400 : Word16 max_shift = L_norm_arr( hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_length );
5028 164400 : IF( GT_16( max_shift, sub( q_out, hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state ) ) )
5029 : {
5030 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
5031 164400 : hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state = q_out;
5032 164400 : move16();
5033 : }
5034 : ELSE
5035 : {
5036 0 : scale_sig32( Cldfb_RealBuffer_fx[idx_in][i], hSpatParamRendCom->num_freq_bands, sub( hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state, q_out ) );
5037 0 : scale_sig32( Cldfb_ImagBuffer_fx[idx_in][i], hSpatParamRendCom->num_freq_bands, sub( hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state, q_out ) );
5038 : }
5039 822000 : FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ )
5040 : {
5041 657600 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // q_cldfb
5042 657600 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // q_cldfb
5043 : }
5044 164400 : Word16 out_size = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] );
5045 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
5046 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] );
5047 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
5048 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, 0, hMasaExtRend->cldfbSynRend[idx_in] );
5049 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
5050 164400 : scale_sig32( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, sub( 11, q_out ) ); // q11
5051 164400 : idx_in++;
5052 : }
5053 : }
5054 : }
5055 20400 : hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slots_rendered );
5056 20400 : move16();
5057 20400 : hSpatParamRendCom->subframes_rendered++;
5058 :
5059 20400 : pop_wmops();
5060 :
5061 20400 : return;
5062 : }
5063 :
5064 :
5065 12750 : void ivas_masa_ext_dirac_render_fx(
5066 : MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */
5067 : Word32 *output_f[], /* i/o: input/output signals in time domain q11*/
5068 : const Word16 num_subframes /* i : number of subframes to render */
5069 : )
5070 : {
5071 : Word16 subframe_idx;
5072 : Word32 *output_f_local[MAX_OUTPUT_CHANNELS];
5073 : Word16 n, n_samples_sf;
5074 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
5075 :
5076 12750 : hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom;
5077 :
5078 12750 : n_samples_sf = i_mult( JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->slot_size );
5079 :
5080 216750 : FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
5081 : {
5082 204000 : output_f_local[n] = output_f[n]; // q11
5083 : }
5084 :
5085 12750 : hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx;
5086 12750 : move16();
5087 :
5088 33150 : FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ )
5089 : {
5090 20400 : hSpatParamRendCom->slots_rendered = 0;
5091 20400 : move16();
5092 20400 : ivas_masa_ext_dirac_render_sf_fx( hMasaExtRend, output_f_local );
5093 346800 : FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
5094 : {
5095 326400 : output_f_local[n] += n_samples_sf;
5096 : }
5097 :
5098 20400 : hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, 1 ) % hSpatParamRendCom->dirac_md_buffer_length;
5099 20400 : move16();
5100 : }
5101 :
5102 12750 : return;
5103 : }
|