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