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 "options.h"
35 : #include <stdint.h>
36 : #include "cnst.h"
37 : #include "rom_enc.h"
38 : #include "rom_com.h"
39 : #include "prot_fx.h"
40 : #include "ivas_prot_rend_fx.h"
41 : #include "ivas_cnst.h"
42 : #include "ivas_rom_com.h"
43 : #include "ivas_rom_dec.h"
44 : #include "math.h"
45 : #include "wmc_auto.h"
46 : #include "rom_dec.h"
47 : #include "ivas_prot_fx.h"
48 :
49 : #define INV_EPSILON_MANT 214748365
50 :
51 : /*-----------------------------------------------------------------------*
52 : * Local constants
53 : *-----------------------------------------------------------------------*/
54 :
55 : #define PARAM_MC_LOCAL_SZ_LFE_MAP 5
56 :
57 : /*-----------------------------------------------------------------------*
58 : * Local typedefs
59 : *-----------------------------------------------------------------------*/
60 :
61 : typedef struct parameter_band_mapping_struct
62 : {
63 : Word16 n_source_bands[20];
64 : Word16 source_band_idx[20][4];
65 : Word16 source_band_factor_fx[20][4]; /*Q15*/
66 :
67 : } PARAM_MC_PARAMETER_BAND_MAPPING;
68 :
69 : /*-----------------------------------------------------------------------*
70 : * Local function prototypes
71 : *-----------------------------------------------------------------------*/
72 :
73 : static void ivas_param_mc_dec_init_fx( PARAM_MC_DEC_HANDLE hParamMC, const Word16 nchan_in, const Word16 nchan_out );
74 :
75 : static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 nY, const Word16 slot_idx );
76 : static Word16 ivas_param_mc_range_decoder_LC_fx( UWord16 *bit_buffer, Word16 *x, Word16 *BER_detect, const Word16 sz_seq, const Word16 sz_alphabet, const UWord16 *cft, const UWord16 *sft, const Word16 tot_shift, const Word16 nbbits );
77 :
78 :
79 : static void ivas_param_mc_get_mixing_matrices_fx(
80 : PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
81 : IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
82 : Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands */
83 : Word16 Cx_in_e,
84 : const Word16 param_band_idx,
85 : Word32 *mixing_matrix_fx[],
86 : Word16 *mixing_matrix_e,
87 : Word32 *mixing_matrix_res_fx[],
88 : Word16 *mixing_matrix_res_e,
89 : const Word16 nY_intern, /* i : number of channels in the transported format */
90 : const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */
91 : const Word16 nX, /* i : number of transport channels */
92 : const Word16 nY_cov /* i : number of covariance synthesis output channels */
93 : );
94 :
95 : static Word16 ivas_param_mc_uniform_decoder_fx( Word16 *seq, const Word16 sz_seq, const Word16 *alphabet, const Word16 N, UWord16 bit_buffer[PARAM_MC_MAX_BITS] );
96 : static void ivas_param_mc_dec_compute_interpolator_fx( const UWord16 bAttackPresent, const UWord16 attackPos, const UWord16 interp_length, Word16 *interpolator );
97 :
98 : static void param_mc_set_num_synth_bands( const Word32 output_Fs, PARAM_MC_DEC_HANDLE hParamMC );
99 :
100 : static void ivas_param_mc_get_param_band_mapping( const Word16 n_target_bands, const Word16 *target_band_grouping, const Word16 n_source_bands, const Word16 *source_band_grouping, PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping );
101 :
102 :
103 : static void ivas_param_mc_bs_decode_parameter_values_fx( UWord16 bit_buffer[], Word16 *bit_pos, const Word16 max_bits, Word16 *BER_detect, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, const Word16 map_size_wo_lfe, const Word16 map_size, const Word16 num_lfe_bands, const Word16 band_step, const Word16 num_param_bands, Word16 *value_buffer );
104 : static void ivas_param_mc_dequantize_cov_fx( PARAM_MC_DEC_HANDLE hParamMC, Word16 *ild_q_fx, Word16 *icc_q_fx, const Word16 param_band_index, const Word16 nY_cov, const PARAM_MC_SYNTHESIS_CONF synth_conf, const Word16 nY_int, const Word16 nX, Word32 *Cx_state_fx, Word16 Cx_state_e, Word32 *Cproto_fx, Word16 Cproto_e, Word32 *Cy_state_fx, Word16 *Cy_state_e );
105 : static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, const UWord16 nchan_transport, const UWord16 nchan_out_cov, PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, Word16 Q_proto_mtx );
106 : static void param_mc_update_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, Word32 *mixing_matrix[], Word16 *mixing_matrix_fx, Word32 *mixing_matrix_res[], Word16 *mixing_matrix_res_exp, const UWord16 nX, const UWord16 nY );
107 :
108 :
109 : static void param_mc_protoSignalComputation_fx( Word32 *RealBuffer_fx, Word32 *ImagBuffer_fx, Word32 *proto_frame_f_fx, const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, const Word16 num_freq_bands, const Word16 Cldfb_Real_Imag_exp, Word16 *proto_frame_f_fx_q /* Word16 ImagBuffer_fx_e, Word16 *common_e*/ );
110 :
111 : /*-------------------------------------------------------------------------
112 : * ivas_param_mc_dec_open()
113 : *
114 : * Open Parametric MC decoder handle
115 : *-------------------------------------------------------------------------*/
116 :
117 279 : ivas_error ivas_param_mc_dec_open_fx(
118 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
119 : )
120 : {
121 : Word16 k, nchan_transport;
122 : PARAM_MC_DEC_HANDLE hParamMC;
123 : Word16 nchan_out_transport;
124 : Word16 nchan_out_cov;
125 : Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
126 : Word32 proto_mtx_norm_fx, tmp32;
127 : Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
128 : Word16 max_param_band_residual;
129 : UWord16 config_index;
130 : MC_LS_SETUP mc_ls_setup;
131 : AUDIO_CONFIG output_config;
132 : Word32 output_Fs, ivas_total_brate;
133 : ivas_error error;
134 :
135 279 : error = IVAS_ERR_OK;
136 279 : move32();
137 :
138 : /*-----------------------------------------------------------------*
139 : * prepare library opening
140 : *-----------------------------------------------------------------*/
141 :
142 279 : IF( ( hParamMC = (PARAM_MC_DEC_HANDLE) malloc( sizeof( PARAM_MC_DEC_DATA ) ) ) == NULL )
143 : {
144 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
145 : }
146 :
147 279 : IF( ( hParamMC->hMetadataPMC = (HANDLE_IVAS_PARAM_MC_METADATA) malloc( sizeof( IVAS_PARAM_MC_METADATA ) ) ) == NULL )
148 : {
149 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC metadata \n" ) );
150 : }
151 :
152 279 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
153 279 : move32();
154 279 : output_config = st_ivas->hDecoderConfig->output_config;
155 279 : move32();
156 279 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
157 279 : move32();
158 279 : mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
159 279 : nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
160 279 : hParamMC->hoa_encoder_fx = NULL;
161 :
162 : /* determine the synthesis config */
163 279 : test();
164 279 : test();
165 279 : test();
166 279 : test();
167 279 : test();
168 279 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( st_ivas->transport_config, output_config ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
169 : {
170 222 : hParamMC->synthesis_conf = PARAM_MC_SYNTH_DIRECT;
171 222 : move32();
172 : }
173 57 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
174 : {
175 2 : hParamMC->synthesis_conf = PARAM_MC_SYNTH_MONO_STEREO;
176 2 : move32();
177 : }
178 55 : ELSE IF( NE_32( st_ivas->transport_config, output_config ) )
179 : {
180 55 : test();
181 55 : test();
182 55 : IF( ( NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, audioCfg2channels( output_config ) ) ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, st_ivas->hOutSetup.nchan_out_woLFE ) ) )
183 : {
184 1 : hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_COV;
185 1 : move32();
186 : /* need to reset the intern config */
187 1 : st_ivas->intern_config = output_config;
188 1 : move32();
189 1 : ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
190 1 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
191 : {
192 0 : st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk;
193 0 : move32();
194 0 : st_ivas->hIntSetup.ls_azimuth_fx = st_ivas->hLsSetupCustom->ls_azimuth_fx; // Q22
195 0 : st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; // Q22
196 : }
197 : }
198 : ELSE
199 : {
200 54 : hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_CLDFB;
201 54 : move32();
202 : }
203 : }
204 :
205 279 : hParamMC->ls_conv_dmx_matrix_fx = NULL;
206 :
207 279 : test();
208 279 : IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
209 : {
210 3 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
211 : }
212 : ELSE
213 : {
214 276 : nchan_out_cov = nchan_out_transport;
215 276 : move16();
216 : }
217 :
218 279 : st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
219 279 : move16();
220 279 : config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
221 279 : nchan_transport = st_ivas->nchan_transport;
222 279 : move16();
223 :
224 279 : SWITCH( nchan_transport )
225 : {
226 17 : case 4:
227 : case 3:
228 17 : st_ivas->nCPE = 2;
229 17 : move16();
230 17 : st_ivas->nSCE = 0;
231 17 : move16();
232 17 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
233 17 : move16();
234 17 : BREAK;
235 262 : case 2:
236 262 : st_ivas->nCPE = 1;
237 262 : move16();
238 262 : st_ivas->nSCE = 0;
239 262 : move16();
240 262 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
241 262 : move16();
242 :
243 262 : BREAK;
244 : }
245 :
246 : /*-----------------------------------------------------------------*
247 : * set input parameters
248 : *-----------------------------------------------------------------*/
249 :
250 : // hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX;
251 279 : hParamMC->slot_size = shr( extract_l( Mpy_32_32_r( output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), 4 );
252 279 : move16();
253 279 : set16_fx( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
254 279 : set16_fx( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS );
255 279 : hParamMC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS;
256 279 : move16();
257 :
258 : // hParamMC->num_freq_bands = (int16_t)(output_Fs * INV_CLDFB_BANDWIDTH + 0.5f);
259 279 : hParamMC->num_freq_bands = extract_l( Mpy_32_32_r( output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) );
260 279 : move16();
261 279 : hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands;
262 279 : move16();
263 279 : ivas_param_mc_metadata_open_fx( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC );
264 :
265 : /* init arrays for quantized parameters */
266 :
267 279 : IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
268 : {
269 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
270 : }
271 279 : IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
272 : {
273 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
274 : }
275 279 : set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); // Q8
276 279 : set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) ); // Q15
277 :
278 279 : param_mc_set_num_synth_bands( output_Fs, hParamMC );
279 :
280 : /* Band Grouping */
281 279 : IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) )
282 : {
283 3 : Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 );
284 : }
285 276 : ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) )
286 : {
287 135 : Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 );
288 : }
289 141 : ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) )
290 : {
291 141 : Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 );
292 : }
293 : ELSE
294 : {
295 0 : assert( 0 && "nbands must be 20, 14, or 10!" );
296 : }
297 :
298 : /* set max parameter band for abs cov */
299 279 : k = 0;
300 279 : move16();
301 2514 : WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) )
302 : {
303 2235 : hParamMC->max_param_band_abs_cov = k;
304 2235 : move16();
305 2235 : k = add( k, 1 );
306 : }
307 :
308 : /*-----------------------------------------------------------------*
309 : * open sub-modules
310 : *-----------------------------------------------------------------*/
311 :
312 : /* prototype signal computation */
313 :
314 279 : test();
315 279 : test();
316 279 : IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
317 : {
318 57 : IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
319 : {
320 0 : return error;
321 : }
322 :
323 : /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */
324 57 : test();
325 57 : IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
326 : {
327 3 : IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL )
328 : {
329 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
330 : }
331 :
332 35 : FOR( k = 0; k < nchan_out_transport; k++ )
333 : {
334 32 : Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); /*Q30*/
335 : }
336 :
337 : /* convert ParamMC parameter bands to SFB */
338 3 : IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
339 : {
340 2 : st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth;
341 2 : move16();
342 30 : FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ )
343 : {
344 28 : st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] );
345 28 : move16();
346 : }
347 : }
348 : ELSE
349 : {
350 : /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */
351 1 : ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
352 : }
353 : }
354 : }
355 279 : IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL )
356 : {
357 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
358 : }
359 279 : Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, imult1616( nchan_transport, nchan_out_transport ) ); /*Q31*/
360 :
361 279 : hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport );
362 279 : move16();
363 :
364 279 : test();
365 279 : IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
366 : {
367 3 : Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); /*Q.26*/
368 3 : matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx ); /*Q.26*/
369 3 : Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); /*Q.26*/
370 3 : IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
371 : {
372 2 : tmp32 = ONE_IN_Q26; /*Q26*/
373 2 : move32();
374 14 : FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ )
375 : {
376 12 : tmp32 = L_max( L_abs( tmp32 ), L_abs( proto_matrix_fx[k] ) ); /*Q.26*/
377 : }
378 2 : proto_mtx_norm_fx = divide3232( ONE_IN_Q26, tmp32 ); /*Q15*/
379 :
380 : /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */
381 8 : FOR( k = 0; k < nchan_transport; k++ )
382 : {
383 18 : FOR( Word16 i = 0; i < nchan_out_cov; i++ )
384 : {
385 12 : IF( EQ_32( proto_matrix_fx[k * nchan_out_cov + i], tmp32 ) )
386 : {
387 4 : st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = ONE_IN_Q30; // Q30
388 : }
389 : ELSE
390 : {
391 8 : st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[k * nchan_out_cov + i], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/
392 : }
393 12 : move32();
394 : }
395 : }
396 : }
397 : }
398 : ELSE
399 : {
400 276 : Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); /*Q.31*/
401 276 : Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); /*Scaling down to 26*/
402 : }
403 :
404 279 : IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
405 : {
406 2 : hParamMC->num_outputs_diff = 0;
407 2 : move16();
408 2 : hParamMC->diff_proto_info = NULL;
409 2 : hParamMC->h_output_synthesis_params.use_onset_filters = 0;
410 2 : move16();
411 2 : hParamMC->max_band_decorr = 0;
412 2 : move16();
413 2 : hParamMC->h_freq_domain_decorr_ap_params = NULL;
414 2 : hParamMC->h_freq_domain_decorr_ap_state = NULL;
415 : }
416 : ELSE
417 : {
418 277 : hParamMC->num_outputs_diff = nchan_out_cov;
419 277 : move16();
420 277 : IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL )
421 : {
422 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
423 : }
424 :
425 277 : IF( NE_32( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ), IVAS_ERR_OK ) )
426 : {
427 0 : return error;
428 : }
429 :
430 : /* decorrelation */
431 277 : hParamMC->h_freq_domain_decorr_ap_params = NULL;
432 277 : hParamMC->h_freq_domain_decorr_ap_state = NULL;
433 :
434 277 : ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0
435 :
436 277 : IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff,
437 : hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ),
438 : IVAS_ERR_OK ) )
439 : {
440 0 : return error;
441 : }
442 :
443 277 : hParamMC->h_output_synthesis_params.use_onset_filters = 0;
444 277 : move16();
445 277 : hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr;
446 277 : move16();
447 : }
448 279 : hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded];
449 279 : move16();
450 279 : max_param_band_residual = 0;
451 279 : move16();
452 :
453 1006 : FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
454 : {
455 1006 : IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
456 : {
457 279 : max_param_band_residual = k;
458 279 : move16();
459 279 : assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr );
460 279 : break;
461 : }
462 : }
463 :
464 : /* output synthesis */
465 279 : IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ), IVAS_ERR_OK ) )
466 : {
467 0 : return error;
468 : }
469 :
470 279 : ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx );
471 :
472 : /* Head or external rotation */
473 279 : test();
474 279 : test();
475 279 : test();
476 279 : IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
477 : {
478 13 : IF( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL )
479 : {
480 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
481 : }
482 13 : compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hParamMC->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER );
483 : }
484 :
485 : /*-----------------------------------------------------------------*
486 : * memory allocation
487 : *-----------------------------------------------------------------*/
488 :
489 279 : IF( hParamMC->max_band_decorr > 0 )
490 : {
491 277 : IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
492 : {
493 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
494 : }
495 277 : IF( ( hParamMC->proto_frame_dec_f_fx = (Word32 *) malloc( 2 * nchan_out_cov * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
496 : {
497 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
498 : }
499 : }
500 : ELSE
501 : {
502 2 : hParamMC->proto_frame_f_fx = NULL;
503 2 : hParamMC->proto_frame_dec_f_fx = NULL;
504 : }
505 :
506 279 : ivas_param_mc_dec_init_fx( hParamMC, nchan_transport, nchan_out_cov );
507 :
508 279 : IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
509 : {
510 : Word16 n_cldfb_slots;
511 :
512 277 : n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS;
513 277 : move16();
514 277 : IF( st_ivas->hDecoderConfig->Opt_tsm )
515 : {
516 4 : n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS;
517 4 : move16();
518 : }
519 :
520 277 : Word16 cldfb_buf_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
521 277 : IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL )
522 : {
523 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
524 : }
525 277 : set32_fx( hParamMC->Cldfb_RealBuffer_tc_fx, 0, cldfb_buf_size );
526 277 : hParamMC->Cldfb_RealBuffer_tc_e = 25; // Q6 , Initialised with Q6 to match non jbm and jbm cases
527 277 : move16();
528 277 : IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL )
529 : {
530 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
531 : }
532 277 : set32_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, 0, cldfb_buf_size );
533 277 : hParamMC->Cldfb_ImagBuffer_tc_e = 25; // Q6 , Initialised with Q6 to match non jbm and jbm cases
534 277 : move16();
535 277 : hParamMC->sz = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
536 277 : move16();
537 :
538 277 : IF( st_ivas->hTcBuffer == NULL )
539 : {
540 10 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
541 : {
542 0 : return error;
543 : }
544 : }
545 : }
546 : ELSE
547 : {
548 2 : hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
549 2 : hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
550 : }
551 :
552 279 : hParamMC->subframes_rendered = 0;
553 279 : move16();
554 279 : hParamMC->slots_rendered = 0;
555 279 : move16();
556 :
557 279 : st_ivas->hParamMC = hParamMC;
558 279 : return error;
559 : }
560 :
561 :
562 : /*-------------------------------------------------------------------------
563 : * ivas_param_mc_get_param_band_mapping()
564 : *
565 : *
566 : *-------------------------------------------------------------------------*/
567 :
568 65 : static void ivas_param_mc_get_param_band_mapping(
569 : const Word16 n_target_bands,
570 : const Word16 *target_band_grouping,
571 : const Word16 n_source_bands,
572 : const Word16 *source_band_grouping,
573 : PARAM_MC_PARAMETER_BAND_MAPPING *parameter_band_mapping )
574 : {
575 : Word16 target_band_idx;
576 65 : Word16 source_band_idx = 0;
577 65 : move16();
578 : Word16 source_band_cnt_total;
579 :
580 851 : FOR( target_band_idx = 0; target_band_idx < n_target_bands; target_band_idx++ )
581 : {
582 786 : Word16 upper = target_band_grouping[target_band_idx + 1];
583 786 : Word16 lower = target_band_grouping[target_band_idx];
584 786 : Word16 source_band_in_target_band_cnt = 0;
585 786 : Word16 norm_fac_fx = 32767; // 1.Q15
586 786 : source_band_cnt_total = 0;
587 786 : move16();
588 786 : move16();
589 786 : move16();
590 :
591 4512 : FOR( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ )
592 : {
593 : /* find lowest corresponding source band*/
594 4512 : test();
595 4512 : IF( LE_16( source_band_grouping[source_band_idx], lower ) && GE_16( source_band_grouping[source_band_idx + 1], lower ) )
596 : {
597 : DO
598 : {
599 2006 : Word16 source_bands_in_target_band = sub( s_min( source_band_grouping[source_band_idx + 1], upper ), s_max( source_band_grouping[source_band_idx], lower ) );
600 2006 : IF( source_bands_in_target_band )
601 : {
602 1048 : source_band_cnt_total = add( source_band_cnt_total, source_bands_in_target_band );
603 1048 : parameter_band_mapping->source_band_idx[target_band_idx][source_band_in_target_band_cnt] = source_band_idx;
604 1048 : parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_in_target_band_cnt++] = shl( source_bands_in_target_band, 10 ); /*Q10*/
605 1048 : move16();
606 1048 : move16();
607 : }
608 2006 : source_band_idx++;
609 : }
610 2006 : WHILE( LE_16( source_band_grouping[source_band_idx], upper ) && LT_16( source_band_idx, n_source_bands ) );
611 786 : BREAK;
612 : }
613 : }
614 786 : norm_fac_fx = div_s( 1, source_band_cnt_total ); /*Q15*/
615 1834 : FOR( source_band_idx = 0; source_band_idx < source_band_in_target_band_cnt; source_band_idx++ )
616 : {
617 1048 : parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx] = shl_sat( mult( parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx], norm_fac_fx ) /*Q10*/, 5 ); /*Q15*/
618 1048 : move16();
619 : }
620 786 : parameter_band_mapping->n_source_bands[target_band_idx] = source_band_in_target_band_cnt;
621 786 : move16();
622 : }
623 65 : return;
624 : }
625 :
626 :
627 : /*-------------------------------------------------------------------------
628 : * ivas_param_mc_dec_reconfig()
629 : *
630 : * Reconfiguration of ParamMC decoder
631 : *-------------------------------------------------------------------------*/
632 :
633 65 : ivas_error ivas_param_mc_dec_reconfig_fx(
634 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
635 : )
636 : {
637 : Word16 k, nchan_transport;
638 : PARAM_MC_DEC_HANDLE hParamMC;
639 : Word16 nchan_out_transport;
640 : Word16 nchan_out_cov;
641 : Word32 proto_matrix_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
642 : Word32 proto_mtx_norm_fx;
643 : Word16 max_param_band_residual;
644 : UWord16 config_index;
645 : MC_LS_SETUP mc_ls_setup;
646 : Word32 output_Fs, ivas_total_brate;
647 : ivas_error error;
648 : Word16 nchan_transport_old;
649 : Word16 num_param_bands_old;
650 : PARAM_MC_PARAMETER_BAND_MAPPING parameter_band_mapping;
651 : Word16 band_grouping_old[20 + 1];
652 :
653 65 : hParamMC = st_ivas->hParamMC;
654 65 : error = IVAS_ERR_OK;
655 65 : move32();
656 : /* save important config information from the previous state */
657 65 : nchan_transport_old = st_ivas->nchan_transport;
658 65 : move32();
659 65 : num_param_bands_old = hParamMC->hMetadataPMC->num_parameter_bands;
660 65 : move32();
661 :
662 : /*-----------------------------------------------------------------*
663 : * prepare library opening
664 : *-----------------------------------------------------------------*/
665 :
666 65 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
667 65 : move32();
668 65 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
669 65 : move32();
670 65 : mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
671 65 : nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
672 :
673 65 : test();
674 65 : IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
675 : {
676 0 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
677 : }
678 : ELSE
679 : {
680 65 : nchan_out_cov = nchan_out_transport;
681 65 : move16();
682 : }
683 :
684 65 : st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
685 65 : move16();
686 65 : config_index = ivas_param_mc_get_configuration_index_fx( mc_ls_setup, ivas_total_brate );
687 65 : nchan_transport = st_ivas->nchan_transport;
688 65 : move16();
689 :
690 65 : SWITCH( nchan_transport )
691 : {
692 0 : case 4:
693 : case 3:
694 0 : st_ivas->nCPE = 2;
695 0 : move16();
696 0 : st_ivas->nSCE = 0;
697 0 : move16();
698 0 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
699 0 : move16();
700 0 : BREAK;
701 65 : case 2:
702 65 : st_ivas->nCPE = 1;
703 65 : move16();
704 65 : st_ivas->nSCE = 0;
705 65 : move16();
706 65 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
707 65 : move16();
708 :
709 65 : BREAK;
710 : }
711 :
712 : /*-----------------------------------------------------------------*
713 : * set input parameters
714 : *-----------------------------------------------------------------*/
715 65 : hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); // Q0
716 65 : move16();
717 65 : hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands;
718 65 : move16();
719 :
720 65 : Copy( hParamMC->band_grouping, band_grouping_old, add( hParamMC->hMetadataPMC->num_parameter_bands, 1 ) );
721 65 : ivas_param_mc_metadata_open_fx( mc_ls_setup, ivas_total_brate, hParamMC->hMetadataPMC );
722 : /* Band Grouping */
723 65 : IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) )
724 : {
725 0 : Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 );
726 : }
727 65 : ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) )
728 : {
729 34 : Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 );
730 : }
731 31 : ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) )
732 : {
733 31 : Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 );
734 : }
735 : ELSE
736 : {
737 0 : assert( 0 && "nbands must be 20, 14, or 10!" );
738 : }
739 :
740 65 : ivas_param_mc_get_param_band_mapping( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->band_grouping, num_param_bands_old, band_grouping_old, ¶meter_band_mapping );
741 :
742 65 : test();
743 65 : IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) )
744 : {
745 62 : Word16 *ild_q_old_fx = hParamMC->icld_q_fx; // Q8
746 62 : Word16 *icc_q_old_fx = hParamMC->icc_q_fx; // Q15
747 :
748 62 : IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
749 : {
750 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
751 : }
752 62 : IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL )
753 : {
754 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
755 : }
756 62 : set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); /*Q8*/
757 62 : set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); /*Q15*/
758 :
759 : /* map old to new parameter banding, only for same number of TCs, needs some more thought for a changing number of TCs */
760 62 : test();
761 62 : IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) )
762 : {
763 : Word16 new_param_band_idx, param_idx, source_param_idx;
764 : Word16 num_param_lfe;
765 60 : Word16 *p_icc_new_fx = hParamMC->icc_q_fx; // Q15
766 60 : Word16 *p_ild_new_fx = hParamMC->icld_q_fx; // Q8
767 60 : Word16 p_ild_new_e = 23;
768 60 : move16();
769 : Word16 p_ild_new_tmp;
770 :
771 : /* ICC */
772 60 : num_param_lfe = hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe;
773 60 : move16();
774 776 : FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
775 : {
776 4336 : FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ )
777 : {
778 3620 : *p_icc_new_fx = 0;
779 3620 : move16();
780 8484 : FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
781 : {
782 4864 : *p_icc_new_fx = add( *p_icc_new_fx, mult( icc_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); /*Q15*/
783 4864 : move16();
784 : }
785 3620 : p_icc_new_fx++;
786 : }
787 : }
788 :
789 : /* ILD */
790 60 : num_param_lfe = hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe;
791 60 : move16();
792 776 : FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
793 : {
794 5052 : FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ )
795 : {
796 4336 : *p_ild_new_fx = 0;
797 4336 : move16();
798 10160 : FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
799 : {
800 5824 : p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); // 31 - p_ild_new_e - 16
801 5824 : *p_ild_new_fx = add( *p_ild_new_fx, mult( p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) );
802 5824 : move16();
803 : }
804 4336 : *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, L_shl( p_ild_new_e, 25 ) ) ), 24660 /*3.Q13*/ ), 15 ) ); // Q8
805 4336 : move16();
806 4336 : p_ild_new_fx++;
807 : }
808 : }
809 : }
810 62 : free( ild_q_old_fx );
811 62 : free( icc_q_old_fx );
812 : }
813 :
814 65 : param_mc_set_num_synth_bands( output_Fs, hParamMC );
815 :
816 : /* set max parameter band for abs cov */
817 65 : k = 0;
818 65 : move16();
819 588 : WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) )
820 : {
821 523 : hParamMC->max_param_band_abs_cov = k;
822 523 : move16();
823 523 : k = add( k, 1 );
824 : }
825 :
826 : /*-----------------------------------------------------------------*
827 : * open sub-modules
828 : *-----------------------------------------------------------------*/
829 :
830 : /* prototype signal computation */
831 :
832 65 : IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
833 : {
834 0 : IF( NE_16( nchan_transport_old, nchan_transport ) )
835 : {
836 0 : IF( st_ivas->hLsSetUpConversion != NULL )
837 : {
838 0 : ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion );
839 : }
840 :
841 0 : IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
842 : {
843 0 : return error;
844 : }
845 :
846 : /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */
847 0 : free( hParamMC->ls_conv_dmx_matrix_fx );
848 :
849 0 : IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL )
850 : {
851 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
852 : }
853 0 : FOR( k = 0; k < nchan_out_transport; k++ )
854 : {
855 0 : Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov );
856 : }
857 : }
858 : /* convert ParamMC parameter bands to SFB */
859 :
860 0 : st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth;
861 0 : move16();
862 0 : FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ )
863 : {
864 0 : st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] );
865 0 : move16();
866 : }
867 0 : FOR( ; k < MAX_SFB + 2; k++ )
868 : {
869 0 : st_ivas->hLsSetUpConversion->sfbOffset[k] = 0;
870 0 : move16();
871 : }
872 : }
873 :
874 65 : IF( NE_16( nchan_transport_old, nchan_transport ) )
875 : {
876 2 : free( hParamMC->proto_matrix_int_fx );
877 2 : IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL )
878 : {
879 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
880 : }
881 2 : hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport );
882 2 : move16();
883 2 : Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, hParamMC->proto_matrix_int_len ); /*Q31*/
884 : }
885 :
886 65 : test();
887 65 : IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
888 : {
889 0 : Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); // Q30 -> Q26
890 0 : matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0,
891 : ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0,
892 : proto_matrix_fx /*Q26*/ );
893 0 : Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); // Q26 -> Q30
894 :
895 0 : IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
896 : {
897 0 : proto_mtx_norm_fx = ONE_IN_Q26; // Q26
898 0 : move32();
899 0 : FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ )
900 : {
901 0 : proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); // Q26
902 : }
903 0 : proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/
904 :
905 : /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */
906 0 : FOR( k = 0; k < nchan_transport; k++ )
907 : {
908 0 : FOR( Word16 i = 0; i < nchan_out_cov; i++ )
909 : {
910 0 : st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); // Q26 -> Q30
911 0 : move32();
912 : }
913 : }
914 : }
915 : }
916 : ELSE
917 : {
918 65 : Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); // proto_matrix_fx -> Q31
919 65 : Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); // proto_matrix_fx -> Q26
920 : }
921 :
922 65 : test();
923 65 : IF( NE_16( nchan_transport_old, nchan_transport ) && NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
924 : {
925 : Word16 i;
926 : Word16 len;
927 :
928 : /* close decorrelator */
929 2 : ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state );
930 :
931 : /* deallocate diffuse prototype info */
932 2 : IF( hParamMC->diff_proto_info )
933 : {
934 8 : FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ )
935 : {
936 6 : free( hParamMC->diff_proto_info->source_chan_idx[i] );
937 6 : hParamMC->diff_proto_info->source_chan_idx[i] = NULL;
938 :
939 6 : free( hParamMC->diff_proto_info->proto_fac_fx[i] );
940 6 : hParamMC->diff_proto_info->proto_fac_fx[i] = NULL;
941 : }
942 :
943 2 : free( hParamMC->diff_proto_info->source_chan_idx );
944 2 : hParamMC->diff_proto_info->source_chan_idx = NULL;
945 :
946 2 : free( hParamMC->diff_proto_info->proto_fac_fx );
947 2 : hParamMC->diff_proto_info->proto_fac_fx = NULL;
948 :
949 2 : free( hParamMC->diff_proto_info->proto_index_diff );
950 2 : hParamMC->diff_proto_info->proto_index_diff = NULL;
951 :
952 2 : free( hParamMC->diff_proto_info->num_source_chan_diff );
953 2 : hParamMC->diff_proto_info->num_source_chan_diff = NULL;
954 :
955 2 : free( hParamMC->diff_proto_info );
956 2 : hParamMC->diff_proto_info = NULL;
957 : }
958 :
959 2 : hParamMC->num_outputs_diff = nchan_out_cov;
960 2 : move16();
961 2 : IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL )
962 : {
963 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
964 : }
965 2 : IF( ( param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ) != IVAS_ERR_OK )
966 : {
967 0 : return error;
968 : }
969 :
970 : /* decorrelation */
971 2 : hParamMC->h_freq_domain_decorr_ap_params = NULL;
972 2 : hParamMC->h_freq_domain_decorr_ap_state = NULL;
973 :
974 : Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX];
975 2 : ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); // Q0
976 :
977 2 : IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff,
978 : hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ),
979 : IVAS_ERR_OK ) )
980 : {
981 0 : return error;
982 : }
983 2 : hParamMC->h_output_synthesis_params.use_onset_filters = 0;
984 2 : move16();
985 2 : hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr;
986 2 : move16();
987 : /* init decorrelation */
988 2 : IF( hParamMC->max_band_decorr > 0 )
989 : {
990 :
991 2 : len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr );
992 :
993 : /* init onsetDetectionPower */
994 2 : set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
995 2 : set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
996 2 : hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
997 2 : move16();
998 : }
999 : }
1000 65 : hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded];
1001 65 : move16();
1002 65 : max_param_band_residual = 0;
1003 65 : move16();
1004 :
1005 229 : FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
1006 : {
1007 229 : IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
1008 : {
1009 65 : max_param_band_residual = k;
1010 65 : move16();
1011 65 : assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr );
1012 65 : BREAK;
1013 : }
1014 : }
1015 :
1016 65 : test();
1017 65 : IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) )
1018 : {
1019 62 : DIRAC_OUTPUT_SYNTHESIS_COV_STATE cov_state_old = hParamMC->h_output_synthesis_cov_state;
1020 62 : DIRAC_OUTPUT_SYNTHESIS_PARAMS params_old = hParamMC->h_output_synthesis_params;
1021 :
1022 : Word32 tmp_buf_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
1023 :
1024 62 : set_zero_fx( tmp_buf_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
1025 :
1026 : /* output synthesis */
1027 62 : IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS,
1028 : hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ),
1029 : IVAS_ERR_OK ) )
1030 : {
1031 0 : return error;
1032 : }
1033 :
1034 62 : ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx );
1035 :
1036 62 : ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual );
1037 :
1038 : /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */
1039 62 : test();
1040 62 : IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) )
1041 : {
1042 : Word16 new_param_band_idx, source_param_idx;
1043 :
1044 776 : FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ )
1045 : {
1046 1676 : FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
1047 : {
1048 : /* Cx */
1049 960 : v_multc_fixed_16( cov_state_old.cx_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_transport_old ) ); // Q(31 - cov_state_old.cx_old_e)
1050 960 : v_add_fixed_me( tmp_buf_fx, cov_state_old.cx_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cx_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx], imult1616( nchan_transport_old, nchan_transport_old ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cx_old_e[new_param_band_idx])
1051 : /* Cy */
1052 960 : v_multc_fixed_16( cov_state_old.cy_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - cov_state_old.cy_old_e)
1053 960 : v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx])
1054 : /* mixing matrix*/
1055 960 : v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) ); // Q(31 - mixing_matrix_old_exp)
1056 960 : v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); // Q(31 - hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx])
1057 : }
1058 : }
1059 627 : FOR( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ )
1060 : {
1061 1347 : FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ )
1062 : {
1063 : /* residual mixing matrix*/
1064 780 : v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); // Q(31 - mixing_matrix_res_old_exp)
1065 780 : v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); // Q(hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx])
1066 : }
1067 : }
1068 : }
1069 62 : ivas_dirac_dec_output_synthesis_cov_close_fx( ¶ms_old, &cov_state_old );
1070 : }
1071 :
1072 : /*-----------------------------------------------------------------*
1073 : * memory allocation
1074 : *-----------------------------------------------------------------*/
1075 :
1076 65 : test();
1077 65 : IF( ( hParamMC->max_band_decorr > 0 ) && NE_16( nchan_transport_old, nchan_transport ) )
1078 : {
1079 2 : free( hParamMC->proto_frame_f_fx );
1080 2 : IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL )
1081 : {
1082 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
1083 : }
1084 2 : set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
1085 : }
1086 :
1087 :
1088 65 : IF( NE_16( nchan_transport_old, nchan_transport ) )
1089 : {
1090 2 : IF( NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
1091 : {
1092 : Word16 n_cldfb_slots;
1093 2 : IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
1094 : {
1095 2 : free( hParamMC->Cldfb_RealBuffer_tc_fx );
1096 2 : hParamMC->Cldfb_RealBuffer_tc_fx = NULL; // Q12
1097 : }
1098 2 : IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
1099 : {
1100 2 : free( hParamMC->Cldfb_ImagBuffer_tc_fx );
1101 2 : hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; // Q12
1102 : }
1103 :
1104 2 : n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS;
1105 2 : move16();
1106 2 : IF( st_ivas->hDecoderConfig->Opt_tsm )
1107 : {
1108 0 : n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS;
1109 0 : move16();
1110 : }
1111 2 : Word16 cldfb_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands );
1112 2 : IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL )
1113 : {
1114 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
1115 : }
1116 2 : set_zero_fx( hParamMC->Cldfb_RealBuffer_tc_fx, cldfb_size );
1117 :
1118 2 : IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL )
1119 : {
1120 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) );
1121 : }
1122 2 : set_zero_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, cldfb_size );
1123 : }
1124 : ELSE
1125 : {
1126 0 : IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
1127 : {
1128 0 : free( hParamMC->Cldfb_RealBuffer_tc_fx );
1129 0 : hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
1130 : }
1131 0 : IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
1132 : {
1133 0 : free( hParamMC->Cldfb_ImagBuffer_tc_fx );
1134 0 : hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
1135 : }
1136 : }
1137 : }
1138 65 : return error;
1139 : }
1140 :
1141 :
1142 : /*-------------------------------------------------------------------------
1143 : * param_mc_get_num_cldfb_syntheses()
1144 : *
1145 : * calculate the necessary number of CLDFB synthesis instances
1146 : *------------------------------------------------------------------------*/
1147 :
1148 : /*! r: number of cldfb synthesis instances */
1149 314 : Word16 param_mc_get_num_cldfb_syntheses_fx(
1150 : Decoder_Struct *st_ivas /* i : Parametric MC handle */
1151 : )
1152 : {
1153 : Word16 num_cldfb_syntheses;
1154 :
1155 314 : num_cldfb_syntheses = 0;
1156 314 : move16();
1157 :
1158 : /* sanity check*/
1159 314 : IF( st_ivas->hParamMC == NULL )
1160 : {
1161 0 : assert( 0 && "ParamMC handle does not exist!\n" );
1162 : }
1163 :
1164 314 : test();
1165 314 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
1166 : {
1167 0 : num_cldfb_syntheses = 2;
1168 0 : move16();
1169 : }
1170 314 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1171 : {
1172 144 : num_cldfb_syntheses = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1173 : }
1174 170 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) )
1175 : {
1176 170 : num_cldfb_syntheses = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
1177 : }
1178 :
1179 314 : return num_cldfb_syntheses;
1180 : }
1181 :
1182 :
1183 : /*-------------------------------------------------------------------------
1184 : * ivas_param_mc_dec_close()
1185 : *
1186 : * Close Parametric MC memories
1187 : *------------------------------------------------------------------------*/
1188 :
1189 882 : void ivas_param_mc_dec_close_fx(
1190 : PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */
1191 : )
1192 : {
1193 : UWord16 i;
1194 : PARAM_MC_DEC_HANDLE hParamMC;
1195 :
1196 882 : IF( hParamMC_out == NULL || *hParamMC_out == NULL )
1197 : {
1198 603 : return;
1199 : }
1200 :
1201 279 : hParamMC = *hParamMC_out;
1202 :
1203 : /* close sub-modules */
1204 279 : ivas_dirac_dec_output_synthesis_cov_close_fx( &hParamMC->h_output_synthesis_params, &hParamMC->h_output_synthesis_cov_state );
1205 :
1206 279 : IF( hParamMC->h_freq_domain_decorr_ap_params != NULL || hParamMC->h_freq_domain_decorr_ap_state != NULL )
1207 : {
1208 277 : ivas_dirac_dec_decorr_close_fx( &hParamMC->h_freq_domain_decorr_ap_params, &hParamMC->h_freq_domain_decorr_ap_state );
1209 : }
1210 :
1211 : /* parameter decoding */
1212 279 : IF( hParamMC->hMetadataPMC != NULL )
1213 : {
1214 279 : free( hParamMC->hMetadataPMC );
1215 279 : hParamMC->hMetadataPMC = NULL;
1216 : }
1217 279 : IF( hParamMC->icc_q_fx != NULL )
1218 : {
1219 279 : free( hParamMC->icc_q_fx );
1220 279 : hParamMC->icc_q_fx = NULL; // Q15
1221 : }
1222 :
1223 279 : IF( hParamMC->icld_q_fx != NULL )
1224 : {
1225 279 : free( hParamMC->icld_q_fx );
1226 279 : hParamMC->icld_q_fx = NULL; // Q8
1227 : }
1228 : /* diffuse prototype info */
1229 279 : IF( hParamMC->diff_proto_info )
1230 : {
1231 1110 : FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ )
1232 : {
1233 833 : free( hParamMC->diff_proto_info->source_chan_idx[i] );
1234 833 : hParamMC->diff_proto_info->source_chan_idx[i] = NULL;
1235 :
1236 833 : free( hParamMC->diff_proto_info->proto_fac_fx[i] );
1237 833 : hParamMC->diff_proto_info->proto_fac_fx[i] = NULL;
1238 : }
1239 :
1240 277 : free( hParamMC->diff_proto_info->source_chan_idx );
1241 277 : hParamMC->diff_proto_info->source_chan_idx = NULL;
1242 :
1243 277 : free( hParamMC->diff_proto_info->proto_fac_fx );
1244 277 : hParamMC->diff_proto_info->proto_fac_fx = NULL;
1245 :
1246 277 : free( hParamMC->diff_proto_info->proto_index_diff );
1247 277 : hParamMC->diff_proto_info->proto_index_diff = NULL;
1248 :
1249 277 : free( hParamMC->diff_proto_info->num_source_chan_diff );
1250 277 : hParamMC->diff_proto_info->num_source_chan_diff = NULL;
1251 :
1252 277 : free( hParamMC->diff_proto_info );
1253 277 : hParamMC->diff_proto_info = NULL;
1254 : }
1255 : /* States */
1256 : /* free prototype signal buffers */
1257 279 : IF( hParamMC->proto_frame_f_fx != NULL )
1258 : {
1259 277 : free( hParamMC->proto_frame_f_fx );
1260 277 : hParamMC->proto_frame_f_fx = NULL;
1261 : }
1262 :
1263 279 : IF( hParamMC->proto_frame_dec_f_fx != NULL )
1264 : {
1265 277 : free( hParamMC->proto_frame_dec_f_fx );
1266 277 : hParamMC->proto_frame_dec_f_fx = NULL;
1267 : }
1268 :
1269 279 : IF( hParamMC->ls_conv_dmx_matrix_fx != NULL )
1270 : {
1271 3 : free( hParamMC->ls_conv_dmx_matrix_fx );
1272 3 : hParamMC->ls_conv_dmx_matrix_fx = NULL;
1273 : }
1274 :
1275 279 : IF( hParamMC->proto_matrix_int_fx != NULL )
1276 : {
1277 279 : free( hParamMC->proto_matrix_int_fx );
1278 279 : hParamMC->proto_matrix_int_fx = NULL;
1279 : }
1280 :
1281 279 : IF( hParamMC->hoa_encoder_fx != NULL )
1282 : {
1283 13 : free( hParamMC->hoa_encoder_fx );
1284 13 : hParamMC->hoa_encoder_fx = NULL;
1285 : }
1286 279 : IF( hParamMC->Cldfb_RealBuffer_tc_fx != NULL )
1287 : {
1288 277 : free( hParamMC->Cldfb_RealBuffer_tc_fx );
1289 277 : hParamMC->Cldfb_RealBuffer_tc_fx = NULL;
1290 : }
1291 279 : IF( hParamMC->Cldfb_ImagBuffer_tc_fx != NULL )
1292 : {
1293 277 : free( hParamMC->Cldfb_ImagBuffer_tc_fx );
1294 277 : hParamMC->Cldfb_ImagBuffer_tc_fx = NULL;
1295 : }
1296 :
1297 279 : free( *hParamMC_out );
1298 279 : *hParamMC_out = NULL;
1299 :
1300 279 : return;
1301 : }
1302 :
1303 :
1304 : /*-------------------------------------------------------------------------
1305 : * ivas_param_mc_dec_read_BS()
1306 : *
1307 : * Read the Parametric MC metadata
1308 : *------------------------------------------------------------------------*/
1309 :
1310 10249 : void ivas_param_mc_dec_read_BS_fx(
1311 : const Word32 ivas_total_brate, /* i : IVAS total bitrate */
1312 : Decoder_State *st, /* i/o: decoder state structure */
1313 : PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder ParamMC handle */
1314 : Word16 *nb_bits /* o : number of bits written */
1315 : )
1316 : {
1317 : Word16 param_frame_idx;
1318 : Word16 band_step;
1319 : UWord16 bit_buffer[PARAM_MC_MAX_BITS];
1320 : Word16 bits_to_copy;
1321 : Word16 bit_pos;
1322 : Word16 num_lfe_bands;
1323 : Word16 num_param_bands;
1324 : Word16 metadata_bit_pos;
1325 : Word16 i, j, k;
1326 : Word16 icc_map_size;
1327 : Word16 icc_map_size_wo_lfe;
1328 : Word16 ild_map_size;
1329 : Word16 ild_map_size_wo_lfe;
1330 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC;
1331 :
1332 10249 : push_wmops( "param_mc_read_bs" );
1333 :
1334 : /* Inits */
1335 10249 : *nb_bits = 0;
1336 10249 : move16();
1337 10249 : hMetadataPMC = hParamMC->hMetadataPMC;
1338 10249 : icc_map_size = hMetadataPMC->icc_mapping_conf->icc_map_size_lfe;
1339 10249 : move16();
1340 10249 : icc_map_size_wo_lfe = hMetadataPMC->icc_mapping_conf->icc_map_size_wo_lfe;
1341 10249 : move16();
1342 10249 : ild_map_size = hMetadataPMC->ild_mapping_conf->ild_map_size_lfe;
1343 10249 : move16();
1344 10249 : ild_map_size_wo_lfe = hMetadataPMC->ild_mapping_conf->ild_map_size_wo_lfe;
1345 10249 : move16();
1346 :
1347 10249 : IF( !st->bfi )
1348 : {
1349 : /*metadata_bit_pos = extract_l(ivas_total_brate / FRAMES_PER_SEC - 1);
1350 : bits_to_copy = s_min(extract_l(ivas_total_brate / FRAMES_PER_SEC), PARAM_MC_MAX_BITS);*/
1351 10216 : Word16 temp = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) );
1352 10216 : metadata_bit_pos = sub( temp, 1 );
1353 10216 : bits_to_copy = s_min( temp, PARAM_MC_MAX_BITS );
1354 :
1355 : /* copy and reverse metadata */
1356 10350440 : FOR( bit_pos = 0; bit_pos < bits_to_copy; bit_pos++ )
1357 : {
1358 10340224 : bit_buffer[bit_pos] = st->bit_stream[metadata_bit_pos];
1359 10340224 : move16();
1360 10340224 : metadata_bit_pos = sub( metadata_bit_pos, 1 );
1361 10340224 : move16();
1362 : }
1363 :
1364 10216 : bit_pos = 0;
1365 10216 : move16();
1366 :
1367 : /* read reserved bit */
1368 10216 : hMetadataPMC->lfe_on = bit_buffer[bit_pos++];
1369 10216 : move16();
1370 :
1371 : /* get coded bwidth */
1372 : {
1373 : Word16 pos;
1374 10216 : Word16 bw = 0;
1375 10216 : move16();
1376 30648 : FOR( pos = 0; pos < 2; pos++ )
1377 : {
1378 20432 : bw = add( bw, extract_l( L_shl( bit_buffer[bit_pos++], pos ) ) );
1379 : }
1380 10216 : hMetadataPMC->coded_bwidth = bw;
1381 10216 : move16();
1382 : }
1383 :
1384 : /* set tables if coded band width differs from last frame */
1385 10216 : IF( NE_16( hMetadataPMC->coded_bwidth, hMetadataPMC->last_coded_bwidth ) )
1386 : {
1387 86 : ivas_param_mc_set_coded_bands_fx( hMetadataPMC );
1388 86 : param_mc_set_num_synth_bands( st->output_Fs, hParamMC );
1389 86 : hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->num_param_bands_synth];
1390 86 : move16();
1391 : }
1392 :
1393 10216 : param_frame_idx = bit_buffer[bit_pos++];
1394 10216 : move16();
1395 10216 : hMetadataPMC->param_frame_idx = param_frame_idx;
1396 10216 : move16();
1397 10216 : num_param_bands = hMetadataPMC->nbands_in_param_frame[param_frame_idx];
1398 10216 : move16();
1399 :
1400 10216 : hMetadataPMC->bAttackPresent = bit_buffer[bit_pos++];
1401 10216 : move16();
1402 10216 : hMetadataPMC->attackIndex = 0;
1403 10216 : move16();
1404 10216 : band_step = 1;
1405 10216 : move16();
1406 10216 : num_lfe_bands = 0;
1407 10216 : move16();
1408 :
1409 10216 : IF( hMetadataPMC->bAttackPresent )
1410 : {
1411 1956 : FOR( i = 2; i >= 0; i-- )
1412 : {
1413 1467 : hMetadataPMC->attackIndex = add( hMetadataPMC->attackIndex, extract_l( L_shl( bit_buffer[bit_pos++], i ) ) );
1414 : }
1415 :
1416 489 : band_step = PARAM_MC_TRANSIENT_BAND_STEP;
1417 489 : move16();
1418 :
1419 : /*num_lfe_bands = add(PARAM_MC_MAX_BAND_LFE / band_step, (PARAM_MC_MAX_BAND_LFE % band_step) ? 1 : 0);
1420 : num_param_bands = add(hMetadataPMC->nbands_coded / band_step, ((hMetadataPMC->nbands_coded % band_step) ? 1 : 0));*/
1421 : Word16 temp_e;
1422 489 : temp = BASOP_Util_Divide3232_Scale( PARAM_MC_MAX_BAND_LFE, band_step, &temp_e );
1423 489 : temp = shr( temp, sub( 15, temp_e ) );
1424 : Word16 temp1;
1425 489 : IF( PARAM_MC_MAX_BAND_LFE % band_step )
1426 : {
1427 489 : temp1 = 1;
1428 : }
1429 : ELSE
1430 : {
1431 0 : temp1 = 0;
1432 : }
1433 489 : move16();
1434 489 : num_lfe_bands = add( temp, temp1 );
1435 :
1436 489 : temp = BASOP_Util_Divide3232_Scale( hMetadataPMC->nbands_coded, band_step, &temp_e );
1437 489 : temp = shr( temp, sub( 15, temp_e ) );
1438 : Word16 temp2;
1439 489 : IF( hMetadataPMC->nbands_coded % band_step )
1440 : {
1441 53 : temp2 = 1;
1442 : }
1443 : ELSE
1444 : {
1445 436 : temp2 = 0;
1446 : }
1447 489 : move16();
1448 489 : num_param_bands = add( temp, temp2 );
1449 : }
1450 : ELSE
1451 : {
1452 19454 : FOR( j = 0; j < PARAM_MC_MAX_BAND_LFE; j += band_step )
1453 : {
1454 9727 : IF( EQ_16( param_frame_idx, hMetadataPMC->coding_band_mapping[j] ) )
1455 : {
1456 : /* LFE ICC is always the last ICC in coding band 0 */
1457 4876 : num_lfe_bands = add( num_lfe_bands, 1 );
1458 4876 : move16();
1459 : }
1460 : }
1461 : }
1462 :
1463 10216 : IF( !hMetadataPMC->lfe_on )
1464 : {
1465 9151 : num_lfe_bands = 0;
1466 9151 : move16();
1467 : }
1468 :
1469 10216 : ivas_param_mc_bs_decode_parameter_values_fx( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->icc_coding,
1470 : icc_map_size_wo_lfe, icc_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icc_q_fx );
1471 :
1472 10216 : IF( !st->BER_detect )
1473 : {
1474 10216 : ivas_param_mc_bs_decode_parameter_values_fx( bit_buffer, &bit_pos, bits_to_copy, &st->BER_detect, hMetadataPMC, &hMetadataPMC->ild_coding,
1475 : ild_map_size_wo_lfe, ild_map_size, num_lfe_bands, band_step, num_param_bands, hParamMC->icld_q_fx );
1476 : }
1477 : /* set LFE ILD and ICC to zero above PARAM_MC_MAX_BAND_LFE for attack frames */
1478 10216 : IF( hMetadataPMC->bAttackPresent )
1479 : {
1480 640 : FOR( k = PARAM_MC_MAX_BAND_LFE; k < imult1616( band_step, num_lfe_bands ); k++ )
1481 : {
1482 151 : hParamMC->icc_q_fx[L_sub( L_mult0( add( k, 1 ), icc_map_size ), 1 )] = 32767; /* 1.0f in Q15 */
1483 151 : move16();
1484 151 : hParamMC->icld_q_fx[L_sub( L_mult0( add( k, 1 ), ild_map_size ), 1 )] = PARAM_MC_DEFAULT_MIN_ILD_FX; /* -92.0f in Q8 */
1485 151 : move16();
1486 : }
1487 : }
1488 :
1489 10216 : *nb_bits = bit_pos;
1490 10216 : move16();
1491 :
1492 : } /* if ( !st->bfi ) */
1493 :
1494 10249 : IF( st->bfi )
1495 : {
1496 : /* for PLC, use the saved ILDs and ICCs from the past and set the transient flag and transient position to zero */
1497 33 : hMetadataPMC->bAttackPresent = 0;
1498 33 : move16();
1499 33 : hMetadataPMC->attackIndex = 0;
1500 33 : move16();
1501 : }
1502 :
1503 10249 : pop_wmops();
1504 :
1505 10249 : return;
1506 : }
1507 :
1508 :
1509 : /*-------------------------------------------------------------------------
1510 : * ivas_param_mc_dec_digest_tc()
1511 : *
1512 : *
1513 : *------------------------------------------------------------------------*/
1514 :
1515 10229 : void ivas_param_mc_dec_digest_tc_fx(
1516 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
1517 : const UWord8 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */
1518 : Word32 *transport_channels_f_fx[],
1519 : Word16 transport_f_e )
1520 : {
1521 : PARAM_MC_DEC_HANDLE hParamMC;
1522 : #ifdef OBJ_EDITING_API
1523 : Word16 ch, slot_idx;
1524 : Word16 nchan_transport;
1525 : #else
1526 : Word16 i, ch;
1527 : Word16 is_next_band, skip_next_band;
1528 : Word16 slot_idx, param_band_idx;
1529 : Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
1530 : Word16 nchan_out_cov;
1531 : #endif
1532 : /*CLDFB*/
1533 :
1534 10229 : hParamMC = st_ivas->hParamMC;
1535 10229 : assert( hParamMC );
1536 :
1537 : #ifndef OBJ_EDITING_API
1538 : Word32 *pCx, *pCx_imag;
1539 : Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_e)
1540 : Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_e)
1541 : Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_next_band_e)
1542 : Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_next_band_e)
1543 : Word32 real_part_fx, imag_part_fx, L_tmp1, L_tmp2;
1544 :
1545 : Word16 cx_buff_e[2][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
1546 : Word16 cx_e;
1547 : Word16 cx_imag_e, tmp_e;
1548 : Word16 cx_imag_next_band_e, cx_next_band_e;
1549 :
1550 : Word16 max_e;
1551 :
1552 : /* format converter */
1553 : Word16 channel_active[MAX_OUTPUT_CHANNELS];
1554 : IVAS_OUTPUT_SETUP *hSynthesisOutputSetup;
1555 : #endif
1556 10229 : Word16 qout = 0;
1557 10229 : move16();
1558 :
1559 :
1560 10229 : push_wmops( "param_mc_dec_digest_tc" );
1561 :
1562 : #ifndef OBJ_EDITING_API
1563 : set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
1564 : #endif
1565 10229 : nchan_transport = st_ivas->nchan_transport;
1566 10229 : move16();
1567 :
1568 : #ifndef OBJ_EDITING_API
1569 : nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1570 :
1571 : test();
1572 : test();
1573 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
1574 : {
1575 : nchan_out_cldfb = BINAURAL_CHANNELS;
1576 : move16();
1577 : set16_fx( channel_active, 1, nchan_out_cldfb );
1578 : nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1579 : hSynthesisOutputSetup = &st_ivas->hTransSetup;
1580 : }
1581 : ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
1582 : {
1583 : nchan_out_cov = nchan_out_transport;
1584 : move16();
1585 : nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
1586 : hSynthesisOutputSetup = &st_ivas->hTransSetup;
1587 : }
1588 : ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
1589 : {
1590 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
1591 : nchan_out_cldfb = nchan_out_cov;
1592 : move16();
1593 : set16_fx( channel_active, 1, nchan_out_cov );
1594 : hSynthesisOutputSetup = &st_ivas->hOutSetup;
1595 : }
1596 : ELSE
1597 : {
1598 : nchan_out_cov = nchan_out_transport;
1599 : move16();
1600 : nchan_out_cldfb = nchan_out_transport;
1601 : move16();
1602 : set16_fx( channel_active, 1, nchan_out_cov );
1603 : hSynthesisOutputSetup = &st_ivas->hTransSetup;
1604 : }
1605 :
1606 : /* adapt transient position */
1607 : IF( hParamMC->hMetadataPMC->bAttackPresent )
1608 : {
1609 : hParamMC->hMetadataPMC->attackIndex = s_max( 0, add( hParamMC->hMetadataPMC->attackIndex, shr( sub( nCldfbSlots, DEFAULT_JBM_CLDFB_TIMESLOTS ), 1 ) ) );
1610 : move16();
1611 : }
1612 : /* adapt subframes */
1613 : hParamMC->num_slots = nCldfbSlots;
1614 : move16();
1615 : hParamMC->slots_rendered = 0;
1616 : move16();
1617 : hParamMC->subframes_rendered = 0;
1618 : move16();
1619 : ivas_jbm_dec_get_adapted_subframes( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes );
1620 : st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes;
1621 : move16();
1622 : Copy( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes );
1623 :
1624 : ivas_param_mc_dec_compute_interpolator_fx( hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx );
1625 :
1626 : /* loop over two bands at a time */
1627 : FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 )
1628 : {
1629 : /* don't process next band if it exceeds the limit */
1630 : skip_next_band = ( ( param_band_idx + 1 ) == hParamMC->num_param_bands_synth ) ? 1 : 0;
1631 :
1632 : set_zero_fx( cx_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
1633 : set_zero_fx( cx_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
1634 : set_zero_fx( cx_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
1635 : set_zero_fx( cx_imag_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
1636 :
1637 : cx_e = 0;
1638 : move16();
1639 : cx_imag_e = 0;
1640 : move16();
1641 : cx_next_band_e = 0;
1642 : move16();
1643 : cx_imag_next_band_e = 0;
1644 : move16();
1645 : #endif
1646 :
1647 : /* slot loop for gathering the input data */
1648 173896 : FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
1649 : {
1650 163667 : IF( st_ivas->hDecoderConfig->Opt_tsm )
1651 : {
1652 : #ifndef OBJ_EDITING_API
1653 : IF( param_band_idx == 0 ) /* only run cldfbAna once */
1654 : {
1655 : #endif
1656 : Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX];
1657 : Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX];
1658 :
1659 : /* CLDFB Analysis*/
1660 2089 : FOR( ch = 0; ch < nchan_transport; ch++ )
1661 : {
1662 1446 : qout = transport_f_e;
1663 1446 : move16();
1664 1446 : cldfbAnalysis_ts_fx_fixed_q( &( transport_channels_f_fx[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch], &qout );
1665 :
1666 1446 : Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands );
1667 1446 : Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands );
1668 : }
1669 :
1670 643 : hParamMC->Cldfb_ImagBuffer_tc_e = qout;
1671 643 : move16();
1672 : #ifndef OBJ_EDITING_API
1673 : }
1674 : #endif
1675 : }
1676 :
1677 : #ifndef OBJ_EDITING_API
1678 : IF( GE_16( slot_idx, shl( hParamMC->hMetadataPMC->attackIndex, 1 ) ) )
1679 : {
1680 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
1681 : {
1682 : test();
1683 : IF( is_next_band && skip_next_band )
1684 : {
1685 : CONTINUE;
1686 : }
1687 : IF( is_next_band )
1688 : {
1689 : ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
1690 : /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
1691 : &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
1692 : /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
1693 : cx_next_band_fx,
1694 : &cx_next_band_e,
1695 : cx_imag_next_band_fx,
1696 : &cx_imag_next_band_e,
1697 : hParamMC,
1698 : add( param_band_idx, is_next_band ),
1699 : nchan_transport );
1700 : }
1701 : ELSE
1702 : {
1703 : ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
1704 : /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
1705 : &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
1706 : /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
1707 : cx_fx,
1708 : &cx_e,
1709 : cx_imag_fx,
1710 : &cx_imag_e,
1711 : hParamMC,
1712 : add( param_band_idx, is_next_band ),
1713 : nchan_transport );
1714 : }
1715 : }
1716 : }
1717 : #endif
1718 : }
1719 :
1720 : #ifndef OBJ_EDITING_API
1721 : Word16 tmp_cx_e, tmp_cx_imag_e;
1722 : /* map from complex input covariance to real values */
1723 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
1724 : {
1725 : test();
1726 : IF( is_next_band && skip_next_band )
1727 : {
1728 : CONTINUE;
1729 : }
1730 : /* Cx for transport channels */
1731 : IF( is_next_band )
1732 : {
1733 : pCx = &cx_next_band_fx[0];
1734 : pCx_imag = &cx_imag_next_band_fx[0];
1735 : tmp_cx_e = cx_next_band_e;
1736 : tmp_cx_imag_e = cx_imag_next_band_e;
1737 : }
1738 : ELSE
1739 : {
1740 : pCx = &cx_fx[0];
1741 : pCx_imag = &cx_imag_fx[0];
1742 : tmp_cx_e = cx_e;
1743 : tmp_cx_imag_e = cx_imag_e;
1744 : }
1745 :
1746 : FOR( i = 0; i < nchan_transport * nchan_transport; i++ )
1747 : {
1748 : real_part_fx = pCx[i]; // Q(31 - cx_buff_e)
1749 : imag_part_fx = pCx_imag[i];
1750 : move32();
1751 : move32();
1752 : cx_buff_e[is_next_band][i] = tmp_cx_e;
1753 : move16();
1754 : /* (a-ib)(c+id) = ac + bd + i(ad-bc) */
1755 : IF( LT_16( param_band_idx, hParamMC->max_param_band_abs_cov ) )
1756 : {
1757 : L_tmp1 = Mpy_32_32( real_part_fx, real_part_fx );
1758 : L_tmp2 = Mpy_32_32( imag_part_fx, imag_part_fx );
1759 : L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, add( tmp_cx_e, tmp_cx_e ), L_tmp2, add( tmp_cx_imag_e, tmp_cx_imag_e ), &tmp_e );
1760 : pCx[i] = Sqrt32( L_tmp1, &tmp_e );
1761 : move32();
1762 : cx_buff_e[is_next_band][i] = tmp_e;
1763 : move16();
1764 : }
1765 : ELSE
1766 : {
1767 : pCx[i] = real_part_fx;
1768 : move32();
1769 : cx_buff_e[is_next_band][i] = tmp_cx_e;
1770 : move16();
1771 : }
1772 : }
1773 : }
1774 :
1775 : max_e = cx_buff_e[0][0];
1776 : move16();
1777 :
1778 : /* Cx for transport channels */
1779 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
1780 : {
1781 : FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
1782 : {
1783 :
1784 : IF( LT_16( max_e, cx_buff_e[is_next_band][i] ) )
1785 : {
1786 : max_e = cx_buff_e[is_next_band][i];
1787 : }
1788 : }
1789 : }
1790 : /* Cx for transport channels */
1791 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
1792 : {
1793 : FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
1794 : {
1795 : if ( is_next_band == 0 )
1796 : {
1797 : cx_fx[i] = L_shr( cx_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
1798 : }
1799 : else
1800 : {
1801 : cx_next_band_fx[i] = L_shr( cx_next_band_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
1802 : }
1803 : move32();
1804 : }
1805 : }
1806 : cx_e = max_e;
1807 : move16();
1808 :
1809 :
1810 : /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/
1811 :
1812 : test();
1813 : test();
1814 : IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) )
1815 : {
1816 : Word16 len = imult1616( nchan_transport, nchan_transport );
1817 : Word16 sc = s_min( getScaleFactor32( cx_fx, len ), getScaleFactor32( cx_next_band_fx, len ) );
1818 : IF( EQ_16( sc, 0 ) )
1819 : {
1820 : Scale_sig32( cx_fx, len, -Q1 ); // add one bit head room
1821 : Scale_sig32( cx_next_band_fx, len, -Q1 ); // add one bit head room
1822 : cx_e = add( cx_e, Q1 );
1823 : cx_next_band_e = add( cx_e, Q1 );
1824 : }
1825 : v_add_fx( cx_fx, cx_next_band_fx, cx_fx, len );
1826 : Copy32( cx_fx, cx_next_band_fx, len );
1827 : }
1828 :
1829 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
1830 : {
1831 : test();
1832 : IF( is_next_band && skip_next_band )
1833 : {
1834 : CONTINUE;
1835 : }
1836 :
1837 : IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
1838 : {
1839 : IF( is_next_band )
1840 : {
1841 :
1842 : ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_next_band_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
1843 : }
1844 : ELSE
1845 : {
1846 :
1847 : ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
1848 : }
1849 : }
1850 : }
1851 : }
1852 : #endif
1853 10229 : pop_wmops();
1854 :
1855 10229 : return;
1856 : }
1857 :
1858 :
1859 : #ifdef OBJ_EDITING_API
1860 : /*-------------------------------------------------------------------------
1861 : * ivas_param_mc_dec_prepare_renderer()
1862 : *
1863 : *
1864 : *------------------------------------------------------------------------*/
1865 :
1866 10229 : void ivas_param_mc_dec_prepare_renderer(
1867 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
1868 : const UWord8 nCldfbSlots /* i : number of CLFBS slots in the transport channels */
1869 : )
1870 : {
1871 : Word16 i;
1872 : Word16 is_next_band, skip_next_band;
1873 : Word16 slot_idx, param_band_idx;
1874 : Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
1875 : Word16 nchan_out_cov;
1876 : PARAM_MC_DEC_HANDLE hParamMC;
1877 :
1878 : Word32 *pCx, *pCx_imag;
1879 : Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_e)
1880 : Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_e)
1881 : Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_next_band_e)
1882 : Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - cx_imag_next_band_e)
1883 : Word32 real_part_fx, imag_part_fx, L_tmp1, L_tmp2;
1884 :
1885 : Word16 cx_buff_e[2][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
1886 : Word16 cx_e;
1887 : Word16 cx_imag_e, tmp_e;
1888 : Word16 cx_imag_next_band_e, cx_next_band_e;
1889 :
1890 : Word16 max_e;
1891 :
1892 : /* format converter */
1893 : Word16 channel_active[MAX_OUTPUT_CHANNELS];
1894 : IVAS_OUTPUT_SETUP *hSynthesisOutputSetup;
1895 :
1896 10229 : hParamMC = st_ivas->hParamMC;
1897 10229 : assert( hParamMC );
1898 :
1899 10229 : set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
1900 :
1901 10229 : nchan_transport = st_ivas->nchan_transport;
1902 10229 : move16();
1903 :
1904 10229 : nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1905 :
1906 10229 : test();
1907 10229 : test();
1908 10229 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
1909 : {
1910 8239 : nchan_out_cldfb = BINAURAL_CHANNELS;
1911 8239 : move16();
1912 8239 : set16_fx( channel_active, 1, nchan_out_cldfb );
1913 8239 : nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1914 8239 : hSynthesisOutputSetup = &st_ivas->hTransSetup;
1915 : }
1916 1990 : ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
1917 : {
1918 340 : nchan_out_cov = nchan_out_transport;
1919 340 : move16();
1920 340 : nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
1921 340 : hSynthesisOutputSetup = &st_ivas->hTransSetup;
1922 : }
1923 1650 : ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
1924 : {
1925 150 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
1926 150 : nchan_out_cldfb = nchan_out_cov;
1927 150 : move16();
1928 150 : set16_fx( channel_active, 1, nchan_out_cov );
1929 150 : hSynthesisOutputSetup = &st_ivas->hOutSetup;
1930 : }
1931 : ELSE
1932 : {
1933 1500 : nchan_out_cov = nchan_out_transport;
1934 1500 : move16();
1935 1500 : nchan_out_cldfb = nchan_out_transport;
1936 1500 : move16();
1937 1500 : set16_fx( channel_active, 1, nchan_out_cov );
1938 1500 : hSynthesisOutputSetup = &st_ivas->hTransSetup;
1939 : }
1940 :
1941 : /* adapt transient position */
1942 10229 : IF( hParamMC->hMetadataPMC->bAttackPresent )
1943 : {
1944 484 : hParamMC->hMetadataPMC->attackIndex = s_max( 0, add( hParamMC->hMetadataPMC->attackIndex, shr( sub( nCldfbSlots, DEFAULT_JBM_CLDFB_TIMESLOTS ), 1 ) ) );
1945 484 : move16();
1946 : }
1947 : /* adapt subframes */
1948 10229 : hParamMC->num_slots = nCldfbSlots;
1949 10229 : move16();
1950 10229 : hParamMC->slots_rendered = 0;
1951 10229 : move16();
1952 10229 : hParamMC->subframes_rendered = 0;
1953 10229 : move16();
1954 10229 : ivas_jbm_dec_get_adapted_subframes( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes );
1955 10229 : st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes;
1956 10229 : move16();
1957 10229 : Copy( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes );
1958 :
1959 10229 : ivas_param_mc_dec_compute_interpolator_fx( hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx );
1960 :
1961 : /* loop over two bands at a time */
1962 77492 : FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 )
1963 : {
1964 : /* don't process next band if it exceeds the limit */
1965 67263 : skip_next_band = ( ( param_band_idx + 1 ) == hParamMC->num_param_bands_synth ) ? 1 : 0;
1966 :
1967 67263 : set_zero_fx( cx_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
1968 67263 : set_zero_fx( cx_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
1969 67263 : set_zero_fx( cx_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
1970 67263 : set_zero_fx( cx_imag_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
1971 :
1972 67263 : cx_e = 0;
1973 67263 : move16();
1974 67263 : cx_imag_e = 0;
1975 67263 : move16();
1976 67263 : cx_next_band_e = 0;
1977 67263 : move16();
1978 67263 : cx_imag_next_band_e = 0;
1979 67263 : move16();
1980 :
1981 : /* slot loop for gathering the input data */
1982 1143486 : FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ )
1983 : {
1984 1076223 : IF( GE_16( slot_idx, shl( hParamMC->hMetadataPMC->attackIndex, 1 ) ) )
1985 : {
1986 3167007 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
1987 : {
1988 2111338 : test();
1989 2111338 : IF( is_next_band && skip_next_band )
1990 : {
1991 27003 : CONTINUE;
1992 : }
1993 2084335 : IF( is_next_band )
1994 : {
1995 2057332 : ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
1996 : /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
1997 1028666 : &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
1998 : /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
1999 : cx_next_band_fx,
2000 : &cx_next_band_e,
2001 : cx_imag_next_band_fx,
2002 : &cx_imag_next_band_e,
2003 : hParamMC,
2004 1028666 : add( param_band_idx, is_next_band ),
2005 : nchan_transport );
2006 : }
2007 : ELSE
2008 : {
2009 2111338 : ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
2010 : /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6,
2011 1055669 : &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport],
2012 : /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6,
2013 : cx_fx,
2014 : &cx_e,
2015 : cx_imag_fx,
2016 : &cx_imag_e,
2017 : hParamMC,
2018 1055669 : add( param_band_idx, is_next_band ),
2019 : nchan_transport );
2020 : }
2021 : }
2022 : }
2023 : }
2024 : Word16 tmp_cx_e, tmp_cx_imag_e;
2025 : /* map from complex input covariance to real values */
2026 201789 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
2027 : {
2028 134526 : test();
2029 134526 : IF( is_next_band && skip_next_band )
2030 : {
2031 1739 : CONTINUE;
2032 : }
2033 : /* Cx for transport channels */
2034 132787 : IF( is_next_band )
2035 : {
2036 65524 : pCx = &cx_next_band_fx[0];
2037 65524 : pCx_imag = &cx_imag_next_band_fx[0];
2038 65524 : tmp_cx_e = cx_next_band_e;
2039 65524 : tmp_cx_imag_e = cx_imag_next_band_e;
2040 : }
2041 : ELSE
2042 : {
2043 67263 : pCx = &cx_fx[0];
2044 67263 : pCx_imag = &cx_imag_fx[0];
2045 67263 : tmp_cx_e = cx_e;
2046 67263 : tmp_cx_imag_e = cx_imag_e;
2047 : }
2048 :
2049 670735 : FOR( i = 0; i < nchan_transport * nchan_transport; i++ )
2050 : {
2051 537948 : real_part_fx = pCx[i]; // Q(31 - cx_buff_e)
2052 537948 : imag_part_fx = pCx_imag[i];
2053 537948 : move32();
2054 537948 : move32();
2055 537948 : cx_buff_e[is_next_band][i] = tmp_cx_e;
2056 537948 : move16();
2057 : /* (a-ib)(c+id) = ac + bd + i(ad-bc) */
2058 537948 : IF( LT_16( param_band_idx, hParamMC->max_param_band_abs_cov ) )
2059 : {
2060 316108 : L_tmp1 = Mpy_32_32( real_part_fx, real_part_fx );
2061 316108 : L_tmp2 = Mpy_32_32( imag_part_fx, imag_part_fx );
2062 316108 : L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, add( tmp_cx_e, tmp_cx_e ), L_tmp2, add( tmp_cx_imag_e, tmp_cx_imag_e ), &tmp_e );
2063 316108 : pCx[i] = Sqrt32( L_tmp1, &tmp_e );
2064 316108 : move32();
2065 316108 : cx_buff_e[is_next_band][i] = tmp_e;
2066 316108 : move16();
2067 : }
2068 : ELSE
2069 : {
2070 221840 : pCx[i] = real_part_fx;
2071 221840 : move32();
2072 221840 : cx_buff_e[is_next_band][i] = tmp_cx_e;
2073 221840 : move16();
2074 : }
2075 : }
2076 : }
2077 :
2078 67263 : max_e = cx_buff_e[0][0];
2079 67263 : move16();
2080 :
2081 : /* Cx for transport channels */
2082 201789 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
2083 : {
2084 679430 : FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
2085 : {
2086 :
2087 544904 : IF( LT_16( max_e, cx_buff_e[is_next_band][i] ) )
2088 : {
2089 46959 : max_e = cx_buff_e[is_next_band][i];
2090 : }
2091 : }
2092 : }
2093 : /* Cx for transport channels */
2094 201789 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
2095 : {
2096 679430 : FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ )
2097 : {
2098 544904 : if ( is_next_band == 0 )
2099 : {
2100 272452 : cx_fx[i] = L_shr( cx_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
2101 : }
2102 : else
2103 : {
2104 272452 : cx_next_band_fx[i] = L_shr( cx_next_band_fx[i], sub( max_e, cx_buff_e[is_next_band][i] ) );
2105 : }
2106 544904 : move32();
2107 : }
2108 : }
2109 67263 : cx_e = max_e;
2110 67263 : move16();
2111 :
2112 :
2113 : /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/
2114 :
2115 67263 : test();
2116 67263 : test();
2117 67263 : IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) )
2118 : {
2119 98 : Word16 len = imult1616( nchan_transport, nchan_transport );
2120 98 : Word16 sc = s_min( getScaleFactor32( cx_fx, len ), getScaleFactor32( cx_next_band_fx, len ) );
2121 98 : IF( EQ_16( sc, 0 ) )
2122 : {
2123 98 : Scale_sig32( cx_fx, len, -Q1 ); // add one bit head room
2124 98 : Scale_sig32( cx_next_band_fx, len, -Q1 ); // add one bit head room
2125 98 : cx_e = add( cx_e, Q1 );
2126 98 : cx_next_band_e = add( cx_e, Q1 );
2127 : }
2128 98 : v_add_fx( cx_fx, cx_next_band_fx, cx_fx, len );
2129 98 : Copy32( cx_fx, cx_next_band_fx, len );
2130 : }
2131 :
2132 201789 : FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
2133 : {
2134 134526 : test();
2135 134526 : IF( is_next_band && skip_next_band )
2136 : {
2137 1739 : CONTINUE;
2138 : }
2139 :
2140 132787 : IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
2141 : {
2142 132787 : IF( is_next_band )
2143 : {
2144 :
2145 65524 : ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_next_band_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
2146 : }
2147 : ELSE
2148 : {
2149 :
2150 67263 : ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
2151 : }
2152 : }
2153 : }
2154 : }
2155 10229 : }
2156 : #endif
2157 :
2158 : /*-------------------------------------------------------------------------
2159 : * ivas_param_mc_dec()
2160 : *
2161 : * Parametric MC decoding process
2162 : *------------------------------------------------------------------------*/
2163 :
2164 10260 : void ivas_param_mc_dec_render_fx(
2165 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
2166 : const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */
2167 : UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */
2168 : UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */
2169 : Word32 *output_f_fx[], /* o : rendered time signal Q11*/
2170 : Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] )
2171 : {
2172 : PARAM_MC_DEC_HANDLE hParamMC;
2173 : Word16 i, ch;
2174 : Word16 subframe_idx;
2175 : Word16 slot_idx, slot_idx_start, slot_idx_start_cldfb_synth, first_sf, last_sf, slots_to_render;
2176 : Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb;
2177 : Word16 nchan_out_cov;
2178 :
2179 : /*CLDFB*/
2180 : Word32 Cldfb_RealBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2181 : Word32 Cldfb_ImagBuffer_fx[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2182 : Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2183 : Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
2184 : Word32 *p_output_f_fx[MAX_OUTPUT_CHANNELS];
2185 174420 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2186 : {
2187 164160 : p_output_f_fx[i] = output_f_fx[i]; // Q11
2188 : }
2189 : /*Decorrelator*/
2190 : Word32 onset_filter_fx[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; // Q31
2191 :
2192 : /* format converter */
2193 : Word16 channel_active[MAX_OUTPUT_CHANNELS];
2194 : UWord16 nband_synth;
2195 : UWord32 output_Fs;
2196 10260 : Word16 tmp_q = 0;
2197 10260 : move16();
2198 :
2199 10260 : hParamMC = st_ivas->hParamMC;
2200 10260 : assert( hParamMC );
2201 :
2202 10260 : push_wmops( "param_mc_dec_render" );
2203 :
2204 10260 : set16_fx( channel_active, 0, MAX_CICP_CHANNELS );
2205 10260 : nchan_transport = st_ivas->nchan_transport;
2206 10260 : move16();
2207 10260 : nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
2208 10260 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
2209 10260 : move32();
2210 :
2211 10260 : test();
2212 10260 : test();
2213 10260 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2214 : {
2215 8270 : nchan_out_cldfb = BINAURAL_CHANNELS;
2216 8270 : set16_fx( channel_active, 1, nchan_out_cldfb );
2217 8270 : nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
2218 : }
2219 1990 : ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
2220 : {
2221 340 : nchan_out_cov = nchan_out_transport;
2222 340 : move16();
2223 340 : nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
2224 : }
2225 1650 : ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
2226 : {
2227 150 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
2228 150 : nchan_out_cldfb = nchan_out_cov;
2229 150 : move16();
2230 150 : set16_fx( channel_active, 1, nchan_out_cov );
2231 : }
2232 : ELSE
2233 : {
2234 1500 : nchan_out_cov = nchan_out_transport;
2235 1500 : move16();
2236 1500 : nchan_out_cldfb = nchan_out_transport;
2237 1500 : move16();
2238 1500 : set16_fx( channel_active, 1, nchan_out_cov );
2239 : }
2240 :
2241 : /* set everything to zero that will not be decoded */
2242 10260 : nband_synth = hParamMC->band_grouping[hParamMC->num_param_bands_synth];
2243 10260 : move16();
2244 174420 : FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
2245 : {
2246 820800 : FOR( slot_idx = 0; slot_idx < JBM_CLDFB_SLOTS_IN_SUBFRAME; slot_idx++ )
2247 : {
2248 656640 : set32_fx( &( Cldfb_RealBuffer_fx[ch][slot_idx][0] ), 0, CLDFB_NO_CHANNELS_MAX );
2249 656640 : set32_fx( &( Cldfb_ImagBuffer_fx[ch][slot_idx][0] ), 0, CLDFB_NO_CHANNELS_MAX );
2250 : }
2251 : }
2252 :
2253 : /* loop FOR synthesis, assume we always have to render in multiples of 5ms subframes with spills */
2254 : /*slots_to_render = min(sub(hParamMC->num_slots, hParamMC->slots_rendered), nSamplesAsked / NS2SA(output_Fs, CLDFB_SLOT_NS));
2255 : *nSamplesRendered = slots_to_render * NS2SA(output_Fs, CLDFB_SLOT_NS);*/
2256 : Word16 temp_e;
2257 10260 : Word16 temp = BASOP_Util_Divide1616_Scale( nSamplesAsked, NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ), &temp_e );
2258 10260 : temp = shr( temp, sub( 15, temp_e ) );
2259 10260 : slots_to_render = s_min( sub( hParamMC->num_slots, hParamMC->slots_rendered ), temp );
2260 10260 : *nSamplesRendered = imult1616( slots_to_render, NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ) );
2261 10260 : move16();
2262 : Word16 j, k;
2263 10260 : first_sf = hParamMC->subframes_rendered;
2264 10260 : move16();
2265 10260 : last_sf = first_sf;
2266 10260 : move16();
2267 51207 : WHILE( slots_to_render > 0 )
2268 : {
2269 40947 : slots_to_render = sub( slots_to_render, hParamMC->subframe_nbslots[last_sf] );
2270 40947 : last_sf = add( last_sf, 1 );
2271 : }
2272 10260 : IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2273 : {
2274 1800 : FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
2275 : {
2276 1440 : slots_to_render = add( slots_to_render, hParamMC->subframe_nbslots[subframe_idx] );
2277 : }
2278 : }
2279 10260 : slot_idx_start = hParamMC->slots_rendered;
2280 10260 : move16();
2281 10260 : slot_idx_start_cldfb_synth = 0;
2282 10260 : move16();
2283 :
2284 145687 : FOR( j = 0; j < st_ivas->hParamMC->hMetadataPMC->nbands_coded; j++ )
2285 : {
2286 135427 : Flag is_zero = is_zero_arr( hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[j], hParamMC->h_output_synthesis_cov_state.mixing_matrix_len );
2287 : {
2288 135427 : if ( is_zero != 0 )
2289 : {
2290 2191 : hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[j] = 0;
2291 2191 : move16();
2292 : }
2293 : }
2294 135427 : IF( LT_16( st_ivas->hParamMC->band_grouping[j], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
2295 : {
2296 107217 : is_zero = is_zero_arr( hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[j], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len );
2297 107217 : if ( is_zero != 0 )
2298 : {
2299 52 : hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[j] = 0;
2300 52 : move16();
2301 : }
2302 : }
2303 : }
2304 51207 : FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
2305 : {
2306 204614 : FOR( slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; ( slot_idx++, hParamMC->slots_rendered++ ) )
2307 : {
2308 163667 : IF( hParamMC->max_band_decorr > 0 )
2309 : {
2310 : /*-----------------------------------------------------------------*
2311 : * protoype signal computation
2312 : *-----------------------------------------------------------------*/
2313 163667 : param_mc_protoSignalComputation_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
2314 163667 : &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
2315 163667 : hParamMC->proto_frame_f_fx, hParamMC->diff_proto_info,
2316 163667 : hParamMC->num_freq_bands, hParamMC->Cldfb_RealBuffer_tc_e, &hParamMC->proto_frame_f_fx_q );
2317 : /*-----------------------------------------------------------------*
2318 : * frequency domain decorrelation
2319 : *-----------------------------------------------------------------*/
2320 : /* decorrelate prototype frame */
2321 :
2322 163667 : ivas_dirac_dec_decorr_process_fx( hParamMC->num_freq_bands,
2323 163667 : hParamMC->num_outputs_diff,
2324 163667 : hParamMC->diff_proto_info->num_protos_diff,
2325 : DIRAC_SYNTHESIS_COV_MC_LS,
2326 : nchan_transport,
2327 163667 : hParamMC->proto_frame_f_fx,
2328 163667 : hParamMC->proto_frame_f_fx_q,
2329 163667 : hParamMC->diff_proto_info->num_protos_diff,
2330 163667 : hParamMC->diff_proto_info->proto_index_diff,
2331 : hParamMC->proto_frame_dec_f_fx, // output
2332 : &tmp_q,
2333 : onset_filter_fx,
2334 : hParamMC->h_freq_domain_decorr_ap_params,
2335 : hParamMC->h_freq_domain_decorr_ap_state );
2336 :
2337 : /* copy decorrelated frame directly to output CLDFB buffer, acts also as intermediate */
2338 : /* memory FOR the decorrelated signal */
2339 163667 : ivas_param_mc_dec_copy_diffuse_proto( hParamMC, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nchan_out_cov, slot_idx ); // Returns Cldfb buffers in Q11(tmp_q)
2340 :
2341 1163275 : FOR( k = 0; k < nchan_out_cov; k++ )
2342 : {
2343 20991768 : FOR( Word16 l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++ )
2344 : {
2345 19992160 : Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6
2346 19992160 : move32();
2347 19992160 : Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); // Q11(tmp_q) -> Q6
2348 19992160 : move32();
2349 : }
2350 : }
2351 : }
2352 :
2353 : /*-----------------------------------------------------------------*
2354 : * output synthesis
2355 : *-----------------------------------------------------------------*/
2356 327334 : ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx(
2357 163667 : &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands],
2358 163667 : &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ),
2359 : nchan_transport, nchan_out_cov, hParamMC );
2360 :
2361 163667 : test();
2362 163667 : IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
2363 : {
2364 131827 : test();
2365 131827 : IF( st_ivas->hCombinedOrientationData && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
2366 51523 : {
2367 : Word16 Q_Cldfb_ImagBuffer, Q_Cldfb_RealBuffer;
2368 51523 : Q_Cldfb_ImagBuffer = Q6 - 5; /*max value =MAX_INTERN_CHANNELS(=16)*Cldfb_ImagBuffer_fx*/
2369 51523 : move16();
2370 51523 : Q_Cldfb_RealBuffer = Q6 - 5;
2371 51523 : move16();
2372 875891 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2373 : {
2374 4121840 : FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
2375 : {
2376 3297472 : Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_ImagBuffer, Q6 ) ); // Q1
2377 3297472 : Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q_Cldfb_RealBuffer, Q6 ) ); // Q1
2378 : }
2379 : }
2380 51523 : ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hParamMC->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, nband_synth, GAIN_LFE_FX );
2381 875891 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2382 : {
2383 4121840 : FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
2384 : {
2385 3297472 : Scale_sig32( Cldfb_RealBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_ImagBuffer ) ); // Q6
2386 3297472 : Scale_sig32( Cldfb_ImagBuffer_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_Cldfb_RealBuffer ) ); // Q6
2387 : }
2388 : }
2389 : }
2390 : ELSE
2391 : {
2392 : /* remove LFE */
2393 : UWord16 idx_out;
2394 : UWord16 idx_lfe;
2395 : IVAS_OUTPUT_SETUP hLsSetup;
2396 :
2397 80304 : hLsSetup = st_ivas->hTransSetup;
2398 : /* If LFE should be rendered, add it to other channels before removing */
2399 80304 : IF( st_ivas->hBinRenderer->render_lfe )
2400 : {
2401 80304 : Word16 tmp_exp = 0;
2402 80304 : move16();
2403 80304 : Word16 tmp = BASOP_Util_Divide1616_Scale( GAIN_LFE_FX, hLsSetup.nchan_out_woLFE, &tmp_exp );
2404 80304 : tmp_exp = add( tmp_exp, ( 1 - 15 ) );
2405 160608 : FOR( idx_lfe = 0; idx_lfe < hLsSetup.num_lfe; idx_lfe++ )
2406 : {
2407 : /* Copy just the first band of LFE*/
2408 80304 : v_multc_fixed_16( Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], tmp, Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1 );
2409 80304 : v_multc_fixed_16( Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], tmp, Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1 );
2410 :
2411 80304 : Scale_sig32( Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1, tmp_exp );
2412 80304 : Scale_sig32( Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1, tmp_exp );
2413 565008 : FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
2414 : {
2415 484704 : IF( hLsSetup.index_lfe[idx_lfe] != ch )
2416 : {
2417 404400 : v_add_fixed_no_hdrm( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_RealBuffer_fx[ch][slot_idx], 1 );
2418 404400 : v_add_fixed_no_hdrm( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], 1 );
2419 : }
2420 : }
2421 : }
2422 : }
2423 :
2424 80304 : idx_out = 0;
2425 80304 : move16();
2426 80304 : idx_lfe = 0;
2427 80304 : move16();
2428 :
2429 565008 : FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
2430 : {
2431 484704 : test();
2432 484704 : IF( ( hLsSetup.num_lfe > 0 ) && EQ_16( hLsSetup.index_lfe[idx_lfe], ch ) )
2433 : {
2434 80304 : IF( LT_16( idx_lfe, ( sub( hLsSetup.num_lfe, 1 ) ) ) )
2435 : {
2436 0 : idx_lfe = add( idx_lfe, 1 );
2437 : }
2438 : }
2439 404400 : ELSE IF( NE_16( ch, idx_out ) )
2440 : {
2441 163488 : Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[idx_out][slot_idx], nband_synth );
2442 163488 : Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[idx_out][slot_idx], nband_synth );
2443 163488 : idx_out = add( idx_out, 1 );
2444 : }
2445 : ELSE
2446 : {
2447 240912 : idx_out = add( idx_out, 1 );
2448 : }
2449 : }
2450 : }
2451 : }
2452 : }
2453 :
2454 40947 : test();
2455 40947 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2456 32987 : {
2457 32987 : Word16 input_q = 6;
2458 32987 : move16();
2459 :
2460 32987 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
2461 : {
2462 0 : IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
2463 : {
2464 0 : FOR( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
2465 : {
2466 0 : FOR( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
2467 : {
2468 0 : Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
2469 0 : Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
2470 : }
2471 : }
2472 0 : st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
2473 0 : move16();
2474 : }
2475 : }
2476 :
2477 : /* Implement binaural rendering */
2478 : /*Binaural output in Q6 format*/
2479 32987 : ivas_binRenderer_fx( st_ivas->hBinRenderer,
2480 0 : ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
2481 : st_ivas->hCombinedOrientationData,
2482 32987 : hParamMC->subframe_nbslots[subframe_idx],
2483 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
2484 : Cldfb_RealBuffer_fx,
2485 : Cldfb_ImagBuffer_fx, &input_q );
2486 :
2487 560779 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2488 : {
2489 2638960 : FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
2490 : {
2491 128781248 : FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
2492 : {
2493 126670080 : Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
2494 126670080 : Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
2495 : }
2496 : }
2497 : }
2498 :
2499 : Word16 pos_idx;
2500 32987 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
2501 : {
2502 0 : FOR( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
2503 : {
2504 0 : FOR( slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; slot_idx++ )
2505 : {
2506 0 : FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
2507 : {
2508 0 : Copy32( Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
2509 0 : Copy32( Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_idx_start, slot_idx )], hParamMC->num_freq_bands );
2510 : }
2511 : }
2512 : }
2513 : }
2514 : /* update combined orientation access index */
2515 32987 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx] );
2516 : }
2517 7960 : ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
2518 : {
2519 : /* format conversion*/
2520 1360 : ivas_lssetupconversion_process_param_mc_fx( st_ivas, hParamMC->subframe_nbslots[subframe_idx], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, channel_active );
2521 : }
2522 :
2523 :
2524 : /* CLDFB synthesis */
2525 164761 : FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
2526 : {
2527 : Word32 *RealBuffer_fx[16];
2528 : Word32 *ImagBuffer_fx[16];
2529 :
2530 123814 : IF( channel_active[ch] )
2531 : {
2532 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands FOR 48kHz */
2533 578028 : FOR( i = 0; i < hParamMC->subframe_nbslots[subframe_idx]; i++ )
2534 : {
2535 462374 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2536 : {
2537 263654 : RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[0][ch][i]; // Q6
2538 263654 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[0][ch][i]; // Q6
2539 : }
2540 : ELSE
2541 : {
2542 198720 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; // Q6
2543 198720 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; // Q6
2544 : }
2545 : }
2546 :
2547 115654 : Word16 len = add( imult1616( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
2548 115654 : scale_sig32( output_f_fx[ch], len, 5 - 11 );
2549 115654 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ),
2550 115654 : imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), 0, 0, st_ivas->cldfbSynDec[ch] );
2551 :
2552 115654 : scale_sig32( output_f_fx[ch], len, 11 - 5 ); // Q11
2553 : }
2554 : ELSE
2555 : {
2556 8160 : set32_fx( &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
2557 : }
2558 : }
2559 40947 : slot_idx_start = add( slot_idx_start, hParamMC->subframe_nbslots[subframe_idx] );
2560 40947 : slot_idx_start_cldfb_synth = add( slot_idx_start_cldfb_synth, hParamMC->subframe_nbslots[subframe_idx] );
2561 : }
2562 10260 : IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2563 : {
2564 360 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_f_fx, p_output_f_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
2565 : }
2566 :
2567 : /* update */
2568 :
2569 10260 : IF( EQ_16( hParamMC->slots_rendered, hParamMC->num_slots ) )
2570 : {
2571 10229 : hParamMC->hMetadataPMC->last_coded_bwidth = hParamMC->hMetadataPMC->coded_bwidth;
2572 10229 : move16();
2573 10229 : param_mc_update_mixing_matrices_fx( hParamMC, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_transport, nchan_out_cov );
2574 : }
2575 :
2576 :
2577 10260 : hParamMC->subframes_rendered = last_sf;
2578 10260 : move16();
2579 10260 : *nSamplesAvailableNext = imult1616( sub( hParamMC->num_slots, hParamMC->slots_rendered ), NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ) );
2580 10260 : move16();
2581 :
2582 174420 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2583 : {
2584 164160 : channel_active_fx[i] = channel_active[i];
2585 164160 : move16();
2586 : }
2587 10260 : pop_wmops();
2588 :
2589 10260 : return;
2590 : }
2591 :
2592 : /*-------------------------------------------------------------------------
2593 : * param_mc_dec_init()
2594 : *
2595 : * Parametric MC decoding initialization
2596 : *------------------------------------------------------------------------*/
2597 :
2598 279 : static void ivas_param_mc_dec_init_fx(
2599 : PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */
2600 : const Word16 nchan_transport, /* i : number of input (transport) channels */
2601 : const Word16 nchan_cov ) /* i : number of cov synthesis channels */
2602 : {
2603 : Word16 k;
2604 : UWord16 max_param_band_residual;
2605 : Word16 len;
2606 :
2607 : /*-----------------------------------------------------------------*
2608 : * init sub-modules
2609 : *-----------------------------------------------------------------*/
2610 :
2611 : /* decorrelation */
2612 279 : IF( hParamMC->max_band_decorr > 0 )
2613 : {
2614 277 : len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr );
2615 :
2616 : /* init onsetDetectionPower */
2617 277 : set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
2618 277 : set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
2619 277 : hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
2620 277 : move16();
2621 : }
2622 :
2623 279 : max_param_band_residual = 0;
2624 279 : move16();
2625 :
2626 : /* output synthesis */
2627 1006 : FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
2628 : {
2629 1006 : IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
2630 : {
2631 279 : max_param_band_residual = k;
2632 279 : move16();
2633 279 : BREAK;
2634 : }
2635 : }
2636 :
2637 279 : ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual );
2638 :
2639 : /*-----------------------------------------------------------------*
2640 : * init proto frames
2641 : *-----------------------------------------------------------------*/
2642 :
2643 279 : IF( hParamMC->max_band_decorr > 0 )
2644 : {
2645 277 : set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
2646 277 : set32_fx( hParamMC->proto_frame_dec_f_fx, 0, shl( imult1616( nchan_cov, hParamMC->num_freq_bands ), 1 ) );
2647 : }
2648 :
2649 279 : return;
2650 : }
2651 :
2652 :
2653 : /*-------------------------------------------------------------------------
2654 : * Local functions
2655 : *-------------------------------------------------------------------------*/
2656 :
2657 :
2658 : /*-------------------------------------------------------------------------
2659 : * ivas_param_mc_dec_compute_diffuse_proto()
2660 : *
2661 : * Compute prototypes for decorrelation
2662 : *------------------------------------------------------------------------*/
2663 :
2664 163667 : static void param_mc_protoSignalComputation_fx(
2665 : Word32 *RealBuffer_fx, /* i : CLDFB samples of the transport channels (real part) */
2666 : Word32 *ImagBuffer_fx, /* i : CLDFB samples of the transport channels (imaginary part) */
2667 : Word32 *proto_frame_f_fx, /* o : interleaved complex prototype CLDFB samples */
2668 : const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i : prototype generation information */
2669 : const Word16 num_freq_bands, /* i : number of frequency bands for the prototypes */
2670 : const Word16 Cldfb_Real_Imag_exp, /*i: Exponent of real and imag buffers */
2671 : Word16 *proto_frame_f_fx_q )
2672 : {
2673 : Word16 band;
2674 : Word16 proto_ch_idx, source_ch_cnt;
2675 :
2676 : Word32 *p_proto_frame_fx;
2677 : Word32 *p_real_buffer_fx; // Q12
2678 : Word32 *p_imag_buffer_fx; // Q12
2679 :
2680 163667 : set32_fx( proto_frame_f_fx, 0, shl( imult1616( num_freq_bands, diff_proto_info->num_protos_diff ), 1 ) );
2681 :
2682 :
2683 659468 : FOR( proto_ch_idx = 0; proto_ch_idx < diff_proto_info->num_protos_diff; proto_ch_idx++ )
2684 : {
2685 495801 : Word16 num_source_ch = diff_proto_info->num_source_chan_diff[proto_ch_idx];
2686 495801 : move16();
2687 :
2688 1153829 : FOR( source_ch_cnt = 0; source_ch_cnt < num_source_ch; source_ch_cnt++ )
2689 : {
2690 :
2691 658028 : Word32 fac_fx = diff_proto_info->proto_fac_fx[proto_ch_idx][source_ch_cnt];
2692 658028 : move32();
2693 :
2694 658028 : Word16 source_ch_idx = diff_proto_info->source_chan_idx[proto_ch_idx][source_ch_cnt];
2695 658028 : move16();
2696 :
2697 658028 : p_proto_frame_fx = &proto_frame_f_fx[shl( imult1616( proto_ch_idx, num_freq_bands ), 1 )];
2698 658028 : p_real_buffer_fx = &RealBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
2699 658028 : p_imag_buffer_fx = &ImagBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
2700 :
2701 37717068 : FOR( band = 0; band < num_freq_bands; band++ )
2702 : {
2703 :
2704 37059040 : Word32 tmp_x = L_shl( Mpy_32_32( fac_fx, ( *( p_real_buffer_fx++ ) ) ), 4 ); // Q(26 + 4 + 6 - 31) :: Q5
2705 :
2706 37059040 : *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
2707 37059040 : move32();
2708 37059040 : p_proto_frame_fx++;
2709 :
2710 37059040 : tmp_x = L_shl( Mpy_32_32( fac_fx, ( *( p_imag_buffer_fx++ ) ) ), 4 ); // Q(26 + 4 + 6 - 31) :: Q5
2711 :
2712 37059040 : *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
2713 37059040 : move32();
2714 37059040 : p_proto_frame_fx++;
2715 : }
2716 658028 : *proto_frame_f_fx_q = sub( 30, Cldfb_Real_Imag_exp );
2717 658028 : move16();
2718 : }
2719 : }
2720 :
2721 163667 : return;
2722 : }
2723 :
2724 : /*-------------------------------------------------------------------------
2725 : * ivas_param_mc_dec_compute_diffuse_proto()
2726 : *
2727 : * Transfer decorrelated signals back from the decorrelator buffer to
2728 : * the buffers used in the final synthesis
2729 : *------------------------------------------------------------------------*/
2730 :
2731 163667 : static void ivas_param_mc_dec_copy_diffuse_proto(
2732 : PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
2733 : Word32 Cldfb_buffer_real_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (real part) */
2734 : Word32 Cldfb_buffer_imag_fx[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : CLDFB buffer used in the final synthesis (imaginary part) */
2735 : const Word16 nY, /* i : number of decorrelated channels */
2736 : const Word16 slot_idx /* i : current time slot index */
2737 : )
2738 : {
2739 : Word16 k, l;
2740 : Word16 num_freq_bands, num_freq_bands_diff;
2741 : Word32 *p_proto_diff_fx;
2742 163667 : num_freq_bands = hParamMC->num_freq_bands;
2743 163667 : move16();
2744 163667 : num_freq_bands_diff = hParamMC->h_output_synthesis_params.max_band_decorr;
2745 163667 : move16();
2746 :
2747 1163275 : FOR( k = 0; k < nY; k++ )
2748 : {
2749 999608 : p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); // Q11
2750 :
2751 20991768 : FOR( l = 0; l < num_freq_bands_diff; l++ )
2752 : {
2753 19992160 : Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
2754 19992160 : move32();
2755 19992160 : Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
2756 19992160 : move32();
2757 : }
2758 : }
2759 :
2760 163667 : return;
2761 : }
2762 :
2763 : /*-------------------------------------------------------------------------
2764 : * ivas_param_mc_bin2dec()
2765 : *
2766 : * decode a number of bits to an integer
2767 : *------------------------------------------------------------------------*/
2768 : /* r : decoded integer */
2769 12366 : static Word16 ivas_param_mc_bin2dec_fx(
2770 : UWord16 bits[PARAM_MC_MAX_BITS], /* i : bit buffer */
2771 : const Word16 N /* i : number of bits to decode */
2772 : )
2773 : {
2774 : Word16 i;
2775 : Word16 out;
2776 :
2777 12366 : assert( N <= 16 );
2778 12366 : out = 0;
2779 12366 : move16();
2780 49464 : FOR( i = 0; i < N; i++ )
2781 : {
2782 37098 : out = add( out, shl( bits[i], sub( sub( N, 1 ), i ) ) );
2783 : }
2784 :
2785 12366 : return out;
2786 : }
2787 :
2788 : /*-------------------------------------------------------------------------
2789 : * ivas_param_mc_uniform_decoder()
2790 : *
2791 : * decode a uniformily coded sequence of float values
2792 : *------------------------------------------------------------------------*/
2793 475 : static Word16 ivas_param_mc_uniform_decoder_fx(
2794 : Word16 *seq, /* o : decoded sequence of float values hParamCodingInfo -> Q-quant*/
2795 : const Word16 sz_seq, /* i : number of values to decode */
2796 : const Word16 *alphabet, /* i : codebook hParamCodingInfo -> Q-quant*/
2797 : const Word16 N, /* i : number of bits per coded index */
2798 : UWord16 bit_buffer[PARAM_MC_MAX_BITS] /* i : bit buffer to decode */
2799 : )
2800 : {
2801 : Word16 i;
2802 : Word16 idx;
2803 : Word16 n_bits;
2804 :
2805 475 : n_bits = 0;
2806 475 : move16();
2807 475 : assert( N * sz_seq < PARAM_MC_MAX_BITS );
2808 :
2809 12841 : FOR( i = 0; i < sz_seq; ++i )
2810 : {
2811 12366 : idx = ivas_param_mc_bin2dec_fx( &bit_buffer[i * N], N );
2812 12366 : seq[i] = alphabet[idx];
2813 12366 : move16();
2814 : }
2815 :
2816 475 : n_bits = imult1616( N, sz_seq );
2817 :
2818 475 : return n_bits;
2819 : }
2820 :
2821 :
2822 : /*-------------------------------------------------------------------------
2823 : * ivas_param_mc_range_decoder_LC()
2824 : *
2825 : * decode a sequency of inidices coded with a range coder
2826 : *------------------------------------------------------------------------*/
2827 19957 : static Word16 ivas_param_mc_range_decoder_LC_fx(
2828 : UWord16 *bit_buffer, /* i : bit buffer to read from */
2829 : Word16 *x, /* o : decoded indices */
2830 : Word16 *BER_detect, /* o : flag for indicating a bit error */
2831 : const Word16 sz_seq, /* i : size of the sequence to be decoded */
2832 : const Word16 sz_alphabet, /* i : size of the alphabet */
2833 : const UWord16 *cft, /* i : cumulative frequency table */
2834 : const UWord16 *sft, /* i : symbol frequency table */
2835 : const Word16 tot_shift, /* i : total frequency as a power of 2 */
2836 : const Word16 nbbits /* i : maximum bit budget */
2837 : )
2838 : {
2839 : RangeUniDecState rc_st_dec; /* State of the range decoder */
2840 : Word16 cur_bit_pos;
2841 : Word16 k;
2842 : Word16 r;
2843 :
2844 : /* Start Decoding */
2845 : /* Initialize range decoder */
2846 19957 : cur_bit_pos = 0;
2847 19957 : move16();
2848 19957 : rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, sub( nbbits, 32 ) ); /* (nbbits + 30) entries are read by the decoder */
2849 :
2850 : /* Main Loop through the indices */
2851 636423 : FOR( k = 0; k < sz_seq; k++ )
2852 : {
2853 616466 : r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
2854 : /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */
2855 :
2856 : /* Update bitstream pointer */
2857 616466 : cur_bit_pos = rc_uni_dec_virtual_finish_fx( &rc_st_dec );
2858 :
2859 : /* Confirm that there is no overflow */
2860 616466 : IF( GT_16( cur_bit_pos, nbbits ) )
2861 : {
2862 0 : *BER_detect = s_or( *BER_detect, 1 );
2863 0 : move16();
2864 : }
2865 :
2866 616466 : x[k] = r;
2867 616466 : move16();
2868 : }
2869 :
2870 : /* We don't need to finish because virtual_finish() already does the same */
2871 : /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/
2872 :
2873 : /* Check for bitstream errors */
2874 19957 : IF( rc_st_dec.bit_error_detected != 0 )
2875 : {
2876 0 : *BER_detect = s_or( *BER_detect, 1 );
2877 0 : move16();
2878 : }
2879 :
2880 19957 : return cur_bit_pos;
2881 : }
2882 :
2883 : /*-------------------------------------------------------------------------
2884 : * param_mc_compute_interpolator()
2885 : *
2886 : * compute the interpolator used in the final synthesis
2887 : *------------------------------------------------------------------------*/
2888 :
2889 10570 : static void ivas_param_mc_dec_compute_interpolator_fx(
2890 : const UWord16 bAttackPresent, /* i : flag indicating if we have a transient in the current frame */
2891 : const UWord16 attackPos, /* i : position of the transient */
2892 : const UWord16 interp_length, /* i : number of interpolation values to be calculated */
2893 : Word16 *interpolator /* o : interpolator */
2894 : )
2895 : {
2896 : Word16 idx;
2897 :
2898 10570 : IF( bAttackPresent )
2899 : {
2900 3752 : FOR( idx = 0; idx < attackPos * 2; idx++ )
2901 : {
2902 3268 : interpolator[idx] = 0;
2903 3268 : move16();
2904 : }
2905 4960 : FOR( ; idx < interp_length; idx++ )
2906 : {
2907 4476 : interpolator[idx] = 32767; /* 1.0f Q15 */
2908 4476 : move16();
2909 : }
2910 : }
2911 : ELSE
2912 : {
2913 10086 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator );
2914 : }
2915 :
2916 10570 : return;
2917 : }
2918 :
2919 :
2920 : /*-------------------------------------------------------------------------
2921 : * remove_lfe_from_cy()
2922 : *
2923 : * remove all LFE related values from a covariance matrix
2924 : *------------------------------------------------------------------------*/
2925 :
2926 131737 : static void remove_lfe_from_cy_fx(
2927 : const Word16 nY, /* i : dimension of the covariance matrix */
2928 : Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP], /* i : LFE index */
2929 : Word16 num_lfe, /* i : number of LFEs */
2930 : Word32 *cy, /* i : covariance matrix */
2931 : Word32 *cy_woLFE /* o : covariance matrix with LFE removed */
2932 : )
2933 : {
2934 : Word16 ch_idx1, ch_idx2;
2935 : Word16 lfe_idx1, lfe_idx2;
2936 : Word32 *ptrCy;
2937 : Word32 *ptrCy_out;
2938 :
2939 131737 : ptrCy = cy;
2940 131737 : ptrCy_out = cy_woLFE;
2941 :
2942 395211 : FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ )
2943 : {
2944 935759 : FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
2945 : {
2946 2016855 : FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ )
2947 : {
2948 4819915 : FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
2949 : {
2950 3475345 : *( ptrCy_out++ ) = *( ptrCy++ );
2951 3475345 : move32();
2952 : }
2953 1344570 : ptrCy++;
2954 : }
2955 672285 : ptrCy--;
2956 : }
2957 263474 : ptrCy += nY;
2958 : }
2959 :
2960 131737 : return;
2961 : }
2962 :
2963 :
2964 : /*-------------------------------------------------------------------------
2965 : * ivas_param_mc_get_mixing_matrices()
2966 : *
2967 : * calculate the direct and residual mixing matrices
2968 : * using the covariance method
2969 : *------------------------------------------------------------------------*/
2970 :
2971 132787 : static void ivas_param_mc_get_mixing_matrices_fx(
2972 : PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
2973 : IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
2974 : Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands Q(31 - Cx_in_e)*/
2975 : Word16 Cx_in_e,
2976 : const Word16 param_band_idx, /* i : parameter band index */
2977 : Word32 *mixing_matrix_fx[], // Q(31 - mixing_matrix_e)
2978 : Word16 *mixing_matrix_e,
2979 : Word32 *mixing_matrix_res_fx[], // Q(31 - mixing_matrix_res_e)
2980 : Word16 *mixing_matrix_res_e,
2981 : const Word16 nY_intern, /* i : number of channels in the transported format */
2982 : const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */
2983 : const Word16 nX, /* i : number of transport channels */
2984 : const Word16 nY_cov /* i : number of covariance synthesis output channels */
2985 : )
2986 : {
2987 132787 : Word16 matSize = MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS;
2988 : Word16 nY_band;
2989 : Word16 num_lfe_bands;
2990 : Word16 brange[2];
2991 : UWord16 i;
2992 : Word16 ch_idx1, ch_idx2, lfe_idx1, lfe_idx2;
2993 : Word16 remove_lfe;
2994 : Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP];
2995 :
2996 : Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
2997 : Word32 Cy_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
2998 :
2999 : Word32 Cy_full_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
3000 :
3001 : Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cr_e)
3002 : Word16 Cr_e;
3003 : Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Cy_diag_buff_e)
3004 : Word16 Cy_diag_buff_e[MAX_OUTPUT_CHANNELS];
3005 : Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - mixing_matrix_local_e)
3006 132787 : Word16 Cy_diag_e = 0, mixing_matrix_local_e = 0;
3007 : Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cproto_e)
3008 : Word16 Cproto_e;
3009 : Word32 *proto_matrix_ptr_fx; // Q(31 - proto_matrix_ptr_e)
3010 : Word32 *Cx_state_fx; // Q(31 - Cx_state_e)
3011 : Word32 *Cx_old_state_fx;
3012 : Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cy_state_e)
3013 : Word32 *Cy_old_state_fx;
3014 : Word16 Cx_state_e;
3015 : Word16 Cy_state_e;
3016 : Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mixing_matrix_res_local_e)
3017 : Word16 mixing_matrix_res_local_e;
3018 : Word32 L_tmp;
3019 : Word16 tmp_e, tmp;
3020 :
3021 132787 : Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
3022 132787 : move16();
3023 : Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; // Q(31 - proto_matrix_noLFE_e)
3024 :
3025 : Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
3026 :
3027 : Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; // Q(31 - Cproto_diag_e)
3028 : Word16 mat_mult_buffer1_e, proto_matrix_ptr_e, Cproto_diag_e;
3029 :
3030 : Word32 *ptrMM_fx;
3031 : Word32 *ptrMM_out_fx;
3032 :
3033 : Word16 Cy_e, Cx_e;
3034 : Word16 Cy_full_e;
3035 132787 : Word16 new_e = 0;
3036 132787 : move16();
3037 :
3038 132787 : set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
3039 132787 : set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
3040 132787 : set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
3041 132787 : set_zero_fx( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
3042 132787 : set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
3043 132787 : Word16 proto_matrix_noLFE_e = 0;
3044 132787 : move16();
3045 :
3046 : Word32 Cx_in_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
3047 :
3048 132787 : Copy32( Cx_in_fixed, Cx_in_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
3049 :
3050 132787 : nY_band = nY_cov;
3051 132787 : move16();
3052 132787 : num_lfe_bands = 0;
3053 132787 : move16();
3054 132787 : remove_lfe = 0;
3055 132787 : move16();
3056 :
3057 132787 : set16_fx( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP );
3058 132787 : IF( hSynthesisOutputSetup->num_lfe )
3059 : {
3060 : Word32 *proto_matrix_ptr_in_fx;
3061 265574 : FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ )
3062 : {
3063 132787 : lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1];
3064 132787 : move16();
3065 : }
3066 132787 : lfe_indices[hSynthesisOutputSetup->num_lfe + 1] = nY_cov;
3067 132787 : move16();
3068 132787 : proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0];
3069 132787 : proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0];
3070 132787 : proto_matrix_noLFE_e = proto_matrix_e;
3071 132787 : move16();
3072 :
3073 132787 : set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
3074 :
3075 399721 : FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
3076 : {
3077 800802 : FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
3078 : {
3079 1904018 : FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
3080 : {
3081 1370150 : *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ );
3082 1370150 : move32();
3083 : }
3084 533868 : proto_matrix_ptr_in_fx++;
3085 : }
3086 266934 : proto_matrix_ptr_in_fx--;
3087 : }
3088 :
3089 132787 : proto_matrix_ptr_e = proto_matrix_e;
3090 132787 : move16();
3091 : }
3092 :
3093 132787 : if ( hParamMC->hMetadataPMC->lfe_on )
3094 : {
3095 13852 : num_lfe_bands = PARAM_MC_MAX_BAND_LFE;
3096 13852 : move16();
3097 : }
3098 132787 : IF( hSynthesisOutputSetup->num_lfe > 0 && param_band_idx >= num_lfe_bands )
3099 : {
3100 131737 : remove_lfe = 1;
3101 131737 : move16();
3102 131737 : nY_band = sub( nY_cov, hSynthesisOutputSetup->num_lfe );
3103 131737 : proto_matrix_ptr_fx = proto_matrix_noLFE_fx;
3104 131737 : proto_matrix_ptr_e = proto_matrix_noLFE_e;
3105 131737 : move16();
3106 : }
3107 : ELSE
3108 : {
3109 1050 : proto_matrix_ptr_fx = hParamMC->h_output_synthesis_params.proto_matrix_fx;
3110 1050 : proto_matrix_ptr_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
3111 1050 : move16();
3112 : }
3113 :
3114 132787 : brange[0] = hParamMC->band_grouping[param_band_idx];
3115 132787 : move16();
3116 132787 : brange[1] = hParamMC->band_grouping[param_band_idx + 1];
3117 132787 : move16();
3118 :
3119 132787 : Cx_state_fx = Cx_in_fx;
3120 132787 : Cx_old_state_fx = hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx];
3121 132787 : Cy_old_state_fx = hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx];
3122 :
3123 :
3124 : /* Getting mixing mtx */
3125 : /* estimate target cov from input cov and proto_matrix */
3126 :
3127 132787 : Cx_state_e = Cx_in_e;
3128 132787 : move16();
3129 132787 : matrix_product_fx( hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx );
3130 132787 : mat_mult_buffer1_e = add( hParamMC->proto_matrix_int_e, Cx_in_e );
3131 :
3132 132787 : matrix_product_fx( mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx );
3133 132787 : Cproto_e = add( mat_mult_buffer1_e, hParamMC->proto_matrix_int_e );
3134 :
3135 948409 : FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ )
3136 : {
3137 815622 : IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )], Cproto_e, 0, 0 ) < 0 )
3138 : {
3139 0 : Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )] = 0;
3140 0 : move32();
3141 : }
3142 : }
3143 :
3144 132787 : set_zero_fx( Cy_state_fx, matSize );
3145 132787 : Cy_state_e = 0;
3146 132787 : move16();
3147 :
3148 398361 : ivas_param_mc_dequantize_cov_fx( hParamMC,
3149 132787 : hParamMC->icld_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ),
3150 132787 : hParamMC->icc_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ),
3151 : param_band_idx, nY_cov,
3152 : synth_config,
3153 : nY_intern,
3154 : nX, Cx_state_fx, Cx_state_e, Cproto_fx, Cproto_e, Cy_state_fx, &Cy_state_e );
3155 :
3156 : // dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state_fx.txt");
3157 :
3158 : /* Smoothing: Sum over two buffers */
3159 132787 : IF( hParamMC->hMetadataPMC->bAttackPresent )
3160 : {
3161 : /* no smoothing on attacks */
3162 6036 : Copy32( Cx_state_fx, Cx_fx, imult1616( nX, nX ) );
3163 6036 : Copy32( Cy_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) );
3164 6036 : Cy_full_e = Cy_state_e;
3165 6036 : move16();
3166 6036 : Cx_e = Cx_state_e;
3167 6036 : move16();
3168 : }
3169 : ELSE
3170 : {
3171 : /* smoothing gains are now identical to one, simply add up */
3172 : // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov );
3173 :
3174 126751 : v_add_fixed_me( Cx_state_fx, Cx_state_e, Cx_old_state_fx, hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_fx, &Cx_e, imult1616( nX, nX ), 1 );
3175 126751 : v_add_fixed_me( Cy_state_fx, Cy_state_e, Cy_old_state_fx, hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_full_fx, &Cy_full_e, imult1616( nY_cov, nY_cov ), 1 );
3176 : }
3177 :
3178 132787 : Copy32( Cx_state_fx, Cx_old_state_fx, imult1616( nX, nX ) );
3179 :
3180 132787 : Copy32( Cy_state_fx, Cy_old_state_fx, imult1616( nY_cov, nY_cov ) );
3181 :
3182 132787 : hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = Cx_state_e;
3183 132787 : move16();
3184 132787 : hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e;
3185 132787 : move16();
3186 :
3187 132787 : FOR( i = 0; i < nX * nX; i++ )
3188 : {
3189 132787 : if ( Cx_old_state_fx[i] != 0 )
3190 : {
3191 132787 : new_e = hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx];
3192 132787 : move16();
3193 132787 : BREAK;
3194 : }
3195 : }
3196 :
3197 132787 : hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = new_e;
3198 132787 : move16();
3199 :
3200 132787 : new_e = 0;
3201 132787 : move16();
3202 :
3203 132787 : FOR( i = 0; i < nY_cov * nY_cov; i++ )
3204 : {
3205 132787 : if ( Cy_old_state_fx[i] != 0 )
3206 : {
3207 132787 : new_e = hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx];
3208 132787 : move16();
3209 132787 : BREAK;
3210 : }
3211 : }
3212 :
3213 132787 : hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = new_e;
3214 132787 : move16();
3215 :
3216 : /* remove LFE IF necessary */
3217 132787 : IF( remove_lfe )
3218 : {
3219 :
3220 131737 : Cy_e = Cy_full_e;
3221 131737 : remove_lfe_from_cy_fx( nY_cov, lfe_indices, hSynthesisOutputSetup->num_lfe, Cy_full_fx, Cy_fx );
3222 : }
3223 : ELSE
3224 : {
3225 1050 : Copy32( Cy_full_fx, Cy_fx, imult1616( nY_band, nY_band ) );
3226 1050 : Cy_e = Cy_full_e;
3227 1050 : move16();
3228 : }
3229 :
3230 132787 : matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx );
3231 132787 : mat_mult_buffer1_e = add( proto_matrix_ptr_e, Cx_e );
3232 :
3233 132787 : matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e );
3234 :
3235 : /* make sure we have no negative entries in Cproto_diag due to rounding errors */
3236 :
3237 812472 : FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ )
3238 : {
3239 679685 : if ( Cproto_diag_fx[ch_idx1] < 0 )
3240 : {
3241 0 : Cproto_diag_fx[ch_idx1] = 0;
3242 0 : move16();
3243 : }
3244 : }
3245 :
3246 :
3247 : /* Computing the mixing matrices */
3248 :
3249 : /* bands with decorr */
3250 132787 : IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
3251 : {
3252 106849 : computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 0, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e );
3253 : /* Compute mixing matrix FOR residual */
3254 106849 : computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e );
3255 :
3256 106849 : IF( NE_16( mixing_matrix_res_local_e, mixing_matrix_local_e ) )
3257 : {
3258 64391 : tmp = getScaleFactor32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
3259 64391 : scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, tmp );
3260 64391 : mixing_matrix_local_e = sub( mixing_matrix_local_e, tmp );
3261 :
3262 64391 : tmp = getScaleFactor32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
3263 64391 : scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, tmp );
3264 64391 : mixing_matrix_res_local_e = sub( mixing_matrix_res_local_e, tmp );
3265 :
3266 64391 : scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, sub( mixing_matrix_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) );
3267 64391 : scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, sub( mixing_matrix_res_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) );
3268 :
3269 64391 : mixing_matrix_res_local_e = mixing_matrix_local_e = s_max( mixing_matrix_local_e, mixing_matrix_res_local_e );
3270 64391 : move16();
3271 : }
3272 106849 : IF( remove_lfe )
3273 : {
3274 105799 : set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
3275 :
3276 105799 : ptrMM_fx = mixing_matrix_res_local_fx;
3277 105799 : ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx];
3278 317397 : FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
3279 : {
3280 751473 : FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
3281 : {
3282 1619625 : FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ )
3283 : {
3284 3869685 : FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
3285 : {
3286 2789935 : *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
3287 2789935 : move32();
3288 : }
3289 1079750 : ptrMM_out_fx++;
3290 : }
3291 539875 : ptrMM_out_fx--;
3292 : }
3293 211598 : ptrMM_out_fx += nY_cov;
3294 : }
3295 105799 : mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
3296 105799 : move16();
3297 : }
3298 : ELSE
3299 : {
3300 1050 : Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
3301 1050 : mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
3302 1050 : move16();
3303 : }
3304 : }
3305 25938 : ELSE IF( brange[0] < hParamMC->max_band_energy_compensation )
3306 : {
3307 : /* Compute mixing matrices (energy compensation only) */
3308 25938 : computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 1, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e );
3309 : }
3310 : ELSE
3311 : {
3312 : /*IF neither decorrelation nor energy compensation is applied*/
3313 0 : FOR( i = 0; i < nY_band; i++ )
3314 : {
3315 0 : tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i], L_add( Cproto_diag_fx[i], EPSILON_FX ), &tmp_e );
3316 0 : tmp_e = add( Cy_diag_e, Cproto_diag_e );
3317 0 : L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_e );
3318 0 : Cy_diag_fx[i] = L_tmp;
3319 0 : move32();
3320 0 : Cy_diag_buff_e[i] = tmp_e;
3321 0 : move16();
3322 : }
3323 :
3324 :
3325 0 : Cy_diag_e = Cy_diag_buff_e[0];
3326 0 : move16();
3327 :
3328 0 : FOR( i = 1; i < nY_band; i++ )
3329 : {
3330 0 : if ( LT_16( Cy_diag_e, Cy_diag_buff_e[i] ) )
3331 : {
3332 0 : Cy_diag_e = Cy_diag_buff_e[i];
3333 0 : move16();
3334 : }
3335 : }
3336 :
3337 0 : FOR( i = 0; i < nY_band; i++ )
3338 : {
3339 0 : Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], sub( Cy_diag_e, Cy_diag_buff_e[i] ) );
3340 0 : move32();
3341 : }
3342 :
3343 0 : diag_matrix_product_fx( Cy_diag_fx, Cy_diag_e, nY_band, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e );
3344 : }
3345 :
3346 132787 : IF( remove_lfe )
3347 : {
3348 131737 : set_zero_fx( mixing_matrix_fx[param_band_idx], imult1616( nX, nY_cov ) );
3349 131737 : ptrMM_fx = mixing_matrix_local_fx;
3350 131737 : ptrMM_out_fx = mixing_matrix_fx[param_band_idx];
3351 396481 : FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
3352 : {
3353 794232 : FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
3354 : {
3355 1886068 : FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
3356 : {
3357 1356580 : *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
3358 1356580 : move32();
3359 : }
3360 529488 : ptrMM_out_fx++;
3361 : }
3362 264744 : ptrMM_out_fx--;
3363 : }
3364 :
3365 131737 : mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
3366 131737 : move16();
3367 : }
3368 : ELSE
3369 : {
3370 1050 : Copy32( mixing_matrix_local_fx, mixing_matrix_fx[param_band_idx], imult1616( nY_cov, nX ) );
3371 1050 : mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
3372 1050 : move16();
3373 : }
3374 :
3375 132787 : return;
3376 : }
3377 :
3378 :
3379 : /*-------------------------------------------------------------------------
3380 : * param_mc_update_mixing_matrices()
3381 : *
3382 : * update mixing matrix buffers
3383 : *------------------------------------------------------------------------*/
3384 :
3385 10229 : static void param_mc_update_mixing_matrices_fx(
3386 : PARAM_MC_DEC_HANDLE hParamMC, /* i/o: Parametric MC handle */
3387 : Word32 *mixing_matrix[], /* i : direct mixing matrices for the frame just processed */
3388 : Word16 *mixing_matrix_exp,
3389 : Word32 *mixing_matrix_res[], /* i : residual mixing matrices for the frame just processed */
3390 : Word16 *mixing_matrix_res_exp,
3391 : const UWord16 nX, /* i : number of transport channels */
3392 : const UWord16 nY ) /* i : number of synthesis channels */
3393 : {
3394 : UWord16 param_band_idx;
3395 :
3396 145166 : FOR( param_band_idx = 0; param_band_idx < hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ )
3397 : {
3398 : Word16 brange[2];
3399 :
3400 134937 : brange[0] = hParamMC->band_grouping[param_band_idx];
3401 134937 : move16();
3402 134937 : brange[1] = hParamMC->band_grouping[param_band_idx + 1];
3403 134937 : move16();
3404 :
3405 134937 : Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nX, nY ) );
3406 134937 : hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = mixing_matrix_exp[param_band_idx];
3407 134937 : move16();
3408 :
3409 134937 : IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
3410 : {
3411 106849 : Copy32( mixing_matrix_res[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nY, nY ) );
3412 106849 : hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = mixing_matrix_res_exp[param_band_idx];
3413 106849 : move16();
3414 : }
3415 : }
3416 :
3417 10229 : return;
3418 : }
3419 :
3420 :
3421 : /*-------------------------------------------------------------------------
3422 : * ivas_param_mc_dequantize_cov()
3423 : *
3424 : * generate the target covariance matrix
3425 : *------------------------------------------------------------------------*/
3426 :
3427 :
3428 : /*-------------------------------------------------------------------------
3429 : * ivas_param_mc_dequantize_cov_fx()
3430 : *
3431 : * generate the target covariance matrix
3432 : *------------------------------------------------------------------------*/
3433 :
3434 132787 : static void ivas_param_mc_dequantize_cov_fx(
3435 : PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
3436 : Word16 *ild_q_fx, /* i : sequence of dequantized ILD values Q8 */
3437 : Word16 *icc_q_fx, /* i : sequence of dequantized ICC values Q15*/
3438 : const Word16 param_band_index, /* i : current parameter band */
3439 : const Word16 nY_cov, /* i : number of output channels in the covariance synthesis */
3440 : const PARAM_MC_SYNTHESIS_CONF synth_conf, /* i : Parametric MC synthesis configuration */
3441 : const Word16 nY_int, /* i : number of channels in the transported format */
3442 : const Word16 nX, /* i : number of transport channels */
3443 : Word32 *Cx_state_fx, /* i : transport channel covariance matrix */
3444 : Word16 Cx_state_e, /* i : exponent for transport channel covariance matrix */
3445 : Word32 *Cproto_fx, /* i : prototype matrix */
3446 : Word16 Cproto_e, /* i : exponent for prototype matrix */
3447 : Word32 *Cy_state_fx, /* o : target covariance matrix */
3448 : Word16 *Cy_state_e /* o : exponent for target covariance matrix */
3449 : )
3450 : {
3451 : Word16 Cy_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
3452 : Word16 Cp_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
3453 :
3454 : Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Nrqq_e)
3455 : Word16 Nrqq_e[MAX_OUTPUT_CHANNELS];
3456 : Word32 a_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - a_e)
3457 : Word16 a_e[MAX_OUTPUT_CHANNELS];
3458 : Word16 k;
3459 : Word16 l;
3460 : Word32 *Cyp_fx; // Q(31 - Cyp_e)
3461 : Word16 *Cyp_e;
3462 : Word32 ap_fx; // Q(31 - ap_e)
3463 : Word16 ap_e;
3464 : Word32 L_tmp;
3465 : Word16 tmp, tmp_e;
3466 : const PARAM_MC_ILD_MAPPING *h_ild_mapping;
3467 : Word32 Cy_state_int_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
3468 : Word16 Cy_state_int_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
3469 :
3470 132787 : set16_fx( Cp_buf_e, Cproto_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
3471 132787 : set32_fx( Nrqq_fx, 0, MAX_OUTPUT_CHANNELS );
3472 132787 : set16_fx( Nrqq_e, 0, MAX_OUTPUT_CHANNELS );
3473 132787 : h_ild_mapping = hParamMC->hMetadataPMC->ild_mapping_conf;
3474 :
3475 : /*get back Nrg*/
3476 132787 : tmp = 0;
3477 132787 : move16();
3478 :
3479 948409 : FOR( k = 0; k < nY_int; k++ )
3480 : {
3481 815622 : Word32 ref_ener_fx = 0; // Q(31 - ref_ener_e)
3482 815622 : move32();
3483 815622 : Word16 ref_ener_e = 0;
3484 815622 : move16();
3485 : Word16 ref_channel_cnt;
3486 : Word16 ref_channel_idx;
3487 :
3488 1894098 : FOR( ref_channel_cnt = 0; ref_channel_cnt < h_ild_mapping->num_ref_channels[k]; ref_channel_cnt++ )
3489 : {
3490 1078476 : ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt];
3491 1078476 : move16();
3492 1078476 : ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[ref_channel_idx + ( ref_channel_idx * nX )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e );
3493 1078476 : move32();
3494 : }
3495 :
3496 815622 : L_tmp = Mpy_32_16_1( 713378626, ild_q_fx[k] ); /*Q24 : L_tmp Q31 for log2(10)/10 -> 713378626 */
3497 815622 : L_tmp = BASOP_util_Pow2( L_tmp, 31 - 24, &tmp_e ); /*powf( 10.0f, ild_q_fx[k] / 10.0f )*/
3498 815622 : L_tmp = Mpy_32_32( L_tmp, Mpy_32_16_1( ref_ener_fx, hParamMC->hMetadataPMC->ild_factors_fx[k] ) );
3499 :
3500 815622 : Nrqq_fx[h_ild_mapping->ild_index[k]] = L_tmp;
3501 815622 : move32();
3502 815622 : Nrqq_e[h_ild_mapping->ild_index[k]] = add( tmp_e, ref_ener_e );
3503 815622 : move16();
3504 : }
3505 :
3506 : /* estimate ICCs from estimated Cproto */
3507 :
3508 948409 : FOR( k = 0; k < nY_int; k++ )
3509 : {
3510 : // a_fx[k] = 1.f / ( sqrtf( Cproto_fx[k + nY_int * k] ) + EPSILON );
3511 815622 : tmp_e = Cp_buf_e[k + ( nY_int * k )];
3512 815622 : move16();
3513 :
3514 815622 : IF( Cproto_fx[k + ( nY_int * k )] != 0 )
3515 : {
3516 815622 : L_tmp = ISqrt32( Cproto_fx[k + ( nY_int * k )], &tmp_e );
3517 : }
3518 : ELSE
3519 : {
3520 0 : L_tmp = INV_EPSILON_MANT;
3521 0 : move32();
3522 0 : tmp_e = 15;
3523 0 : move16();
3524 : }
3525 815622 : a_fx[k] = L_tmp;
3526 815622 : move32();
3527 815622 : a_e[k] = tmp_e;
3528 815622 : move16();
3529 :
3530 5880714 : FOR( l = 0; l < nY_int; l++ )
3531 : {
3532 5065092 : Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cproto_fx[( k * nY_int ) + l], a_fx[k] );
3533 5065092 : move32();
3534 5065092 : Cy_state_int_e[( k * nY_int ) + l] = add( Cp_buf_e[( k * nY_int ) + l], a_e[k] );
3535 5065092 : move16();
3536 : }
3537 : }
3538 :
3539 948409 : FOR( k = 0; k < nY_int; k++ )
3540 : {
3541 815622 : Cyp_fx = Cy_state_int_fx + k;
3542 815622 : Cyp_e = Cy_state_int_e + k;
3543 815622 : ap_fx = a_fx[k];
3544 815622 : move32();
3545 815622 : ap_e = a_e[k];
3546 815622 : move16();
3547 :
3548 5880714 : FOR( l = 0; l < nY_int; l++ )
3549 : {
3550 5065092 : ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
3551 5065092 : move32();
3552 5065092 : *Cyp_e = add( *Cyp_e, ap_e );
3553 5065092 : move16();
3554 :
3555 5065092 : Cyp_fx += nY_int;
3556 5065092 : Cyp_e += nY_int;
3557 : }
3558 : }
3559 :
3560 : /*normalizing the Cy_state_int_fx to a common exponent*/
3561 :
3562 : /* replace some estimated ICCs with transmitted values */
3563 815622 : FOR( k = 0; k < hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; k++ )
3564 : {
3565 682835 : Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp );
3566 682835 : move32();
3567 682835 : Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] )] = tmp;
3568 682835 : move16();
3569 682835 : Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp );
3570 682835 : move32();
3571 682835 : Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + ( nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] )] = tmp;
3572 682835 : move16();
3573 : }
3574 :
3575 132787 : test();
3576 132787 : IF( GE_16( param_band_index, PARAM_MC_MAX_BAND_LFE ) || ( hParamMC->hMetadataPMC->lfe_on == 0 ) )
3577 : {
3578 939659 : FOR( k = 0; k < nY_int; k++ )
3579 : {
3580 807922 : Cy_state_int_fx[k + ( 3 * nY_int )] = ONE_IN_Q31;
3581 807922 : move32();
3582 807922 : Cy_state_int_e[k + ( 3 * nY_int )] = 0;
3583 807922 : move16();
3584 807922 : Cy_state_int_fx[3 + ( k * nY_int )] = ONE_IN_Q31;
3585 807922 : move32();
3586 807922 : Cy_state_int_e[3 + ( k * nY_int )] = 0;
3587 807922 : move16();
3588 : }
3589 131737 : Nrqq_fx[3] = 0;
3590 131737 : move32();
3591 : }
3592 :
3593 : /* Generate back Covariance Mtx */
3594 948409 : FOR( k = 0; k < nY_int; k++ )
3595 : {
3596 815622 : tmp_e = Nrqq_e[k];
3597 815622 : move16();
3598 815622 : a_fx[k] = Sqrt32( Nrqq_fx[k], &tmp_e );
3599 815622 : move32();
3600 815622 : a_e[k] = tmp_e;
3601 815622 : move16();
3602 :
3603 : /* v_multc( Cy_state_int_fx + k * nY_int, a_fx[k], Cy_state_int_fx + k * nY_int, nY_int ) */
3604 5880714 : FOR( l = 0; l < nY_int; l++ )
3605 : {
3606 5065092 : Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cy_state_int_fx[( k * nY_int ) + l], a_fx[k] );
3607 5065092 : move32();
3608 5065092 : Cy_state_int_e[( k * nY_int ) + l] = add( Cy_state_int_e[( k * nY_int ) + l], a_e[k] );
3609 5065092 : move16();
3610 : }
3611 : }
3612 :
3613 948409 : FOR( k = 0; k < nY_int; k++ )
3614 : {
3615 815622 : Cyp_fx = Cy_state_int_fx + k;
3616 815622 : Cyp_e = Cy_state_int_e + k;
3617 815622 : ap_fx = a_fx[k];
3618 815622 : move32();
3619 815622 : ap_e = a_e[k];
3620 815622 : move16();
3621 :
3622 5880714 : FOR( l = 0; l < nY_int; l++ )
3623 : {
3624 5065092 : ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
3625 5065092 : move32();
3626 5065092 : ( *Cyp_e ) = add( *Cyp_e, ap_e );
3627 5065092 : move16();
3628 :
3629 5065092 : Cyp_fx += nY_int;
3630 5065092 : Cyp_e += nY_int;
3631 : }
3632 : }
3633 :
3634 132787 : IF( EQ_32( synth_conf, PARAM_MC_SYNTH_LS_CONV_COV ) )
3635 : {
3636 : /* Cy = dmx*Cy*dmx' */
3637 : Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
3638 : Word16 mat_mult_buffer1_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
3639 : Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; // Q(31 - target_ch_ener_e)
3640 : Word16 target_ch_ener_e[MAX_CICP_CHANNELS];
3641 : Word32 dmx_ch_ener_fx[MAX_CICP_CHANNELS];
3642 :
3643 : Word16 ls_conv_dmx_matrix_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
3644 :
3645 2100 : set32_fx( target_ch_ener_fx, 0, MAX_CICP_CHANNELS );
3646 2100 : set16_fx( target_ch_ener_e, 0, MAX_CICP_CHANNELS );
3647 2100 : set32_fx( dmx_ch_ener_fx, 0, MAX_CICP_CHANNELS );
3648 2100 : set16_fx( ls_conv_dmx_matrix_e, 1, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
3649 :
3650 2100 : matrix_product_mant_exp( hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 0,
3651 : Cy_state_int_fx, Cy_state_int_e, nY_int, nY_int, 0,
3652 : mat_mult_buffer1_fx, mat_mult_buffer1_e );
3653 :
3654 2100 : matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_cov, nY_int, 0,
3655 2100 : hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 1,
3656 : Cy_state_fx, Cy_buf_e );
3657 :
3658 14700 : FOR( k = 0; k < nY_cov; k++ )
3659 : {
3660 113400 : FOR( l = 0; l < nY_int; l++ )
3661 : {
3662 100800 : L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[k + ( l * nY_cov )], Nrqq_fx[l] );
3663 100800 : tmp_e = add( ls_conv_dmx_matrix_e[k + ( l + nY_cov )], Nrqq_e[l] );
3664 100800 : L_tmp = BASOP_Util_Add_Mant32Exp( target_ch_ener_fx[k], target_ch_ener_e[k], L_tmp, tmp_e, &tmp_e );
3665 100800 : target_ch_ener_fx[k] = L_tmp;
3666 100800 : move32();
3667 100800 : target_ch_ener_e[k] = tmp_e;
3668 100800 : move16();
3669 : }
3670 :
3671 12600 : dmx_ch_ener_fx[k] = Cy_state_fx[k + ( nY_cov * k )];
3672 12600 : move32();
3673 :
3674 12600 : IF( dmx_ch_ener_fx[k] < 0 )
3675 : {
3676 0 : Cy_state_fx[k + ( nY_cov * k )] = L_negate( Cy_state_fx[k + ( nY_cov * k )] );
3677 0 : move32();
3678 0 : dmx_ch_ener_fx[k] = L_negate( dmx_ch_ener_fx[k] );
3679 0 : move32();
3680 : }
3681 :
3682 12600 : IF( extract_h( dmx_ch_ener_fx[k] ) == 0 )
3683 : {
3684 1950 : target_ch_ener_fx[k] = 0;
3685 1950 : move32();
3686 1950 : target_ch_ener_e[k] = 0;
3687 1950 : move16();
3688 : }
3689 : ELSE
3690 : {
3691 10650 : BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[k + ( nY_cov * k )], &tmp, &tmp_e );
3692 10650 : tmp = Sqrt16( tmp, &tmp_e );
3693 10650 : target_ch_ener_fx[k] = L_deposit_h( tmp );
3694 10650 : move32();
3695 10650 : target_ch_ener_e[k] = tmp_e;
3696 10650 : move16();
3697 : }
3698 :
3699 88200 : FOR( l = 0; l < nY_cov; l++ )
3700 : {
3701 75600 : Cy_state_fx[( k * nY_cov ) + l] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[( k * nY_cov ) + l] );
3702 75600 : move32();
3703 75600 : Cy_buf_e[( k * nY_cov ) + l] = add( target_ch_ener_e[k], Cy_buf_e[( k * nY_cov ) + l] );
3704 75600 : move16();
3705 : }
3706 :
3707 12600 : Cyp_fx = Cy_state_fx + k;
3708 12600 : Cyp_e = Cy_buf_e + k;
3709 12600 : ap_fx = target_ch_ener_fx[k];
3710 12600 : move32();
3711 12600 : ap_e = target_ch_ener_e[k];
3712 12600 : move16();
3713 88200 : FOR( l = 0; l < nY_cov; l++ )
3714 : {
3715 75600 : ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
3716 75600 : move32();
3717 75600 : *Cyp_e = add( *Cyp_e, ap_e );
3718 75600 : move16();
3719 :
3720 75600 : Cyp_fx += nY_cov;
3721 75600 : Cyp_e += nY_cov;
3722 : }
3723 : }
3724 : }
3725 : ELSE
3726 : {
3727 130687 : Copy32( Cy_state_int_fx, Cy_state_fx, imult1616( nY_int, nY_int ) );
3728 130687 : Copy( Cy_state_int_e, Cy_buf_e, imult1616( nY_int, nY_int ) );
3729 : }
3730 :
3731 : /*normalize output matrix to a common exponent*/
3732 132787 : tmp = 0;
3733 5197879 : FOR( k = 0; k < nY_int * nY_int; k++ )
3734 : {
3735 5065092 : Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] );
3736 5065092 : move32();
3737 5065092 : tmp = s_max( tmp, Cy_buf_e[k] );
3738 : }
3739 5197879 : FOR( k = 0; k < nY_int * nY_int; k++ )
3740 : {
3741 5065092 : L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) );
3742 5065092 : Cy_state_fx[k] = L_tmp;
3743 5065092 : move32();
3744 : }
3745 132787 : *Cy_state_e = tmp;
3746 132787 : move16();
3747 :
3748 132787 : return;
3749 : }
3750 :
3751 : /*-------------------------------------------------------------------------*
3752 : * param_mc_set_num_synth_bands()
3753 : *
3754 : * set the number of frequency bands to be synthesized
3755 : *-------------------------------------------------------------------------*/
3756 :
3757 430 : static void param_mc_set_num_synth_bands(
3758 : const Word32 output_Fs, /* i : output sampling frequency */
3759 : PARAM_MC_DEC_HANDLE hParamMC /* i/o: Parametric MC handle */
3760 : )
3761 : {
3762 : UWord16 max_param_band_synth;
3763 : const Word16 *param_mc_bands_coded;
3764 :
3765 430 : SWITCH( hParamMC->hMetadataPMC->num_parameter_bands )
3766 : {
3767 3 : case 20:
3768 3 : param_mc_bands_coded = param_mc_bands_coded_20;
3769 3 : BREAK;
3770 216 : case 10:
3771 216 : param_mc_bands_coded = param_mc_bands_coded_10;
3772 216 : BREAK;
3773 211 : case 14:
3774 : default:
3775 211 : param_mc_bands_coded = param_mc_bands_coded_14;
3776 211 : BREAK;
3777 : }
3778 430 : move16();
3779 430 : SWITCH( output_Fs )
3780 : {
3781 0 : case 8000:
3782 0 : max_param_band_synth = (UWord16) param_mc_bands_coded[NB];
3783 0 : BREAK;
3784 77 : case 16000:
3785 77 : max_param_band_synth = (UWord16) param_mc_bands_coded[WB];
3786 77 : BREAK;
3787 7 : case 32000:
3788 7 : max_param_band_synth = (UWord16) param_mc_bands_coded[SWB];
3789 7 : BREAK;
3790 346 : case 48000:
3791 : default:
3792 346 : max_param_band_synth = (UWord16) param_mc_bands_coded[FB];
3793 346 : BREAK;
3794 : }
3795 430 : move16();
3796 430 : hParamMC->num_param_bands_synth = s_min( hParamMC->hMetadataPMC->nbands_coded, max_param_band_synth );
3797 430 : move16();
3798 :
3799 430 : return;
3800 : }
3801 :
3802 :
3803 : /*-------------------------------------------------------------------------*
3804 : * param_mc_get_diff_proto_info()
3805 : *
3806 : * calculated the diffuse prototype information
3807 : *-------------------------------------------------------------------------*/
3808 :
3809 :
3810 279 : static ivas_error param_mc_get_diff_proto_info_fx(
3811 : const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */
3812 : const UWord16 nchan_transport, /* i : number of transport channels */
3813 : const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */
3814 : PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, /* o : generated diffuse prototype info */
3815 : Word16 Q_proto_mtx )
3816 : {
3817 : Word32 proto_fac_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
3818 : UWord16 cur_out_ch;
3819 : UWord16 cur_diff_proto;
3820 : UWord16 cur_transport_ch;
3821 : UWord16 max_num_src_chan;
3822 :
3823 : /* Initializations */
3824 279 : max_num_src_chan = 0;
3825 279 : move16();
3826 :
3827 279 : set_zero_fx( proto_fac_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
3828 279 : IF( ( p_diff_proto_info->proto_index_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
3829 : {
3830 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3831 : }
3832 279 : set16_fx( p_diff_proto_info->proto_index_diff, 0, nchan_out_cov );
3833 :
3834 279 : IF( ( p_diff_proto_info->num_source_chan_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
3835 : {
3836 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3837 : }
3838 279 : set16_fx( p_diff_proto_info->num_source_chan_diff, 0, nchan_out_cov );
3839 :
3840 : /* we have at least one prototype, copy the first one */
3841 279 : p_diff_proto_info->num_protos_diff = 1;
3842 279 : move16();
3843 :
3844 279 : mvr2r_inc_fixed( proto_mtx, nchan_out_cov, proto_fac_fx, nchan_out_cov, nchan_transport );
3845 279 : p_diff_proto_info->proto_index_diff[0] = 0;
3846 279 : move16();
3847 :
3848 : /* search for distinct prototypes */
3849 1788 : FOR( cur_out_ch = 1; cur_out_ch < nchan_out_cov; cur_out_ch++ )
3850 : {
3851 1509 : UWord16 found = 0;
3852 1509 : move16();
3853 :
3854 3246 : FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
3855 : {
3856 2686 : Word32 diff_fx = 0;
3857 2686 : move32();
3858 2686 : Word32 *proto_fac_ptr_fx = proto_fac_fx + cur_diff_proto;
3859 2686 : const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
3860 8310 : FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
3861 : {
3862 5624 : diff_fx = L_add( diff_fx, L_abs( L_sub( *proto_fac_ptr_fx, *proto_mtx_ptr ) ) );
3863 5624 : proto_fac_ptr_fx += nchan_out_cov;
3864 5624 : proto_mtx_ptr += nchan_out_cov;
3865 : }
3866 :
3867 : /* we already have this prototype, save the index */
3868 2686 : IF( LT_64( W_mult0_32_32( diff_fx, 10 ), L_shl_sat( 1, Q_proto_mtx ) ) )
3869 : {
3870 949 : found = 1;
3871 949 : move16();
3872 949 : p_diff_proto_info->proto_index_diff[cur_out_ch] = cur_diff_proto;
3873 949 : move16();
3874 949 : BREAK;
3875 : }
3876 : }
3877 :
3878 : /* new distinct prototype, add it */
3879 1509 : IF( found == 0 )
3880 : {
3881 560 : const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
3882 : Word16 cur_num_src_chan;
3883 :
3884 560 : cur_num_src_chan = 0;
3885 560 : move16();
3886 1710 : FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
3887 : {
3888 1150 : if ( GT_32( *proto_mtx_ptr, 0 /*EPSILON*/ ) )
3889 : {
3890 824 : cur_num_src_chan = add( cur_num_src_chan, 1 );
3891 : }
3892 1150 : proto_mtx_ptr += nchan_out_cov;
3893 : }
3894 :
3895 560 : mvr2r_inc_fixed( proto_mtx + cur_out_ch, nchan_out_cov, proto_fac_fx + p_diff_proto_info->num_protos_diff, nchan_out_cov, nchan_transport );
3896 :
3897 560 : p_diff_proto_info->proto_index_diff[cur_out_ch] = p_diff_proto_info->num_protos_diff;
3898 560 : move16();
3899 560 : p_diff_proto_info->num_protos_diff = add( p_diff_proto_info->num_protos_diff, 1 );
3900 560 : move16();
3901 560 : max_num_src_chan = s_max( max_num_src_chan, cur_num_src_chan );
3902 : }
3903 : }
3904 :
3905 : /* set up the prototype info struct */
3906 279 : IF( ( p_diff_proto_info->source_chan_idx = (Word16 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word16 * ) ) ) == NULL )
3907 : {
3908 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3909 : }
3910 :
3911 279 : IF( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL )
3912 : {
3913 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3914 : }
3915 1118 : FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
3916 : {
3917 : Word32 *proto_fac_ptr;
3918 :
3919 839 : IF( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (Word16 *) malloc( max_num_src_chan * sizeof( Word16 ) ) ) == NULL )
3920 : {
3921 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3922 : }
3923 :
3924 839 : IF( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL )
3925 : {
3926 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3927 : }
3928 :
3929 839 : proto_fac_ptr = proto_fac_fx + cur_diff_proto;
3930 2562 : FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
3931 : {
3932 1723 : IF( GT_32( *proto_fac_ptr, EPSILON_FX_SMALL ) )
3933 : {
3934 1103 : p_diff_proto_info->source_chan_idx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = cur_transport_ch;
3935 1103 : move16();
3936 1103 : p_diff_proto_info->proto_fac_fx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = *proto_fac_ptr; // (proto_fac_fx)Q26 = Q26
3937 1103 : move16();
3938 1103 : p_diff_proto_info->num_source_chan_diff[cur_diff_proto] = add( p_diff_proto_info->num_source_chan_diff[cur_diff_proto], 1 );
3939 1103 : move16();
3940 : }
3941 1723 : proto_fac_ptr += nchan_out_cov;
3942 : }
3943 : }
3944 279 : return IVAS_ERR_OK;
3945 : }
3946 :
3947 :
3948 : /*-------------------------------------------------------------------------*
3949 : * ivas_param_mc_bs_decode_parameter_values()
3950 : *
3951 : * reads and decodes a sequence of Parametric MC parameters from the bitstream
3952 : *-------------------------------------------------------------------------*/
3953 :
3954 20432 : static void ivas_param_mc_bs_decode_parameter_values_fx(
3955 : UWord16 bit_buffer[], /* i : bitstream buffer */
3956 : Word16 *bit_pos, /* i/o: current bitstream buffer position */
3957 : const Word16 max_bits, /* i : maximum available bits in the buffer */
3958 : Word16 *BER_detect, /* i/o: bit error detection flag */
3959 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, /* i : Parametric MC metadata information */
3960 : HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, /* i : Parametric MC parameter quantization and coding tables */
3961 : const Word16 map_size_wo_lfe, /* i : number of parameters per band (w/o LFEs) */
3962 : const Word16 map_size, /* i : number of parameters per band (total) */
3963 : const Word16 num_lfe_bands, /* i : number of parameter bands with coded LFE */
3964 : const Word16 band_step, /* i : parameter band step */
3965 : const Word16 num_param_bands, /* i : number of parameter bands to decode */
3966 : Word16 *value_buffer /* o : output buffer for decoded parameter values hParamCodingInfo -> Q-quant*/
3967 : )
3968 : {
3969 : Word16 range_coding;
3970 : Word16 sz_seq;
3971 : Word16 delta_coding;
3972 : Word16 delta_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
3973 : Word16 idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
3974 : Word16 idx_prev;
3975 : Word16 idx_offset;
3976 : Word16 sz_alphabet;
3977 : Word16 i, j, k;
3978 : Word16 dequant_seq_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
3979 : Word16 dequant_ordered_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
3980 : Word16 n_lfe_idx;
3981 :
3982 20432 : range_coding = bit_buffer[*bit_pos];
3983 20432 : move16();
3984 20432 : *bit_pos = add( *bit_pos, 1 );
3985 20432 : move16();
3986 :
3987 : /* Decoding the sequence */
3988 20432 : n_lfe_idx = sub( map_size, map_size_wo_lfe );
3989 20432 : sz_seq = add( imult1616( num_param_bands, map_size_wo_lfe ), imult1616( num_lfe_bands, n_lfe_idx ) );
3990 :
3991 20432 : set16_fx( idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
3992 20432 : set16_fx( dequant_ordered_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
3993 20432 : set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
3994 20432 : IF( range_coding )
3995 : {
3996 19957 : delta_coding = bit_buffer[*bit_pos];
3997 19957 : move16();
3998 19957 : *bit_pos = add( *bit_pos, 1 );
3999 19957 : move16();
4000 :
4001 19957 : IF( delta_coding )
4002 : {
4003 19694 : idx_prev = sub( add( shr( hParamCodingInfo->quantizer_size, 1 ), hParamCodingInfo->quantizer_size % 2 ), 1 );
4004 19694 : sz_alphabet = sub( shl( hParamCodingInfo->quantizer_size, 1 ), 1 );
4005 19694 : idx_offset = sub( hParamCodingInfo->quantizer_size, 1 );
4006 :
4007 : /* read range coded delta ICC indices */
4008 19694 : *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], delta_idx, BER_detect, sz_seq, sz_alphabet,
4009 19694 : hParamCodingInfo->cum_freq_delta, hParamCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
4010 19694 : move16();
4011 :
4012 : /* delta index to absolute index */
4013 629279 : FOR( j = 0; j < sz_seq; j++ )
4014 : {
4015 609585 : idx[j] = add( idx_prev, sub( delta_idx[j], idx_offset ) );
4016 609585 : idx_prev = idx[j];
4017 609585 : move16();
4018 : }
4019 : }
4020 : ELSE
4021 : {
4022 : /* read range coded absolute ICC indices */
4023 263 : sz_alphabet = hParamCodingInfo->quantizer_size;
4024 263 : move16();
4025 263 : *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], idx, BER_detect, sz_seq, sz_alphabet,
4026 263 : hParamCodingInfo->cum_freq, hParamCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
4027 263 : move16();
4028 : }
4029 :
4030 : /* dequantize */
4031 636423 : FOR( j = 0; j < sz_seq; j++ )
4032 : {
4033 616466 : dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; // hParamCodingInfo -> Q-quant
4034 616466 : move16();
4035 : }
4036 : }
4037 : ELSE
4038 : {
4039 475 : set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
4040 : /* read uniformly coded ICCs */
4041 475 : *bit_pos = add( *bit_pos, ivas_param_mc_uniform_decoder_fx( dequant_seq_fx, sz_seq, hParamCodingInfo->quantizer_fx, hParamCodingInfo->uni_bits, &bit_buffer[*bit_pos] ) );
4042 475 : move16();
4043 : }
4044 :
4045 : /* reorder from sequential to parameter-band-wise */
4046 20432 : k = 0;
4047 115295 : FOR( j = 0; j < map_size_wo_lfe; ++j )
4048 : {
4049 722462 : FOR( i = 0; i < num_param_bands; ++i )
4050 : {
4051 627599 : dequant_ordered_fx[j + ( i * map_size )] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
4052 627599 : move16();
4053 627599 : k = add( k, 1 );
4054 : }
4055 : }
4056 :
4057 21600 : FOR( i = 0; i < num_lfe_bands; i++ )
4058 : {
4059 2401 : FOR( j = 0; j < n_lfe_idx; j++ )
4060 : {
4061 1233 : dequant_ordered_fx[map_size - n_lfe_idx + j + i * map_size] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
4062 1233 : move16();
4063 1233 : k = add( k, 1 );
4064 : }
4065 : }
4066 :
4067 20432 : IF( !( *BER_detect ) )
4068 : {
4069 20432 : j = 0;
4070 283952 : FOR( k = 0; k < hMetadataPMC->nbands_coded; k += band_step )
4071 : {
4072 263520 : test();
4073 263520 : IF( hMetadataPMC->bAttackPresent || EQ_16( hMetadataPMC->param_frame_idx, hMetadataPMC->coding_band_mapping[k] ) )
4074 : {
4075 134950 : Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); // hParamCodingInfo -> Q-quant
4076 134950 : j++;
4077 : }
4078 263520 : IF( hMetadataPMC->bAttackPresent && k + 1 < hMetadataPMC->nbands_coded )
4079 : {
4080 6234 : Copy( value_buffer + imult1616( k, map_size ), value_buffer + imult1616( add( k, 1 ), map_size ), map_size );
4081 : }
4082 : }
4083 : }
4084 :
4085 20432 : return;
4086 : }
|