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_fx.h"
40 : #include "ivas_cnst.h"
41 : #include "ivas_rom_com.h"
42 : #include "ivas_rom_com_fx.h"
43 : #include "wmc_auto.h"
44 :
45 : /*-------------------------------------------------------------------------
46 : * Local function prototypes
47 : *------------------------------------------------------------------------*/
48 : static void computeIntensityVector_enc_fx(
49 : const DIRAC_ENC_HANDLE hDirAC,
50 : Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],
51 : Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],
52 : const Word16 enc_param_start_band, /* i : first band to process */
53 : const Word16 num_frequency_bands,
54 : Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS],
55 : Word16 q_cldfb,
56 : Word16 q_intensity_real[DIRAC_MAX_NBANDS] );
57 :
58 : /*-------------------------------------------------------------------------
59 : * ivas_dirac_enc_open()
60 : *
61 : * Initialize DirAC handle
62 : *------------------------------------------------------------------------*/
63 :
64 281 : ivas_error ivas_dirac_enc_open_fx(
65 : Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
66 : )
67 : {
68 : Word16 i, j;
69 : DIRAC_ENC_HANDLE hDirAC;
70 : Word32 dirac_slot_ns;
71 : ivas_error error;
72 :
73 281 : error = IVAS_ERR_OK;
74 281 : move16();
75 :
76 281 : IF( ( hDirAC = (DIRAC_ENC_HANDLE) malloc( sizeof( DIRAC_ENC_DATA ) ) ) == NULL )
77 : {
78 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
79 : }
80 :
81 281 : IF( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL )
82 : {
83 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) );
84 : }
85 281 : hDirAC->firstrun_sector_params = 1; /* Q0 */
86 281 : move16();
87 :
88 281 : set32_fx( hDirAC->sec_I_vec_smth_x_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
89 281 : set16_fx( hDirAC->sec_I_vec_smth_x_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
90 281 : set32_fx( hDirAC->sec_I_vec_smth_y_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
91 281 : set16_fx( hDirAC->sec_I_vec_smth_y_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
92 281 : set32_fx( hDirAC->sec_I_vec_smth_z_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
93 281 : set16_fx( hDirAC->sec_I_vec_smth_z_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
94 281 : set32_fx( hDirAC->energy_smth_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
95 281 : set16_fx( hDirAC->energy_smth_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
96 281 : set32_fx( hDirAC->ele_prev_fx, 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
97 281 : set32_fx( hDirAC->azi_prev_fx, 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS );
98 : /*-----------------------------------------------------------------*
99 : * DirAC main configuration
100 : *-----------------------------------------------------------------*/
101 :
102 281 : st_ivas->hDirAC = hDirAC;
103 :
104 281 : IF( ( error = ivas_dirac_config_fx( (void *) st_ivas, ENC ) ) != IVAS_ERR_OK )
105 : {
106 0 : return error;
107 : }
108 :
109 : /* set FB config. */
110 281 : hDirAC->hFbMixer = NULL;
111 :
112 3934 : FOR( i = 0; i < DIRAC_MAX_NBANDS + 1; i++ )
113 : {
114 : /* adapt band grouping to from CLDFB to MDFT bands */
115 3653 : hDirAC->band_grouping[i] = imult1616( hDirAC->band_grouping[i], CLDFB_TO_MDFT_FAC ); /* Q0 */
116 3653 : move16();
117 : }
118 281 : dirac_slot_ns = DIRAC_SLOT_ENC_NS;
119 281 : move16();
120 : /* initialize delay for SPAR/DirAC delay synchronization */
121 :
122 : /* intensity 3-dim */
123 1124 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
124 : {
125 843 : IF( ( hDirAC->direction_vector_m_fx[i] = (Word32 **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word32 * ) ) ) == NULL )
126 : {
127 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
128 : }
129 :
130 4215 : FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
131 : {
132 3372 : IF( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL )
133 : {
134 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
135 : }
136 3372 : set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS );
137 : }
138 : }
139 :
140 281 : Word16 tmp_e = 0;
141 281 : move16();
142 281 : Word16 tmp = BASOP_Util_Divide3232_Scale( (Word32) DIRAC_NO_COL_AVG_DIFF_NS, dirac_slot_ns, &tmp_e ); /* exp(tmp_e) */
143 281 : hDirAC->no_col_avg_diff = shr( tmp, sub( 15, tmp_e ) );
144 281 : move16();
145 :
146 281 : set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS );
147 281 : set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS );
148 :
149 1124 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
150 : {
151 843 : IF( ( hDirAC->buffer_intensity_real_fx[i] = (Word32 **) malloc( hDirAC->no_col_avg_diff * sizeof( Word32 * ) ) ) == NULL )
152 : {
153 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
154 : }
155 7587 : FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ )
156 : {
157 6744 : IF( ( hDirAC->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL )
158 : {
159 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
160 : }
161 6744 : set32_fx( hDirAC->buffer_intensity_real_fx[i][j], 0, DIRAC_MAX_NBANDS );
162 6744 : set16_fx( hDirAC->buffer_intensity_real_q[i][j], Q31, hDirAC->hConfig->nbands );
163 : }
164 : }
165 :
166 281 : IF( ( hDirAC->buffer_energy_fx = (Word32 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word32 ) ) ) == NULL )
167 : {
168 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) );
169 : }
170 281 : set32_fx( hDirAC->buffer_energy_fx, 0, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff );
171 281 : set16_fx( hDirAC->buffer_energy_q, Q31, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff );
172 :
173 281 : IF( st_ivas->hQMetaData->useLowerRes )
174 : {
175 37 : hDirAC->block_grouping[0] = 0;
176 37 : hDirAC->block_grouping[1] = MAX_PARAM_SPATIAL_SUBFRAMES;
177 37 : move16();
178 37 : move16();
179 : }
180 : ELSE
181 : {
182 244 : Copy( DirAC_block_grouping_5ms_MDFT, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 );
183 : }
184 :
185 281 : hDirAC->index_buffer_intensity = 0;
186 281 : hDirAC->mono_frame_count = 0;
187 281 : move16();
188 281 : move16();
189 :
190 281 : st_ivas->hDirAC = hDirAC;
191 281 : st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; /* Q0 */
192 281 : move16();
193 :
194 281 : return error;
195 : }
196 :
197 :
198 : /*-------------------------------------------------------------------------
199 : * ivas_dirac_enc_reconfigure()
200 : *
201 : * Reconfigure DirAC handle
202 : *------------------------------------------------------------------------*/
203 :
204 1673 : ivas_error ivas_dirac_enc_reconfigure(
205 : Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */
206 : )
207 : {
208 : DIRAC_ENC_HANDLE hDirAC;
209 : ivas_error error;
210 :
211 1673 : error = IVAS_ERR_OK;
212 1673 : move32();
213 :
214 1673 : hDirAC = st_ivas->hDirAC;
215 :
216 : /*-----------------------------------------------------------------*
217 : * DirAC main configuration
218 : *-----------------------------------------------------------------*/
219 :
220 1673 : IF( NE_32( ( error = ivas_dirac_config_fx( (void *) st_ivas, ENC ) ), IVAS_ERR_OK ) )
221 : {
222 0 : return error;
223 : }
224 :
225 1673 : IF( st_ivas->hQMetaData->useLowerRes )
226 : {
227 359 : hDirAC->block_grouping[0] = 0;
228 359 : move16();
229 359 : hDirAC->block_grouping[1] = MAX_PARAM_SPATIAL_SUBFRAMES;
230 359 : move16();
231 : }
232 : ELSE
233 : {
234 1314 : MVR2R_WORD16( DirAC_block_grouping_5ms_MDFT, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 );
235 : }
236 :
237 1673 : return error;
238 : }
239 :
240 :
241 : /*-------------------------------------------------------------------------
242 : * ivas_dirac_enc_close()
243 : *
244 : * Close DirAC encoder handle
245 : *------------------------------------------------------------------------*/
246 627 : void ivas_dirac_enc_close_fx(
247 : DIRAC_ENC_HANDLE *hDirAC_out, /* i/o: encoder DirAC handle */
248 : const Word32 input_Fs /* i : input sampling rate Q0*/
249 : )
250 : {
251 : Word16 i, j;
252 : DIRAC_ENC_HANDLE hDirAC;
253 :
254 627 : test();
255 627 : IF( hDirAC_out == NULL || *hDirAC_out == NULL )
256 : {
257 346 : return;
258 : }
259 :
260 281 : hDirAC = *hDirAC_out;
261 :
262 281 : IF( hDirAC->hFbMixer != NULL )
263 : {
264 0 : ivas_FB_mixer_close_fx( &hDirAC->hFbMixer, input_Fs, 0 );
265 : }
266 : /* intensity 3-dim */
267 1124 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
268 : {
269 4215 : FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
270 : {
271 3372 : free( hDirAC->direction_vector_m_fx[i][j] );
272 3372 : hDirAC->direction_vector_m_fx[i][j] = NULL;
273 : }
274 :
275 7587 : FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ )
276 : {
277 6744 : IF( hDirAC->buffer_intensity_real_fx[i][j] != 0 )
278 : {
279 6744 : free( hDirAC->buffer_intensity_real_fx[i][j] );
280 6744 : hDirAC->buffer_intensity_real_fx[i][j] = NULL;
281 : }
282 : }
283 :
284 843 : free( hDirAC->buffer_intensity_real_fx[i] );
285 843 : hDirAC->buffer_intensity_real_fx[i] = NULL;
286 :
287 843 : free( hDirAC->direction_vector_m_fx[i] );
288 843 : hDirAC->direction_vector_m_fx[i] = NULL;
289 : }
290 :
291 281 : free( hDirAC->buffer_energy_fx );
292 281 : hDirAC->buffer_energy_fx = NULL;
293 :
294 281 : IF( hDirAC->hConfig != NULL )
295 : {
296 281 : free( hDirAC->hConfig );
297 281 : hDirAC->hConfig = NULL;
298 : }
299 :
300 281 : free( *hDirAC_out );
301 281 : *hDirAC_out = NULL;
302 :
303 281 : return;
304 : }
305 :
306 : /*-------------------------------------------------------------------------
307 : * ivas_dirac_enc()
308 : *
309 : * DirAC Encoder
310 : *
311 : *------------------------------------------------------------------------*/
312 :
313 159500 : ivas_error ivas_dirac_enc_fx(
314 : DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */
315 : IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */
316 : BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */
317 : Word32 *data_f_fx[], /* i/o: SBA channels Qx*/
318 : Word32 **pp_fr_real_fx, /* o : real freq domain values pp_fr_q*/
319 : Word32 **pp_fr_imag_fx, /* o : imag freq domain values pp_fr_q*/
320 : Word16 pp_fr_q,
321 : const Word16 input_frame, /* i : input frame length Q0*/
322 : const Word16 dtx_vad, /* i : DTX vad flag Q0*/
323 : const IVAS_FORMAT ivas_format, /* i : ivas format */
324 : const Word16 nchan_transport, /* i : number of transport channels */
325 : const Word16 hodirac_flag, /* i : hodirac flag Q0*/
326 : const Word16 shift )
327 : {
328 : Word16 orig_dirac_bands;
329 : Word32 dir_fx[3], avg_dir_fx[3];
330 : Word16 i, j, b, i_ts;
331 : ivas_error error;
332 159500 : push_wmops( "ivas_dirac_enc" );
333 :
334 : Word16 nchan_fb_in;
335 :
336 159500 : IF( hodirac_flag )
337 : {
338 16240 : nchan_fb_in = HOA2_CHANNELS;
339 16240 : move16();
340 : }
341 : ELSE
342 : {
343 143260 : nchan_fb_in = FOA_CHANNELS;
344 143260 : move16();
345 : }
346 :
347 159500 : ivas_dirac_param_est_enc_fx( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ), shift );
348 :
349 159500 : IF( hQMetaData->q_direction->cfg.nbands > 0 )
350 : {
351 159500 : orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; /* Q0 */
352 159500 : move16();
353 :
354 159500 : IF( EQ_16( dtx_vad, 1 ) )
355 : {
356 : /* WB 4TC mode bit : disable for now*/
357 157895 : push_next_indice( hMetaData, 0, 1 );
358 :
359 : /* Set Energy Ratio to 0.0 if the mono flag is set, before the metadata is encoded */
360 157895 : IF( hQMetaData->dirac_mono_flag )
361 : {
362 0 : IF( EQ_16( dtx_vad, 1 ) )
363 : {
364 0 : FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ )
365 : {
366 0 : FOR( i_ts = 0; i_ts < hQMetaData->q_direction[0].cfg.nblocks; i_ts++ )
367 : {
368 0 : hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0;
369 0 : hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0;
370 0 : hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0;
371 0 : move32();
372 0 : move32();
373 0 : move32();
374 : }
375 : }
376 : }
377 : ELSE
378 : {
379 0 : FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ )
380 : {
381 0 : FOR( i_ts = 0; i_ts < 1; i_ts++ )
382 : {
383 0 : hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0;
384 0 : hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0;
385 0 : hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0;
386 0 : move32();
387 0 : move32();
388 0 : move32();
389 : }
390 : }
391 : }
392 : }
393 :
394 157895 : IF( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK )
395 : {
396 0 : return error;
397 : }
398 : }
399 : ELSE
400 : {
401 1605 : hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS;
402 1605 : move16();
403 : /* compute directions */
404 7473 : FOR( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ )
405 : {
406 5868 : set32_fx( avg_dir_fx, 0, 3 );
407 5868 : Word16 avg_dir_e = 0;
408 5868 : Word16 energySum_e = 0;
409 5868 : Word32 energySum_fx = 0;
410 5868 : move32();
411 5868 : move16();
412 5868 : move16();
413 :
414 : /* combine all DirAC bands except the last one, handle last band separately, last band covers BW above WB */
415 17420 : FOR( j = 0; j < sub( orig_dirac_bands, 1 ); j++ )
416 : {
417 11552 : ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] );
418 :
419 11552 : Word32 vecLen_fx = Mpy_32_32( hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] /*Q30*/, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j] ); /* hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 */
420 11552 : avg_dir_fx[0] = L_add( avg_dir_fx[0], Mpy_32_32( dir_fx[0], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31
421 11552 : avg_dir_fx[1] = L_add( avg_dir_fx[1], Mpy_32_32( dir_fx[1], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31
422 11552 : avg_dir_fx[2] = L_add( avg_dir_fx[2], Mpy_32_32( dir_fx[2], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31
423 11552 : move32();
424 11552 : move32();
425 11552 : move32();
426 11552 : avg_dir_e = sub( 31, ( sub( add( Q30, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), 1 - 31 ) ) );
427 11552 : energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j], sub( 31, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), &energySum_e ); /* exp(energySum_e) */
428 : }
429 :
430 5868 : Word16 x = getScaleFactor32( avg_dir_fx, 3 );
431 5868 : Scale_sig32( avg_dir_fx, 3, sub( x, 1 ) );
432 5868 : avg_dir_e = sub( avg_dir_e, sub( x, 1 ) );
433 :
434 5868 : ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( &avg_dir_fx[0], Q30, &hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], &hQMetaData->q_direction[0].band_data[0].elevation_fx[i] );
435 :
436 5868 : Word32 tmp = dotp_fixed( avg_dir_fx, avg_dir_fx, 3 ); // 2*avg_dir_e
437 5868 : Word16 tmp_e = shl( avg_dir_e, 1 );
438 5868 : tmp = Sqrt32( tmp, &tmp_e );
439 5868 : Word16 er_tmp_e = 0;
440 5868 : move16();
441 5868 : Word16 er_tmp = 0;
442 5868 : move16();
443 5868 : Word16 denom_e = 0;
444 5868 : move16();
445 5868 : Word32 denom = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, EPSILON_FX_M, EPSILON_FX_E, &denom_e ); /* exp(denom_e) */
446 :
447 5868 : er_tmp = BASOP_Util_Divide3232_Scale( tmp, denom, &er_tmp_e ); /* exp(er_tmp_e) */
448 5868 : er_tmp_e = add( er_tmp_e, sub( tmp_e, denom_e ) );
449 5868 : er_tmp = shr( er_tmp, sub( 1, ( er_tmp_e ) ) ); // Q14
450 :
451 5868 : hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[i] = L_deposit_h( er_tmp ); // Q30
452 5868 : hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; // Q22
453 5868 : hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; // Q22
454 5868 : hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i]; // Q30
455 5868 : move32();
456 5868 : move32();
457 5868 : move32();
458 5868 : move32();
459 : }
460 :
461 : /* 1 bit to indicate mode MD coding : temp solution*/
462 1605 : push_next_indice( hMetaData, 1, 1 );
463 :
464 : /* encode SID parameters */
465 1605 : ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, -1, nchan_transport, SBA_FORMAT );
466 : }
467 :
468 159500 : Word16 len = 0;
469 159500 : move16();
470 159500 : IF( EQ_16( dtx_vad, 1 ) )
471 : {
472 157895 : len = hQMetaData->q_direction[0].cfg.nblocks;
473 157895 : move16();
474 : }
475 : ELSE
476 : {
477 1605 : len = 1;
478 1605 : move16();
479 : }
480 752946 : FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ )
481 : {
482 2877386 : FOR( i_ts = 0; i_ts < len; i_ts++ )
483 : {
484 2283940 : hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; // Q22
485 2283940 : hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; // Q22
486 2283940 : hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); // Q30
487 2283940 : move32();
488 2283940 : move32();
489 2283940 : move32();
490 : }
491 : }
492 :
493 159500 : IF( dtx_vad == 0 )
494 : {
495 8025 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
496 : {
497 6420 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; // Q22
498 6420 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; // Q22
499 6420 : hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0]; // Q30
500 6420 : move32();
501 6420 : move32();
502 6420 : move32();
503 : }
504 :
505 8025 : FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
506 : {
507 18524 : FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- )
508 : {
509 12104 : hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; // Q22
510 12104 : hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; // Q22
511 12104 : hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0]; // Q30
512 12104 : move32();
513 12104 : move32();
514 12104 : move32();
515 : }
516 : }
517 :
518 1605 : hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; /* Q0 */
519 1605 : move16();
520 : }
521 : }
522 :
523 159500 : pop_wmops();
524 :
525 159500 : return IVAS_ERR_OK;
526 : }
527 :
528 :
529 : /*-------------------------------------------------------------------------
530 : * ivas_dirac_get_mono_flag()
531 : *
532 : *
533 : *-------------------------------------------------------------------------*/
534 :
535 638000 : static Word16 ivas_dirac_get_mono_flag_fx(
536 : const Word16 *band_grouping, /* i : Band grouping for estimation Q0*/
537 : Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal e_Cldfb*/
538 : Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal e_Cldfb*/
539 : Word16 e_Cldfb, /* i : Exponent of cldfb buffer */
540 : const Word16 nchan_ana, /* i : number of analysis channels Q0*/
541 : Word16 *mono_frame_count ) /* i/o: current number of mono frames count Q0*/
542 : {
543 : Word16 brange[2];
544 : Word16 i, j, ch_idx;
545 : Word32 other_ch_band_power;
546 : Word32 W_band_power;
547 638000 : Word16 any_mc_band = 0;
548 638000 : Word16 any_mono_band = 0;
549 638000 : Word16 local_mono_flag = 0;
550 : Word32 W_band_power_norm;
551 638000 : Word32 threshold = 0;
552 638000 : Word16 W_band_power_e = 0;
553 638000 : Word16 other_ch_band_power_e = 0;
554 638000 : move16();
555 638000 : move16();
556 638000 : move16();
557 638000 : move16();
558 638000 : move16();
559 638000 : move32();
560 :
561 : /* Banded Power Calculations */
562 8294000 : FOR( i = 0; i < DIRAC_MAX_NBANDS; i++ )
563 : {
564 7656000 : W_band_power = 0;
565 7656000 : other_ch_band_power = 0;
566 7656000 : move32();
567 7656000 : move32();
568 :
569 7656000 : brange[0] = band_grouping[i]; /* Q0 */
570 7656000 : brange[1] = band_grouping[i + 1]; /* Q0 */
571 7656000 : move16();
572 7656000 : move16();
573 :
574 7656000 : Word64 acc = 0, acc1 = 0;
575 7656000 : move64();
576 7656000 : move64();
577 :
578 7656000 : Word16 shift1 = 0;
579 7656000 : Word16 shift2 = 0;
580 7656000 : move16();
581 7656000 : move16();
582 :
583 7656000 : Word16 gb = find_guarded_bits_fx( sub( brange[1], brange[0] ) );
584 :
585 : /* Loop over the W channel bins to calculate the power in the band */
586 116721600 : FOR( j = brange[0]; j < brange[1]; j++ )
587 : {
588 109065600 : acc = W_mac_32_32( acc, L_shr( Cldfb_RealBuffer[0][j], gb ), L_shr( Cldfb_RealBuffer[0][j], gb ) ); /*Q:(2*(31-e_Cldfb-gb)+1*/
589 109065600 : acc = W_mac_32_32( acc, L_shr( Cldfb_ImagBuffer[0][j], gb ), L_shr( Cldfb_ImagBuffer[0][j], gb ) ); /*Q:(2*(31-e_Cldfb-gb)+1*/
590 : }
591 7656000 : shift1 = W_norm( acc );
592 7656000 : W_band_power = W_extract_h( W_shl( acc, shift1 ) ); /*Q:(2*(31-e_Cldfb-gb)+1+shift1-32*/
593 7656000 : W_band_power_e = sub( shl( add( e_Cldfb, gb ), 1 ), shift1 );
594 :
595 7656000 : gb = find_guarded_bits_fx( imult1616( sub( brange[1], brange[0] ), sub( nchan_ana, 1 ) ) );
596 : /* Loop over the other channels and bins to calculate the power in the band */
597 30624000 : FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ )
598 : {
599 : /* abs()^2 */
600 350164800 : FOR( j = brange[0]; j < brange[1]; j++ )
601 : {
602 327196800 : acc1 = W_mac_32_32( acc1, L_shr( Cldfb_RealBuffer[ch_idx][j], gb ), L_shr( Cldfb_RealBuffer[ch_idx][j], gb ) ); /*Q:(2*(31-e_Cldfb-gb)+1*/
603 327196800 : acc1 = W_mac_32_32( acc1, L_shr( Cldfb_ImagBuffer[ch_idx][j], gb ), L_shr( Cldfb_ImagBuffer[ch_idx][j], gb ) ); /*Q:(2*(31-e_Cldfb-gb)+1*/
604 : }
605 : }
606 7656000 : shift2 = W_norm( acc1 );
607 7656000 : other_ch_band_power = W_extract_h( W_shl( acc1, shift2 ) ); /*Q:(2*(31-e_Cldfb-gb)+1+shift2-32*/
608 7656000 : other_ch_band_power_e = sub( shl( add( e_Cldfb, gb ), 1 ), shift2 );
609 :
610 7656000 : IF( BASOP_Util_Cmp_Mant32Exp( other_ch_band_power, other_ch_band_power_e, EPSILON_FX_M, EPSILON_FX_E ) < 0 )
611 : {
612 768816 : if ( BASOP_Util_Cmp_Mant32Exp( W_band_power, W_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 )
613 : {
614 136 : any_mono_band = 1;
615 136 : move16();
616 : }
617 : }
618 : ELSE
619 : {
620 6887184 : test();
621 6887184 : IF( ( BASOP_Util_Cmp_Mant32Exp( W_band_power, W_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 ) || ( BASOP_Util_Cmp_Mant32Exp( other_ch_band_power, other_ch_band_power_e, DIRAC_MONO_THRESH_SILENCE_FX, 31 ) > 0 ) )
622 : {
623 6270130 : Word16 tmp_div_e = 0;
624 6270130 : move16();
625 6270130 : Word16 tmp_div = BASOP_Util_Divide3232_Scale( W_band_power, DIRAC_MONO_NORM_FACTOR_M, &tmp_div_e ); /* exp(tmp_div_e) */
626 6270130 : tmp_div_e = add( tmp_div_e, sub( W_band_power_e, DIRAC_MONO_NORM_FACTOR_E ) );
627 6270130 : Word16 W_band_power_norm_e = 0;
628 6270130 : move16();
629 6270130 : Word16 flag = BASOP_Util_Cmp_Mant32Exp( tmp_div, tmp_div_e, ONE_IN_Q14, 1 );
630 6270130 : IF( EQ_16( flag, 1 ) )
631 : {
632 9382 : W_band_power_norm = 1;
633 9382 : move16();
634 9382 : W_band_power_norm_e = 31;
635 9382 : move16();
636 : }
637 : ELSE
638 : {
639 6260748 : W_band_power_norm = L_deposit_h( tmp_div );
640 6260748 : W_band_power_norm_e = tmp_div_e;
641 6260748 : move16();
642 : }
643 6270130 : Word32 tmp_2 = Mpy_32_32( W_band_power_norm, DIRAC_MONO_MAX_THRESH_FX ); // W_band_power_norm_e+31
644 6270130 : Word32 tmp_3 = W_extract_h( W_shl( DIRAC_MONO_MIN_THRESH_FX, sub( 31, add( W_band_power_norm_e, 31 ) ) ) );
645 6270130 : tmp_3 = DIRAC_MONO_MIN_THRESH_FX; // exp31
646 6270130 : move32();
647 6270130 : Word16 flag2 = BASOP_Util_Cmp_Mant32Exp( tmp_2, add( W_band_power_norm_e, 31 ), tmp_3, 31 );
648 :
649 6270130 : Word16 threshold_e = 0;
650 6270130 : move16();
651 6270130 : IF( EQ_16( flag2, 1 ) )
652 : {
653 1908371 : threshold = tmp_2;
654 1908371 : move32();
655 1908371 : threshold_e = add( W_band_power_norm_e, 31 );
656 : }
657 : ELSE
658 : {
659 4361759 : threshold = DIRAC_MONO_MIN_THRESH_FX;
660 4361759 : threshold_e = 31;
661 4361759 : move32();
662 4361759 : move16();
663 : }
664 6270130 : IF( BASOP_Util_Cmp_Mant32Exp( W_band_power, W_band_power_e, Mpy_32_32( other_ch_band_power, threshold ), other_ch_band_power_e + threshold_e ) == 1 )
665 : {
666 1309 : any_mono_band = 1;
667 1309 : move16();
668 : }
669 : ELSE
670 : {
671 6268821 : any_mc_band = 1;
672 6268821 : move16();
673 : }
674 : }
675 : }
676 : }
677 :
678 : /* If any band contains multi-channel content it's not mono */
679 638000 : IF( any_mc_band )
680 : {
681 624593 : local_mono_flag = 0;
682 624593 : move16();
683 : }
684 : ELSE
685 : {
686 : /* If any band contains mono content the frame is mono. */
687 13407 : if ( any_mono_band )
688 : {
689 341 : local_mono_flag = 1;
690 341 : move16();
691 : }
692 : }
693 :
694 : /* Hysteresis - only after DIRAC_MONO_FRAME_THRESH frames on mono will the actual mono flag be set */
695 638000 : IF( local_mono_flag )
696 : {
697 341 : IF( LT_16( *mono_frame_count, DIRAC_MONO_FRAME_THRESH ) )
698 : {
699 341 : *mono_frame_count = add( *mono_frame_count, 1 ); /* Q0 */
700 341 : move16();
701 : }
702 : }
703 : ELSE
704 : {
705 : /* Instantaneously disable actual mono flag if multi-channel content is observed */
706 637659 : if ( any_mc_band )
707 : {
708 624593 : *mono_frame_count = 0;
709 624593 : move16();
710 : }
711 : }
712 :
713 : /* Final check if there has been mono for DIRAC_MONO_FRAME_THRESH number of frames than the content is declared mono */
714 638000 : IF( EQ_16( *mono_frame_count, DIRAC_MONO_FRAME_THRESH ) )
715 : {
716 0 : return 1;
717 : }
718 : ELSE
719 : {
720 638000 : return 0;
721 : }
722 : }
723 :
724 : /*-------------------------------------------------------------------------
725 : * computeReferencePower_enc_fx_dirac()
726 : *
727 : *
728 : *-------------------------------------------------------------------------*/
729 :
730 638000 : void computeReferencePower_enc_fx_dirac(
731 : const Word16 *band_grouping, /* i : Band grouping for estimation */
732 : Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal e_Cldfb*/
733 : Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal e_Cldfb*/
734 : Word16 e_Cldfb, /* i : exponent of Cldfb buffer */
735 : Word32 *reference_power, /* o : Estimated power e_reference*/
736 : Word16 *e_reference, /* o : exponent of reference_power */
737 : const Word16 enc_param_start_band, /* i : first band to process Q0*/
738 : const Word16 num_freq_bands, /* i : Number of frequency bands Q0*/
739 : const IVAS_FORMAT ivas_format, /* i : ivas_format */
740 : Word16 ref_power_w, /* i : use 0 if hodirac is enabled Q0*/
741 : const Word16 nchan_ana, /* i : number of analysis channels Q0*/
742 : Word16 *mono_frame_count, /* i/o: Mono Frame Count Q0*/
743 : Word16 *dirac_mono_flag /* i/o: Mono Flag Q0*/
744 : )
745 : {
746 : Word16 brange[2];
747 : Word16 ch_idx, i, j;
748 : Word64 reference_power_temp[DIRAC_MAX_NBANDS];
749 : Word64 reference_power_W[DIRAC_MAX_NBANDS];
750 638000 : Word16 e_reference_W = 0, e_reference_temp = 0;
751 : Word16 min_norm;
752 638000 : move16();
753 638000 : move16();
754 :
755 638000 : IF( dirac_mono_flag != NULL )
756 : {
757 638000 : *dirac_mono_flag = ivas_dirac_get_mono_flag_fx( band_grouping, Cldfb_RealBuffer, Cldfb_ImagBuffer, e_Cldfb, nchan_ana, mono_frame_count ); /* Q0 */
758 638000 : move16();
759 : }
760 638000 : Word16 gb = 0;
761 638000 : move16();
762 3017468 : FOR( i = 0; i < num_freq_bands; i++ )
763 : {
764 2379468 : brange[0] = band_grouping[i + enc_param_start_band];
765 2379468 : brange[1] = band_grouping[i + enc_param_start_band + 1];
766 2379468 : move16();
767 2379468 : move16();
768 2379468 : gb = s_max( gb, find_guarded_bits_fx( sub( brange[1], brange[0] ) ) );
769 : }
770 638000 : e_reference_W = sub( 31, sub( add( shl( sub( 31, e_Cldfb ), 1 ), 1 ), gb ) );
771 638000 : e_reference_temp = e_reference_W;
772 638000 : move16();
773 3017468 : FOR( i = 0; i < num_freq_bands; i++ )
774 : {
775 2379468 : brange[0] = band_grouping[i + enc_param_start_band];
776 2379468 : brange[1] = band_grouping[i + enc_param_start_band + 1];
777 2379468 : move16();
778 2379468 : move16();
779 :
780 2379468 : reference_power_temp[i] = 0;
781 2379468 : move64();
782 :
783 2379468 : reference_power_W[i] = 0;
784 2379468 : move64();
785 :
786 88681228 : FOR( j = brange[0]; j < brange[1]; j++ )
787 : {
788 86301760 : reference_power_W[i] = W_add( reference_power_W[i], W_shr( W_mult_32_32( Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ), gb ) ); /* exp(2 * e_Cldfb) */
789 86301760 : reference_power_W[i] = W_add( reference_power_W[i], W_shr( W_mult_32_32( Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ), gb ) ); /* exp(2 * e_Cldfb) */
790 86301760 : move64();
791 86301760 : move64();
792 : }
793 2379468 : reference_power_temp[i] = W_add( reference_power_temp[i], reference_power_W[i] ); /* exp(2 * e_Cldfb) */
794 2379468 : move64();
795 :
796 9517872 : FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ )
797 : {
798 : /* abs()^2 */
799 266043684 : FOR( j = brange[0]; j < brange[1]; j++ )
800 : {
801 258905280 : reference_power_temp[i] = W_add( reference_power_temp[i], W_shr( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), gb ) ); /* exp(2 * e_Cldfb) */
802 258905280 : reference_power_temp[i] = W_add( reference_power_temp[i], W_shr( W_mult_32_32( Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ), gb ) ); /* exp(2 * e_Cldfb) */
803 258905280 : move64();
804 258905280 : move64();
805 : }
806 : }
807 : }
808 :
809 3017468 : FOR( i = 0; i < num_freq_bands; i++ )
810 : {
811 2379468 : reference_power_temp[i] = W_shr( reference_power_temp[i], 1 ); /* exp(2 * e_Cldfb + 1) */
812 2379468 : move64();
813 : }
814 :
815 638000 : test();
816 638000 : IF( EQ_16( ivas_format, SBA_FORMAT ) && EQ_16( ref_power_w, 1 ) )
817 : {
818 1768672 : FOR( i = 0; i < num_freq_bands; i++ )
819 : {
820 1315832 : IF( BASOP_Util_Cmp_Mant32Exp( W_extract_h( reference_power_temp[i] ), e_reference_temp, W_extract_h( reference_power_W[i] ), e_reference_W ) < 0 )
821 : {
822 611195 : reference_power_temp[i] = reference_power_W[i]; /* exp(2 * e_Cldfb + 1 ) */
823 611195 : move64();
824 : }
825 : }
826 : }
827 :
828 3017468 : FOR( i = 0; i < num_freq_bands; i++ )
829 : {
830 2379468 : min_norm = W_norm( reference_power_temp[i] );
831 2379468 : reference_power[i] = W_extract_h( W_shl( reference_power_temp[i], min_norm ) ); // Right shift with min_norm and extract high bits
832 2379468 : move32();
833 2379468 : e_reference[i] = sub( 31, sub( add( sub( 31, e_reference_temp ), min_norm ), 32 ) );
834 2379468 : move16();
835 : }
836 638000 : move16();
837 :
838 638000 : return;
839 : }
840 :
841 46720 : void computeReferencePower_enc_fx(
842 : const Word16 *band_grouping, /* i : Band grouping for estimation Q0*/
843 : Word32 Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal inp_q*/
844 : Word32 Cldfb_ImagBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Imag part of input signal inp_q*/
845 : Word32 *reference_power, /* o : Estimated power ref_exp*/
846 : const Word16 enc_param_start_band, /* i : first band to process Q0*/
847 : const Word16 num_freq_bands, /* i : Number of frequency bands Q0*/
848 : const IVAS_FORMAT ivas_format, /* i : ivas_format */
849 : Word16 ref_power_w, /* i : use 0 if hodirac is enabled Q0*/
850 : const Word16 nchan_ana, /* i : number of analysis channels Q0*/
851 : Word16 inp_q, /* i : q of cld buffers */
852 : Word16 q_reference_power[DIRAC_NO_FB_BANDS_MAX] )
853 : {
854 : Word16 brange[2];
855 : Word16 ch_idx, i, j;
856 : Word16 num_bins, guard_bits, norm;
857 :
858 : Word64 reference_power_tmp[DIRAC_MAX_NBANDS];
859 : Word64 reference_power_W[DIRAC_MAX_NBANDS];
860 :
861 46720 : Word16 shift_ref_power = sub( shl( inp_q, 1 ), 31 );
862 :
863 280320 : FOR( i = 0; i < num_freq_bands; i++ )
864 : {
865 233600 : brange[0] = band_grouping[i + enc_param_start_band]; /* Q0 */
866 233600 : move16();
867 233600 : brange[1] = band_grouping[i + enc_param_start_band + 1]; /* Q0 */
868 233600 : move16();
869 233600 : reference_power[i] = 0;
870 233600 : move32();
871 233600 : reference_power_W[i] = 0;
872 233600 : move64();
873 233600 : reference_power_tmp[i] = 0;
874 233600 : move64();
875 :
876 233600 : num_bins = sub( brange[1], brange[0] );
877 233600 : guard_bits = find_guarded_bits_fx( num_bins );
878 :
879 11382400 : FOR( j = brange[0]; j < brange[1]; j++ )
880 : {
881 11148800 : reference_power_W[i] = W_add( reference_power_W[i], W_shr( W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[0][j], Cldfb_RealBuffer[0][j] ), Cldfb_ImagBuffer[0][j], Cldfb_ImagBuffer[0][j] ), guard_bits ) ); // 2*inp_q + 1 - guard_bits
882 11148800 : move64();
883 : }
884 233600 : reference_power_tmp[i] = W_add( reference_power_tmp[i], reference_power_W[i] ); // 2*inp_q + 1 - guard_bits
885 233600 : move64();
886 934400 : FOR( ch_idx = 1; ch_idx < nchan_ana; ch_idx++ )
887 : {
888 : /* abs()^2 */
889 34147200 : FOR( j = brange[0]; j < brange[1]; j++ )
890 : {
891 33446400 : reference_power_tmp[i] = W_add( reference_power_tmp[i], W_shr( W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ), guard_bits ) ); // 2*inp_q + 1 - guard_bits
892 33446400 : move64();
893 : }
894 : }
895 233600 : q_reference_power[i] = sub( shift_ref_power, guard_bits );
896 233600 : move16();
897 : }
898 280320 : FOR( i = 0; i < num_freq_bands; i++ )
899 : {
900 233600 : reference_power_tmp[i] = W_shr( reference_power_tmp[i], 1 ); // 2*inp_q + 1
901 233600 : move64();
902 : }
903 :
904 46720 : test();
905 46720 : IF( EQ_16( ivas_format, SBA_FORMAT ) && EQ_16( ref_power_w, 1 ) )
906 : {
907 0 : FOR( i = 0; i < num_freq_bands; i++ )
908 : {
909 0 : IF( LT_64( reference_power_tmp[i], reference_power_W[i] ) )
910 : {
911 0 : reference_power_tmp[i] = reference_power_W[i]; // 2*inp_q + 1
912 0 : move64();
913 : }
914 : }
915 : }
916 :
917 280320 : FOR( i = 0; i < num_freq_bands; i++ )
918 : {
919 233600 : norm = 63;
920 233600 : move16();
921 233600 : IF( reference_power_tmp[i] != 0 )
922 : {
923 232115 : norm = W_norm( reference_power_tmp[i] );
924 : }
925 233600 : reference_power[i] = W_extract_h( W_shl( reference_power_tmp[i], norm ) ); // 2 * inp_q + 1 - guard_bits + norm - 32
926 233600 : move32();
927 233600 : q_reference_power[i] = add( q_reference_power[i], norm );
928 233600 : move16();
929 : }
930 :
931 46720 : return;
932 : }
933 : /*-------------------------------------------------------------------------
934 : * ivas_dirac_param_est_enc()
935 : *
936 : *
937 : *------------------------------------------------------------------------*/
938 :
939 159500 : void ivas_dirac_param_est_enc_fx(
940 : DIRAC_ENC_HANDLE hDirAC,
941 : IVAS_QDIRECTION *q_direction,
942 : const UWord8 useLowerRes, /* Q0 */
943 : Word32 *data_f_fx[], /* Qx */
944 : Word32 **pp_fr_real_fx, /* pp_fr_q */
945 : Word32 **pp_fr_imag_fx, /* pp_fr_q */
946 : Word16 pp_fr_q,
947 : const Word16 input_frame, /* Q0 */
948 : const IVAS_FORMAT ivas_format,
949 : const Word16 hodirac_flag, /* Q0 */
950 : const Word16 nchan_fb_in, /* Q0 */
951 : Word16 *mono_frame_count, /* Q0 */
952 : Word16 *dirac_mono_flag, /* Q0 */
953 : const Word16 shift )
954 : {
955 : Word16 i, j, k, d, ts, index, l_ts, num_freq_bands;
956 : Word16 band_m_idx, block_m_idx;
957 : Word32 dir_v_fx[DIRAC_NUM_DIMS];
958 : Word32 *pcm_in_fx[DIRAC_MAX_ANA_CHANS];
959 : Word32 Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX];
960 : Word32 Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX];
961 : Word32 *p_Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS];
962 : Word32 *p_Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS];
963 : Word16 cldfb_q;
964 : Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS];
965 : Word16 intensity_real_q[DIRAC_MAX_NBANDS];
966 : Word32 direction_vector_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS];
967 : Word16 direction_vector_q;
968 : Word32 diffuseness_vector_fx[DIRAC_MAX_NBANDS];
969 : Word16 diffuseness_vector_q;
970 : Word32 renormalization_factor_fx[DIRAC_MAX_NBANDS];
971 : Word16 renormalization_factor_exp[DIRAC_MAX_NBANDS];
972 : Word32 renormalization_factor_diff_fx[DIRAC_MAX_NBANDS];
973 : Word16 renormalization_factor_diff_exp[DIRAC_MAX_NBANDS];
974 : Word32 norm_tmp_fx;
975 : Word16 norm_tmp_exp;
976 : Word16 mrange[2];
977 : Word16 num_blocks;
978 : Word32 reference_power_fx[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX];
979 : Word16 reference_power_exp[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX];
980 : Word32 azi_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS];
981 : Word32 ele_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS];
982 : Word32 diff_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS];
983 : Word16 diff_secs_exp[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS];
984 : Word32 ene_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS];
985 : Word16 ene_secs_exp[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS];
986 :
987 159500 : push_wmops( "dirac_enc_param_est" );
988 159500 : num_freq_bands = hDirAC->hConfig->nbands; /* Q0 */
989 159500 : move16();
990 :
991 : /* Initialization */
992 159500 : cldfb_q = 0;
993 159500 : move16();
994 :
995 :
996 159500 : direction_vector_q = 0;
997 159500 : move16();
998 159500 : diffuseness_vector_q = 0;
999 159500 : move16();
1000 :
1001 159500 : l_ts = shr( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES_LOG2 ); /* Q0 */
1002 159500 : IF( useLowerRes )
1003 : {
1004 13553 : q_direction->cfg.nblocks = 1;
1005 13553 : move16();
1006 13553 : num_blocks = 1;
1007 13553 : move16();
1008 : }
1009 : ELSE
1010 : {
1011 145947 : q_direction->cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES;
1012 145947 : move16();
1013 145947 : num_blocks = MAX_PARAM_SPATIAL_SUBFRAMES;
1014 145947 : move16();
1015 : }
1016 :
1017 : /* Need to initialize renormalization_factors, direction_m and diffuseness_m */
1018 159500 : set_zero_fx( hDirAC->diffuseness_m_fx, hDirAC->hConfig->nbands );
1019 159500 : set16_zero_fx( hDirAC->diffuseness_m_exp, hDirAC->hConfig->nbands );
1020 159500 : set_zero_fx( renormalization_factor_diff_fx, hDirAC->hConfig->nbands );
1021 159500 : set16_zero_fx( renormalization_factor_diff_exp, hDirAC->hConfig->nbands );
1022 2711500 : FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ )
1023 : {
1024 2552000 : set16_zero_fx( reference_power_exp[i], DIRAC_NO_FB_BANDS_MAX );
1025 : }
1026 :
1027 159500 : set_zero_fx( azi_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS );
1028 159500 : set_zero_fx( ele_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS );
1029 159500 : set_zero_fx( diff_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS );
1030 159500 : set16_zero_fx( diff_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS );
1031 159500 : set_zero_fx( ene_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS );
1032 159500 : set16_zero_fx( ene_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS );
1033 :
1034 : /* Copy current frame to memory for delay compensation */
1035 878700 : FOR( i = 0; i < nchan_fb_in; i++ )
1036 : {
1037 719200 : pcm_in_fx[i] = data_f_fx[i];
1038 719200 : p_Cldfb_RealBuffer_fx[i] = &Cldfb_RealBuffer_fx[i][0];
1039 719200 : p_Cldfb_ImagBuffer_fx[i] = &Cldfb_ImagBuffer_fx[i][0];
1040 : }
1041 :
1042 : /* do processing over all CLDFB time slots */
1043 756841 : FOR( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ )
1044 : {
1045 597341 : mrange[0] = hDirAC->block_grouping[block_m_idx]; /* Q0 */
1046 597341 : move16();
1047 597341 : mrange[1] = hDirAC->block_grouping[block_m_idx + 1];
1048 597341 : move16();
1049 :
1050 597341 : set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands );
1051 597341 : set16_fx( renormalization_factor_exp, 0, hDirAC->hConfig->nbands );
1052 597341 : set_zero_fx( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->hConfig->nbands );
1053 597341 : set_zero_fx( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->hConfig->nbands );
1054 597341 : set_zero_fx( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->hConfig->nbands );
1055 : Word64 dir[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS];
1056 597341 : Word16 direction_vector_exp_tmp[DIRAC_NUM_DIMS][MAX_PARAM_SPATIAL_SUBFRAMES][DIRAC_MAX_NBANDS] = { 0 };
1057 2389364 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
1058 : {
1059 1792023 : set64_fx( dir[i], 0, DIRAC_MAX_NBANDS );
1060 8960115 : FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
1061 : {
1062 7168092 : set16_fx( direction_vector_exp_tmp[i][j], 0, DIRAC_MAX_NBANDS );
1063 : }
1064 : }
1065 597341 : hDirAC->direction_vector_m_exp[block_m_idx] = 0;
1066 597341 : move16();
1067 :
1068 1235341 : FOR( ts = mrange[0]; ts < mrange[1]; ts++ )
1069 : {
1070 638000 : IF( hDirAC->hFbMixer )
1071 : {
1072 0 : FOR( i = 0; i < nchan_fb_in; i++ )
1073 : {
1074 0 : scale_sig32( pcm_in_fx[i], input_frame, shift ); // Q:Qx+shift
1075 0 : scale_sig32( hDirAC->hFbMixer->ppFilterbank_prior_input_fx[i], hDirAC->hFbMixer->fb_cfg->prior_input_length, shift ); // Q:Qx+shift
1076 : }
1077 0 : ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 );
1078 0 : FOR( i = 0; i < nchan_fb_in; i++ )
1079 : {
1080 0 : scale_sig32( pcm_in_fx[i], input_frame, negate( shift ) ); // Q:Qx
1081 0 : scale_sig32( hDirAC->hFbMixer->ppFilterbank_prior_input_fx[i], hDirAC->hFbMixer->fb_cfg->prior_input_length, negate( shift ) ); // Q:Qx
1082 : }
1083 0 : ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans );
1084 :
1085 0 : FOR( i = 0; i < nchan_fb_in; i++ )
1086 : {
1087 0 : pcm_in_fx[i] += l_ts;
1088 : }
1089 : }
1090 : ELSE
1091 : {
1092 3514800 : FOR( i = 0; i < nchan_fb_in; i++ )
1093 : {
1094 2876800 : Copy32( &pp_fr_real_fx[i][ts * l_ts], Cldfb_RealBuffer_fx[i], l_ts ); /* pp_fr_q */
1095 2876800 : Copy32( &pp_fr_imag_fx[i][ts * l_ts], Cldfb_ImagBuffer_fx[i], l_ts ); /* pp_fr_q */
1096 : }
1097 638000 : cldfb_q = pp_fr_q;
1098 638000 : move16();
1099 : }
1100 :
1101 638000 : Word16 ref_power_w = 1;
1102 638000 : move16();
1103 638000 : if ( hodirac_flag )
1104 : {
1105 64960 : ref_power_w = 0;
1106 64960 : move16();
1107 : }
1108 :
1109 1276000 : computeReferencePower_enc_fx_dirac(
1110 638000 : hDirAC->band_grouping,
1111 : Cldfb_RealBuffer_fx,
1112 : Cldfb_ImagBuffer_fx,
1113 638000 : sub( 31, cldfb_q ),
1114 638000 : reference_power_fx[ts],
1115 638000 : reference_power_exp[ts],
1116 638000 : hDirAC->hConfig->enc_param_start_band,
1117 : num_freq_bands,
1118 : ivas_format,
1119 : ref_power_w,
1120 : FOA_CHANNELS,
1121 : mono_frame_count,
1122 : dirac_mono_flag );
1123 :
1124 638000 : computeIntensityVector_enc_fx(
1125 : hDirAC,
1126 : Cldfb_RealBuffer_fx,
1127 : Cldfb_ImagBuffer_fx,
1128 638000 : hDirAC->hConfig->enc_param_start_band,
1129 : num_freq_bands,
1130 : intensity_real_fx,
1131 : cldfb_q,
1132 : intensity_real_q );
1133 638000 : IF( !hodirac_flag )
1134 : {
1135 573040 : computeDirectionVectors_fixed(
1136 : intensity_real_fx[0],
1137 : intensity_real_fx[1],
1138 : intensity_real_fx[2],
1139 573040 : hDirAC->hConfig->enc_param_start_band,
1140 : num_freq_bands,
1141 : direction_vector_fx[0],
1142 : direction_vector_fx[1],
1143 : direction_vector_fx[2],
1144 : 31, intensity_real_q );
1145 :
1146 573040 : direction_vector_q = Q30;
1147 573040 : move16();
1148 : }
1149 :
1150 : /* fill buffers of length "averaging_length" time slots for intensity and energy */
1151 638000 : hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 Q0*/
1152 638000 : move16();
1153 638000 : index = hDirAC->index_buffer_intensity; /* Q0 */
1154 638000 : move16();
1155 2552000 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
1156 : {
1157 : /* only real part needed */
1158 1914000 : Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); /* intensity_real_q */
1159 1914000 : Copy( intensity_real_q, &hDirAC->buffer_intensity_real_q[i][index - 1][0], num_freq_bands );
1160 : }
1161 638000 : Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); /* exp(reference_power_exp) */
1162 3017468 : FOR( i = 0; i < num_freq_bands; i++ )
1163 : {
1164 2379468 : hDirAC->buffer_energy_q[( index - 1 ) * num_freq_bands + i] = sub( 31, reference_power_exp[ts][i] );
1165 2379468 : move16();
1166 : }
1167 :
1168 638000 : Word16 buffer_intensity_real_single_q, min_shift = MAX_16;
1169 638000 : move16();
1170 638000 : buffer_intensity_real_single_q = hDirAC->buffer_intensity_real_q[0][0][0];
1171 638000 : move16();
1172 2552000 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
1173 : {
1174 17226000 : FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ )
1175 : {
1176 15312000 : min_shift = s_min( min_shift, L_norm_arr( hDirAC->buffer_intensity_real_fx[i][j], num_freq_bands ) );
1177 72419232 : FOR( k = 0; k < num_freq_bands; k++ )
1178 : {
1179 57107232 : buffer_intensity_real_single_q = s_min( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] );
1180 : }
1181 : }
1182 : }
1183 638000 : buffer_intensity_real_single_q = add( buffer_intensity_real_single_q, min_shift );
1184 2552000 : FOR( i = 0; i < DIRAC_NUM_DIMS; i++ )
1185 : {
1186 17226000 : FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ )
1187 : {
1188 72419232 : FOR( k = 0; k < num_freq_bands; k++ )
1189 : {
1190 57107232 : hDirAC->buffer_intensity_real_fx[i][j][k] = L_shl( hDirAC->buffer_intensity_real_fx[i][j][k], sub( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ) ); /* buffer_intensity_real_single_q */
1191 57107232 : move32();
1192 57107232 : hDirAC->buffer_intensity_real_q[i][j][k] = buffer_intensity_real_single_q;
1193 57107232 : move16();
1194 : }
1195 : }
1196 : }
1197 :
1198 : Word16 buffer_energy_single_q;
1199 : Word16 buffer_len;
1200 638000 : buffer_len = imult1616( DIRAC_MAX_NBANDS, hDirAC->no_col_avg_diff );
1201 638000 : minimum_fx( hDirAC->buffer_energy_q, buffer_len, &buffer_energy_single_q );
1202 61886000 : FOR( i = 0; i < buffer_len; i++ )
1203 : {
1204 61248000 : hDirAC->buffer_energy_fx[i] = L_shl( hDirAC->buffer_energy_fx[i], sub( buffer_energy_single_q, hDirAC->buffer_energy_q[i] ) ); /* buffer_energy_single_q */
1205 61248000 : move32();
1206 61248000 : hDirAC->buffer_energy_q[i] = buffer_energy_single_q;
1207 61248000 : move16();
1208 : }
1209 :
1210 : Word16 tmp_q_buffer_for_intensity[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF];
1211 : Word16 tmp_q_buffer_for_energy[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF];
1212 :
1213 638000 : set16_fx( tmp_q_buffer_for_intensity, buffer_intensity_real_single_q, buffer_len );
1214 638000 : set16_fx( tmp_q_buffer_for_energy, buffer_energy_single_q, buffer_len );
1215 :
1216 638000 : computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, tmp_q_buffer_for_intensity, tmp_q_buffer_for_energy, &diffuseness_vector_q );
1217 :
1218 638000 : IF( hodirac_flag )
1219 : {
1220 64960 : calculate_hodirac_sector_parameters_fx(
1221 : hDirAC,
1222 : Cldfb_RealBuffer_fx,
1223 : Cldfb_ImagBuffer_fx,
1224 : cldfb_q,
1225 : HODIRAC_BETA,
1226 64960 : hDirAC->band_grouping,
1227 64960 : hDirAC->hConfig->nbands,
1228 64960 : hDirAC->hConfig->enc_param_start_band,
1229 : azi_secs_fx,
1230 : ele_secs_fx,
1231 : diff_secs_fx,
1232 : diff_secs_exp,
1233 : ene_secs_fx,
1234 : ene_secs_exp );
1235 : }
1236 :
1237 638000 : IF( hodirac_flag )
1238 : {
1239 779520 : FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ )
1240 : {
1241 714560 : Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30
1242 714560 : hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx],
1243 714560 : Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp[ts][band_m_idx], 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); /* exp(hDirAC->diffuseness_m_exp) */
1244 714560 : move32();
1245 714560 : renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], reference_power_fx[ts][band_m_idx], reference_power_exp[ts][band_m_idx], &renormalization_factor_diff_exp[band_m_idx] ); /* exp(renormalization_factor_diff_exp) */
1246 714560 : move32();
1247 : }
1248 : }
1249 : ELSE
1250 : {
1251 2237948 : FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ )
1252 : {
1253 1664908 : Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30
1254 1664908 : norm_tmp_exp = add( reference_power_exp[ts][band_m_idx], 1 );
1255 1664908 : norm_tmp_fx = Mpy_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, tmp_diff ) );
1256 :
1257 1664908 : dir[0][band_m_idx] = W_mult_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] );
1258 1664908 : move64();
1259 1664908 : dir[1][band_m_idx] = W_mult_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] );
1260 1664908 : move64();
1261 1664908 : dir[2][band_m_idx] = W_mult_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] );
1262 1664908 : move64();
1263 1664908 : Word16 norm = 62;
1264 1664908 : move16();
1265 1664908 : IF( dir[0][band_m_idx] != 0 )
1266 : {
1267 1612972 : norm = W_norm( dir[0][band_m_idx] );
1268 : }
1269 1664908 : IF( dir[1][band_m_idx] != 0 )
1270 : {
1271 1611492 : norm = s_min( norm, W_norm( dir[1][band_m_idx] ) );
1272 : }
1273 1664908 : IF( dir[2][band_m_idx] != 0 )
1274 : {
1275 1509567 : norm = s_min( norm, W_norm( dir[2][band_m_idx] ) );
1276 : }
1277 1664908 : Word32 tmp = W_extract_h( W_shl( dir[0][band_m_idx], norm ) );
1278 1664908 : Word16 tmp_e = sub( Q31, add( sub( direction_vector_q, norm_tmp_exp ), sub( norm, 0 ) ) );
1279 1664908 : hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], direction_vector_exp_tmp[0][block_m_idx][band_m_idx], tmp, tmp_e, &direction_vector_exp_tmp[0][block_m_idx][band_m_idx] );
1280 1664908 : move32();
1281 1664908 : tmp = W_extract_h( W_shl( dir[1][band_m_idx], norm ) );
1282 1664908 : hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], direction_vector_exp_tmp[1][block_m_idx][band_m_idx], tmp, tmp_e, &direction_vector_exp_tmp[1][block_m_idx][band_m_idx] );
1283 1664908 : move32();
1284 1664908 : tmp = W_extract_h( W_shl( dir[2][band_m_idx], norm ) );
1285 1664908 : hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], direction_vector_exp_tmp[2][block_m_idx][band_m_idx], tmp, tmp_e, &direction_vector_exp_tmp[2][block_m_idx][band_m_idx] );
1286 1664908 : move32();
1287 1664908 : renormalization_factor_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_fx[band_m_idx], renormalization_factor_exp[band_m_idx], norm_tmp_fx, norm_tmp_exp, &renormalization_factor_exp[band_m_idx] ); /* exp(norm_tmp_exp + gbits) */
1288 1664908 : move32();
1289 1664908 : hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx],
1290 1664908 : Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp[ts][band_m_idx], 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); /* exp(hDirAC->diffuseness_m_exp) */
1291 1664908 : move32();
1292 3329816 : renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx],
1293 1664908 : reference_power_fx[ts][band_m_idx], reference_power_exp[ts][band_m_idx], &renormalization_factor_diff_exp[band_m_idx] ); /* exp(renormalization_factor_diff_exp) */
1294 1664908 : move32();
1295 : }
1296 : }
1297 : }
1298 :
1299 597341 : IF( !hodirac_flag )
1300 : {
1301 2115971 : FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ )
1302 : {
1303 1583590 : renormalization_factor_fx[band_m_idx] = EPSILON_FX;
1304 1583590 : move32();
1305 1583590 : renormalization_factor_exp[band_m_idx] = 0;
1306 1583590 : move16();
1307 1583590 : Word16 tmp_e = shl( direction_vector_exp_tmp[0][block_m_idx][band_m_idx], 1 );
1308 1583590 : renormalization_factor_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_fx[band_m_idx], renormalization_factor_exp[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ), tmp_e, &renormalization_factor_exp[band_m_idx] ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */
1309 1583590 : move32();
1310 1583590 : tmp_e = shl( direction_vector_exp_tmp[1][block_m_idx][band_m_idx], 1 );
1311 1583590 : renormalization_factor_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_fx[band_m_idx], renormalization_factor_exp[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ), tmp_e, &renormalization_factor_exp[band_m_idx] ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */
1312 1583590 : move32();
1313 1583590 : tmp_e = shl( direction_vector_exp_tmp[2][block_m_idx][band_m_idx], 1 );
1314 1583590 : renormalization_factor_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_fx[band_m_idx], renormalization_factor_exp[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ), tmp_e, &renormalization_factor_exp[band_m_idx] ); /* norm_tmp_exp + ( 31 - direction_vector_q ) + gbits */
1315 1583590 : move32();
1316 1583590 : IF( renormalization_factor_fx[band_m_idx] == 0 )
1317 : {
1318 50016 : renormalization_factor_fx[band_m_idx] = EPSILON_FX;
1319 50016 : move32();
1320 50016 : renormalization_factor_exp[band_m_idx] = 0;
1321 50016 : move16();
1322 : }
1323 1583590 : renormalization_factor_fx[band_m_idx] = Sqrt32( renormalization_factor_fx[band_m_idx], &renormalization_factor_exp[band_m_idx] );
1324 1583590 : move32();
1325 :
1326 1583590 : IF( GT_32( renormalization_factor_fx[band_m_idx], EPSILON_FX ) )
1327 : {
1328 : Word32 tmp32;
1329 :
1330 1583590 : tmp32 = hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx];
1331 1583590 : move32();
1332 1583590 : tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); /* exp(tmp_e + ( hDirAC->direction_vector_m_exp[block_m_idx] - renormalization_factor_exp)) */
1333 1583590 : tmp_e = add( tmp_e, sub( direction_vector_exp_tmp[0][block_m_idx][band_m_idx], renormalization_factor_exp[band_m_idx] ) );
1334 1583590 : hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_shr_sat( tmp32, sub( 1, tmp_e ) ); // Q30 saturation needs to check
1335 1583590 : move32();
1336 :
1337 1583590 : tmp32 = hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx]; // Q30
1338 1583590 : move32();
1339 1583590 : tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); /* exp(tmp_e + ( hDirAC->direction_vector_m_exp[block_m_idx] - renormalization_factor_exp)) */
1340 1583590 : tmp_e = add( tmp_e, sub( direction_vector_exp_tmp[1][block_m_idx][band_m_idx], renormalization_factor_exp[band_m_idx] ) );
1341 1583590 : hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_shr_sat( tmp32, sub( 1, tmp_e ) ); // Q30 saturation needs to check
1342 1583590 : move32();
1343 :
1344 1583590 : tmp32 = hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx]; // Q30
1345 1583590 : move32();
1346 1583590 : tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); /* exp(tmp_e + ( hDirAC->direction_vector_m_exp[block_m_idx] - renormalization_factor_exp)) */
1347 1583590 : tmp_e = add( tmp_e, sub( direction_vector_exp_tmp[2][block_m_idx][band_m_idx], renormalization_factor_exp[band_m_idx] ) );
1348 1583590 : hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_shr_sat( tmp32, sub( 1, tmp_e ) ); // Q30 saturation needs to check
1349 1583590 : move32();
1350 : }
1351 : ELSE
1352 : {
1353 0 : hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = ONE_IN_Q30;
1354 0 : move32();
1355 0 : hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = 0;
1356 0 : move32();
1357 0 : hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0;
1358 0 : move32();
1359 : }
1360 :
1361 : /* save the elevation and azimuth values to be used later by the ivas_dirac_QuantizeParameters function */
1362 6334360 : FOR( d = 0; d < DIRAC_NUM_DIMS; d++ )
1363 : {
1364 4750770 : dir_v_fx[d] = hDirAC->direction_vector_m_fx[d][block_m_idx][band_m_idx]; // Q30
1365 4750770 : move32();
1366 : }
1367 :
1368 1583590 : Scale_sig32( dir_v_fx, 3, -1 );
1369 1583590 : ivas_qmetadata_direction_vector_to_azimuth_elevation_fx(
1370 : dir_v_fx,
1371 : Q29,
1372 1583590 : &q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx],
1373 1583590 : &q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] );
1374 : }
1375 532381 : hDirAC->direction_vector_m_exp[block_m_idx] = 1;
1376 532381 : move16();
1377 : }
1378 :
1379 : /* Sectors */
1380 597341 : IF( hodirac_flag )
1381 : {
1382 : Word32 L_tmp, L_tmp1;
1383 : Word16 e_tmp, e_tmp1, exp_diff;
1384 779520 : FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ )
1385 : {
1386 714560 : q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[band_m_idx], 1 ); // Q23 -> Q22
1387 714560 : move32();
1388 714560 : q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[band_m_idx], 1 ); // Q23 -> Q22
1389 714560 : move32();
1390 :
1391 714560 : q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22
1392 714560 : move32();
1393 714560 : q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22
1394 714560 : move32();
1395 :
1396 714560 : L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[band_m_idx] ), diff_secs_exp[band_m_idx], &e_tmp ); /* exp(e_tmp) */
1397 714560 : L_tmp1 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[num_freq_bands + band_m_idx] ), diff_secs_exp[num_freq_bands + band_m_idx], &e_tmp1 ); /* exp(e_tmp1) */
1398 714560 : L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp, e_tmp, L_tmp1, e_tmp1, &e_tmp1 ); /* exp(e_tmp1) */
1399 714560 : IF( L_tmp1 == 0 )
1400 : {
1401 4000 : q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx] = L_shl( div_l( L_tmp, EPSILON_FX ), Q30 - Q15 ); // Q30
1402 4000 : move32();
1403 : }
1404 : ELSE
1405 : {
1406 710560 : L_tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( L_tmp, L_add( L_tmp1, EPSILON_FX ), &exp_diff ) ); /* exp(exp_diff) */
1407 710560 : exp_diff = add( exp_diff, sub( e_tmp, e_tmp1 ) );
1408 710560 : q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx] = L_shl( L_tmp, sub( exp_diff, Q1 ) ); // Q30
1409 710560 : move32();
1410 : }
1411 : }
1412 : }
1413 : }
1414 :
1415 : /* Diffuseness */
1416 754367 : FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ )
1417 : {
1418 594867 : IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) )
1419 : {
1420 : Word16 tmp_e;
1421 582738 : hDirAC->diffuseness_m_fx[band_m_idx] = L_deposit_h( BASOP_Util_Divide3232_Scale( hDirAC->diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &tmp_e ) ); /* exp(tmp_e) */
1422 582738 : move32();
1423 582738 : tmp_e = add( tmp_e, sub( hDirAC->diffuseness_m_exp[band_m_idx], renormalization_factor_diff_exp[band_m_idx] ) );
1424 582738 : hDirAC->diffuseness_m_fx[band_m_idx] = L_shr( hDirAC->diffuseness_m_fx[band_m_idx], sub( 1, tmp_e ) ); // to Q30
1425 582738 : move32();
1426 : }
1427 : ELSE
1428 : {
1429 12129 : hDirAC->diffuseness_m_fx[band_m_idx] = 0;
1430 12129 : move32();
1431 : }
1432 594867 : hDirAC->diffuseness_m_exp[band_m_idx] = 1;
1433 594867 : move16();
1434 :
1435 : /* set coherence to zero and convert diffuseness to energy ratio*/
1436 :
1437 594867 : set32_fx( q_direction->band_data[band_m_idx].energy_ratio_fx, L_sub( ONE_IN_Q30, hDirAC->diffuseness_m_fx[band_m_idx] ), q_direction->cfg.nblocks );
1438 :
1439 2893017 : FOR( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ )
1440 : {
1441 2298150 : IF( q_direction->coherence_band_data != NULL )
1442 : {
1443 0 : q_direction->coherence_band_data[band_m_idx].spread_coherence[block_m_idx] = 0;
1444 0 : move16();
1445 : }
1446 : }
1447 : }
1448 :
1449 159500 : pop_wmops();
1450 159500 : return;
1451 : }
1452 :
1453 :
1454 : /*-------------------------------------------------------------------------
1455 : * computeIntensityVector_enc()
1456 : *
1457 : *
1458 : *------------------------------------------------------------------------*/
1459 638000 : static void computeIntensityVector_enc_fx(
1460 : const DIRAC_ENC_HANDLE hDirAC,
1461 : Word32 Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* q_cldfb */
1462 : Word32 Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* q_cldfb */
1463 : const Word16 enc_param_start_band, /* i : first band to process Q0*/
1464 : const Word16 num_frequency_bands, /* Q0 */
1465 : Word32 intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS] /* q_intensity_real */
1466 : ,
1467 : Word16 q_cldfb,
1468 : Word16 q_intensity_real[DIRAC_MAX_NBANDS] )
1469 : {
1470 : /* Reminder
1471 : * X = a + ib; Y = c + id
1472 : * X*Y = ac - bd + i(ad +bc)
1473 : */
1474 : Word16 i, j;
1475 : Word32 real, img;
1476 : Word16 brange[2];
1477 638000 : Word16 shift_value = sub( shl( q_cldfb, 1 ), 31 );
1478 3017468 : FOR( i = 0; i < num_frequency_bands; i++ )
1479 : {
1480 2379468 : brange[0] = hDirAC->band_grouping[i + enc_param_start_band]; /* Q0 */
1481 2379468 : move16();
1482 2379468 : brange[1] = hDirAC->band_grouping[i + enc_param_start_band + 1]; /* Q0 */
1483 2379468 : move16();
1484 2379468 : Word16 num_bins = sub( brange[1], brange[0] );
1485 2379468 : Word16 gb = find_guarded_bits_fx( num_bins );
1486 : Word16 norm;
1487 2379468 : intensity_real[0][i] = 0;
1488 2379468 : move32();
1489 2379468 : intensity_real[1][i] = 0;
1490 2379468 : move32();
1491 2379468 : intensity_real[2][i] = 0;
1492 2379468 : move32();
1493 :
1494 2379468 : Word64 tmp_1 = 0, tmp_2 = 0, tmp_3 = 0;
1495 2379468 : move64();
1496 2379468 : move64();
1497 2379468 : move64();
1498 :
1499 88681228 : FOR( j = brange[0]; j < brange[1]; j++ )
1500 : {
1501 86301760 : real = Cldfb_RealBuffer[0][j];
1502 86301760 : move32();
1503 86301760 : img = Cldfb_ImagBuffer[0][j];
1504 86301760 : move32();
1505 : Word64 t1, t2, t3;
1506 86301760 : t1 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[3][j], real ), Cldfb_ImagBuffer[3][j], img ); /* 2 * q_cldfb + 1 */
1507 86301760 : t2 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[1][j], real ), Cldfb_ImagBuffer[1][j], img ); /* 2 * q_cldfb + 1 */
1508 86301760 : t3 = W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[2][j], real ), Cldfb_ImagBuffer[2][j], img ); /* 2 * q_cldfb + 1 */
1509 86301760 : t1 = W_shr( t1, gb );
1510 86301760 : t2 = W_shr( t2, gb );
1511 86301760 : t3 = W_shr( t3, gb );
1512 : /* Intensity is XYZ order, audio is WYZX order. */
1513 86301760 : tmp_1 = W_add( tmp_1, t1 ); /* 2 * q_cldfb + 1 */
1514 86301760 : tmp_2 = W_add( tmp_2, t2 ); /* 2 * q_cldfb + 1 */
1515 86301760 : tmp_3 = W_add( tmp_3, t3 ); /* 2 * q_cldfb + 1 */
1516 : }
1517 2379468 : norm = 63;
1518 2379468 : move16();
1519 2379468 : IF( tmp_1 != 0 )
1520 : {
1521 2322086 : norm = s_min( norm, W_norm( tmp_1 ) );
1522 : }
1523 2379468 : IF( tmp_2 != 0 )
1524 : {
1525 2322109 : norm = s_min( norm, W_norm( tmp_2 ) );
1526 : }
1527 2379468 : IF( tmp_3 != 0 )
1528 : {
1529 2124701 : norm = s_min( norm, W_norm( tmp_3 ) );
1530 : }
1531 2379468 : intensity_real[0][i] = W_extract_h( W_shl( tmp_1, norm ) ); // shift_value - (gb - norm)
1532 2379468 : move32();
1533 2379468 : intensity_real[1][i] = W_extract_h( W_shl( tmp_2, norm ) ); // shift_value - (gb - norm)
1534 2379468 : move32();
1535 2379468 : intensity_real[2][i] = W_extract_h( W_shl( tmp_3, norm ) ); // shift_value - (gb - norm)
1536 2379468 : q_intensity_real[i] = sub( shift_value, sub( gb, norm ) );
1537 2379468 : move16();
1538 : }
1539 :
1540 638000 : return;
1541 : }
1542 :
1543 : /*-------------------------------------------------------------------------
1544 : * computeDiffuseness_mdft()
1545 : *
1546 : *
1547 : *------------------------------------------------------------------------*/
1548 684720 : void computeDiffuseness_mdft_fx(
1549 : Word32 **buffer_intensity[DIRAC_NUM_DIMS], /* q_factor_intensity */
1550 : const Word32 *buffer_energy, /* q_factor_energy */
1551 : const Word16 num_freq_bands, /* Q0 */
1552 : const UWord16 no_col_avg_diff, /* Q0 */
1553 : Word32 *diffuseness, /* q_diffuseness */
1554 : Word16 *q_factor_intensity,
1555 : Word16 *q_factor_energy,
1556 : Word16 *q_diffuseness /*Ouput Q*/
1557 : )
1558 : {
1559 : Word32 intensity_slow[DIRAC_NUM_DIMS * MASA_FREQUENCY_BANDS];
1560 : Word16 intensity_slow_e[DIRAC_NUM_DIMS * MASA_FREQUENCY_BANDS];
1561 : Word32 intensity_slow_abs[MASA_FREQUENCY_BANDS];
1562 : Word16 intensity_slow_abs_e[MASA_FREQUENCY_BANDS];
1563 : Word32 energy_slow[MASA_FREQUENCY_BANDS];
1564 : Word16 energy_slow_e[MASA_FREQUENCY_BANDS];
1565 : Word16 i, j, k;
1566 : Word32 tmp;
1567 : Word32 *p_tmp;
1568 : const Word32 *p_tmp_c;
1569 : Word16 *p_tmp_e, tmp_q;
1570 :
1571 : /* Compute Intensity slow and energy slow buffer_intensity and buffer_energy */
1572 :
1573 684720 : set_zero_fx( intensity_slow, i_mult( DIRAC_NUM_DIMS, MASA_FREQUENCY_BANDS ) );
1574 684720 : set16_fx( intensity_slow_e, 0, i_mult( DIRAC_NUM_DIMS, MASA_FREQUENCY_BANDS ) );
1575 684720 : set_zero_fx( intensity_slow_abs, MASA_FREQUENCY_BANDS );
1576 684720 : set16_fx( intensity_slow_abs_e, 0, no_col_avg_diff );
1577 684720 : set_zero_fx( energy_slow, MASA_FREQUENCY_BANDS );
1578 684720 : set16_fx( energy_slow_e, 0, no_col_avg_diff );
1579 :
1580 6162480 : FOR( i = 0; i < no_col_avg_diff; ++i )
1581 : {
1582 : /* Energy slow */
1583 5477760 : p_tmp_c = buffer_energy + i_mult( i, num_freq_bands );
1584 5477760 : tmp_q = q_factor_energy[i];
1585 5477760 : move16();
1586 :
1587 26382304 : FOR( k = 0; k < num_freq_bands; k++ )
1588 : {
1589 20904544 : energy_slow[k] = BASOP_Util_Add_Mant32Exp( energy_slow[k], energy_slow_e[k], p_tmp_c[k], sub( 31, tmp_q ), &energy_slow_e[k] ); /* exp(energy_slow_e)*/
1590 20904544 : move32();
1591 : }
1592 :
1593 : /* Intensity slow */
1594 21911040 : FOR( j = 0; j < DIRAC_NUM_DIMS; ++j )
1595 : {
1596 16433280 : p_tmp = buffer_intensity[j][i];
1597 79146912 : FOR( k = 0; k < num_freq_bands; k++ )
1598 : {
1599 62713632 : intensity_slow[j * num_freq_bands + k] = BASOP_Util_Add_Mant32Exp( intensity_slow[j * num_freq_bands + k], intensity_slow_e[j * num_freq_bands + k], p_tmp[k], sub( 31, q_factor_intensity[i] ), &intensity_slow_e[j * num_freq_bands + k] ); /* exp(intensity_slow_e) */
1600 62713632 : move32();
1601 : }
1602 : }
1603 : }
1604 :
1605 : /* intensity_slow.^2 + intensity_slow_abs*/
1606 2738880 : FOR( j = 0; j < DIRAC_NUM_DIMS; ++j )
1607 : {
1608 2054160 : p_tmp = intensity_slow + i_mult( j, num_freq_bands );
1609 2054160 : p_tmp_e = intensity_slow_e + i_mult( j, num_freq_bands );
1610 :
1611 9893364 : FOR( k = 0; k < num_freq_bands; k++ )
1612 : {
1613 7839204 : p_tmp[k] = Mpy_32_32( p_tmp[k], p_tmp[k] ); /* 2 * (31-p_tmp_e) - 31 */
1614 7839204 : move32();
1615 7839204 : tmp_q = sub( shl( sub( 31, p_tmp_e[k] ), 1 ), 31 );
1616 7839204 : intensity_slow_abs[k] = BASOP_Util_Add_Mant32Exp( intensity_slow_abs[k], intensity_slow_abs_e[k], p_tmp[k], sub( 31, tmp_q ), &intensity_slow_abs_e[k] ); /* exp(intensity_slow_abs_e) */
1617 7839204 : move32();
1618 : }
1619 : }
1620 :
1621 : /* Compute Diffuseness */
1622 684720 : p_tmp = intensity_slow_abs;
1623 684720 : tmp_q = 0;
1624 684720 : move16();
1625 3297788 : FOR( i = 0; i < num_freq_bands; ++i )
1626 : {
1627 2613068 : tmp = Sqrt32( p_tmp[i], &intensity_slow_abs_e[i] );
1628 :
1629 2613068 : tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp, L_add( energy_slow[i], EPSILLON_FX ), &tmp_q ) ); /* exp(tmp_q) */
1630 2613068 : tmp_q = add( tmp_q, sub( intensity_slow_abs_e[i], energy_slow_e[i] ) );
1631 2613068 : tmp = L_shl_sat( tmp, tmp_q );
1632 2613068 : tmp = L_sub( ONE_IN_Q31, tmp );
1633 2613068 : diffuseness[i] = tmp;
1634 2613068 : move32();
1635 :
1636 2613068 : IF( LT_32( tmp, ONE_IN_Q31 ) )
1637 : {
1638 2557670 : IF( tmp < 0 )
1639 : {
1640 0 : diffuseness[i] = 0;
1641 0 : move32();
1642 : }
1643 : }
1644 : ELSE
1645 : {
1646 55398 : diffuseness[i] = ONE_IN_Q31;
1647 55398 : move32();
1648 : }
1649 : }
1650 684720 : *q_diffuseness = Q31;
1651 684720 : move16();
1652 :
1653 684720 : return;
1654 : }
|