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 /*, Word16 RealBuffer_fx_e, 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 40439 : 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 48 : hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[j] = 0;
1970 48 : 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 );
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 : Q5,
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 : #ifdef VEC_ARITH_OPT_v1
2088 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 );
2089 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 );
2090 : #else /* VEC_ARITH_OPT_v1 */
2091 : v_add_fixed( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_RealBuffer_fx[ch][slot_idx], 1, 0 );
2092 : v_add_fixed( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], 1, 0 );
2093 : #endif /* VEC_ARITH_OPT_v1 */
2094 : }
2095 : }
2096 : }
2097 : }
2098 :
2099 59680 : idx_out = 0;
2100 59680 : move16();
2101 59680 : idx_lfe = 0;
2102 59680 : move16();
2103 :
2104 420640 : FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ )
2105 : {
2106 360960 : test();
2107 360960 : IF( ( hLsSetup.num_lfe > 0 ) && EQ_16( hLsSetup.index_lfe[idx_lfe], ch ) )
2108 : {
2109 59680 : IF( LT_16( idx_lfe, ( sub( hLsSetup.num_lfe, 1 ) ) ) )
2110 : {
2111 0 : idx_lfe = add( idx_lfe, 1 );
2112 : }
2113 : }
2114 301280 : ELSE IF( NE_16( ch, idx_out ) )
2115 : {
2116 122240 : Copy32( Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_RealBuffer_fx[idx_out][slot_idx], nband_synth );
2117 122240 : Copy32( Cldfb_ImagBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[idx_out][slot_idx], nband_synth );
2118 122240 : idx_out = add( idx_out, 1 );
2119 : }
2120 : ELSE
2121 : {
2122 179040 : idx_out = add( idx_out, 1 );
2123 : }
2124 : }
2125 : }
2126 : }
2127 : }
2128 :
2129 35040 : test();
2130 35040 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2131 27640 : {
2132 27640 : Word16 input_q = 6;
2133 27640 : move16();
2134 : /* Implement binaural rendering */
2135 27640 : ivas_binRenderer_fx( st_ivas->hBinRenderer,
2136 : st_ivas->hCombinedOrientationData,
2137 27640 : hParamMC->subframe_nbslots[subframe_idx],
2138 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
2139 : Cldfb_RealBuffer_fx,
2140 : Cldfb_ImagBuffer_fx, &input_q );
2141 :
2142 469880 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2143 : {
2144 2211200 : FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ )
2145 : {
2146 107906560 : FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
2147 : {
2148 106137600 : Cldfb_RealBuffer_fx[i][j][k] = L_shl( Cldfb_RealBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
2149 106137600 : Cldfb_ImagBuffer_fx[i][j][k] = L_shl( Cldfb_ImagBuffer_fx[i][j][k], sub( Q6, input_q ) ); // Q6
2150 : }
2151 : }
2152 : }
2153 :
2154 82920 : FOR( Word16 idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ )
2155 : {
2156 276400 : FOR( Word16 idx2 = 0; idx2 < hParamMC->subframe_nbslots[subframe_idx]; idx2++ )
2157 : {
2158 221120 : Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6
2159 221120 : Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); // Q6
2160 : }
2161 : }
2162 : /* update combined orientation access index */
2163 27640 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx] );
2164 : }
2165 7400 : ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
2166 : {
2167 : /* format conversion*/
2168 1360 : ivas_lssetupconversion_process_param_mc_fx( st_ivas, hParamMC->subframe_nbslots[subframe_idx], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, channel_active );
2169 : }
2170 :
2171 :
2172 : /* CLDFB synthesis */
2173 143360 : FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
2174 : {
2175 : Word32 *RealBuffer_fx[16];
2176 : Word32 *ImagBuffer_fx[16];
2177 :
2178 108320 : IF( channel_active[ch] )
2179 : {
2180 : /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands FOR 48kHz */
2181 500800 : FOR( i = 0; i < hParamMC->subframe_nbslots[subframe_idx]; i++ )
2182 : {
2183 400640 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2184 : {
2185 221120 : RealBuffer_fx[i] = Cldfb_RealBuffer_Binaural_fx[ch][i]; // Q6
2186 221120 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_Binaural_fx[ch][i]; // Q6
2187 : }
2188 : ELSE
2189 : {
2190 179520 : RealBuffer_fx[i] = Cldfb_RealBuffer_fx[ch][i]; // Q6
2191 179520 : ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[ch][i]; // Q6
2192 : }
2193 : }
2194 :
2195 100160 : Word16 len = add( imult1616( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) );
2196 100160 : scale_sig32( output_f_fx[ch], len, 5 - 11 );
2197 : #ifdef OPT_AVOID_STATE_BUF_RESCALE
2198 100160 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ),
2199 100160 : imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), 0, 0, st_ivas->cldfbSynDec[ch] );
2200 : #else /* OPT_AVOID_STATE_BUF_RESCALE */
2201 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ),
2202 : imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), 0, st_ivas->cldfbSynDec[ch] );
2203 : #endif /* OPT_AVOID_STATE_BUF_RESCALE */
2204 :
2205 100160 : scale_sig32( output_f_fx[ch], len, 11 - 5 ); // Q11
2206 : }
2207 : ELSE
2208 : {
2209 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] ) );
2210 : }
2211 : }
2212 35040 : slot_idx_start = add( slot_idx_start, hParamMC->subframe_nbslots[subframe_idx] );
2213 35040 : slot_idx_start_cldfb_synth = add( slot_idx_start_cldfb_synth, hParamMC->subframe_nbslots[subframe_idx] );
2214 : }
2215 8760 : IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2216 : {
2217 360 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_f_fx, p_output_f_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
2218 : }
2219 :
2220 : /* update */
2221 :
2222 8760 : IF( EQ_16( hParamMC->slots_rendered, hParamMC->num_slots ) )
2223 : {
2224 8760 : hParamMC->hMetadataPMC->last_coded_bwidth = hParamMC->hMetadataPMC->coded_bwidth;
2225 8760 : move16();
2226 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 );
2227 : }
2228 :
2229 :
2230 8760 : hParamMC->subframes_rendered = last_sf;
2231 8760 : move16();
2232 8760 : *nSamplesAvailableNext = imult1616( sub( hParamMC->num_slots, hParamMC->slots_rendered ), NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ) );
2233 8760 : move16();
2234 :
2235 148920 : FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ )
2236 : {
2237 140160 : channel_active_fx[i] = channel_active[i];
2238 140160 : move16();
2239 : }
2240 8760 : pop_wmops();
2241 :
2242 8760 : return;
2243 : }
2244 :
2245 : /*-------------------------------------------------------------------------
2246 : * param_mc_dec_init()
2247 : *
2248 : * Parametric MC decoding initialization
2249 : *------------------------------------------------------------------------*/
2250 :
2251 241 : static void ivas_param_mc_dec_init_fx(
2252 : PARAM_MC_DEC_HANDLE hParamMC, /* i/o: decoder DirAC handle */
2253 : const Word16 nchan_transport, /* i : number of input (transport) channels */
2254 : const Word16 nchan_cov ) /* i : number of cov synthesis channels */
2255 : {
2256 : Word16 k;
2257 : UWord16 max_param_band_residual;
2258 : Word16 len;
2259 :
2260 : /*-----------------------------------------------------------------*
2261 : * init sub-modules
2262 : *-----------------------------------------------------------------*/
2263 :
2264 : /* decorrelation */
2265 241 : IF( hParamMC->max_band_decorr > 0 )
2266 : {
2267 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 );
2268 :
2269 : /* init onsetDetectionPower */
2270 239 : set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len );
2271 239 : set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len );
2272 239 : hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31;
2273 239 : move16();
2274 : }
2275 :
2276 241 : max_param_band_residual = 0;
2277 241 : move16();
2278 :
2279 : /* output synthesis */
2280 851 : FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- )
2281 : {
2282 851 : IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) )
2283 : {
2284 241 : max_param_band_residual = k;
2285 241 : move16();
2286 241 : BREAK;
2287 : }
2288 : }
2289 :
2290 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 );
2291 :
2292 : /*-----------------------------------------------------------------*
2293 : * init proto frames
2294 : *-----------------------------------------------------------------*/
2295 :
2296 241 : IF( hParamMC->max_band_decorr > 0 )
2297 : {
2298 239 : set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) );
2299 239 : set32_fx( hParamMC->proto_frame_dec_f_fx, 0, shl( imult1616( nchan_cov, hParamMC->num_freq_bands ), 1 ) );
2300 : }
2301 :
2302 241 : return;
2303 : }
2304 :
2305 :
2306 : /*-------------------------------------------------------------------------
2307 : * Local functions
2308 : *-------------------------------------------------------------------------*/
2309 :
2310 :
2311 : /*-------------------------------------------------------------------------
2312 : * ivas_param_mc_dec_compute_diffuse_proto()
2313 : *
2314 : * Compute prototypes for decorrelation
2315 : *------------------------------------------------------------------------*/
2316 :
2317 140160 : static void param_mc_protoSignalComputation_fx(
2318 : Word32 *RealBuffer_fx, /* i : CLDFB samples of the transport channels (real part) */
2319 : Word32 *ImagBuffer_fx, /* i : CLDFB samples of the transport channels (imaginary part) */
2320 : Word32 *proto_frame_f_fx, /* o : interleaved complex prototype CLDFB samples */
2321 : const PARAM_MC_DIFF_PROTO_INFO *diff_proto_info, /* i : prototype generation information */
2322 : const Word16 num_freq_bands /* i : number of frequency bands for the prototypes */
2323 : )
2324 : {
2325 : Word16 band;
2326 : Word16 proto_ch_idx, source_ch_cnt;
2327 :
2328 : Word32 *p_proto_frame_fx;
2329 : Word32 *p_real_buffer_fx; // Q12
2330 : Word32 *p_imag_buffer_fx; // Q12
2331 :
2332 140160 : set32_fx( proto_frame_f_fx, 0, shl( imult1616( num_freq_bands, diff_proto_info->num_protos_diff ), 1 ) );
2333 :
2334 :
2335 565440 : FOR( proto_ch_idx = 0; proto_ch_idx < diff_proto_info->num_protos_diff; proto_ch_idx++ )
2336 : {
2337 425280 : Word16 num_source_ch = diff_proto_info->num_source_chan_diff[proto_ch_idx];
2338 425280 : move16();
2339 :
2340 990080 : FOR( source_ch_cnt = 0; source_ch_cnt < num_source_ch; source_ch_cnt++ )
2341 : {
2342 :
2343 564800 : Word32 fac_fx = diff_proto_info->proto_fac_fx[proto_ch_idx][source_ch_cnt];
2344 564800 : move32();
2345 :
2346 564800 : Word16 source_ch_idx = diff_proto_info->source_chan_idx[proto_ch_idx][source_ch_cnt];
2347 564800 : move16();
2348 :
2349 564800 : p_proto_frame_fx = &proto_frame_f_fx[shl( imult1616( proto_ch_idx, num_freq_bands ), 1 )];
2350 564800 : p_real_buffer_fx = &RealBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
2351 564800 : p_imag_buffer_fx = &ImagBuffer_fx[imult1616( source_ch_idx, num_freq_bands )];
2352 :
2353 32225600 : FOR( band = 0; band < num_freq_bands; band++ )
2354 : {
2355 :
2356 31660800 : Word32 tmp_x = Mpy_32_32( fac_fx, ( *( p_real_buffer_fx++ ) ) ); // Q(30 + 6 - 31) :: Q5
2357 :
2358 31660800 : *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
2359 31660800 : move32();
2360 31660800 : p_proto_frame_fx++;
2361 :
2362 31660800 : tmp_x = Mpy_32_32( fac_fx, ( *( p_imag_buffer_fx++ ) ) ); // Q(30 + 6 - 31) :: Q5
2363 :
2364 31660800 : *( p_proto_frame_fx ) = L_add( *( p_proto_frame_fx ), tmp_x );
2365 31660800 : move32();
2366 31660800 : p_proto_frame_fx++;
2367 : }
2368 : }
2369 : }
2370 :
2371 140160 : return;
2372 : }
2373 :
2374 : /*-------------------------------------------------------------------------
2375 : * ivas_param_mc_dec_compute_diffuse_proto()
2376 : *
2377 : * Transfer decorrelated signals back from the decorrelator buffer to
2378 : * the buffers used in the final synthesis
2379 : *------------------------------------------------------------------------*/
2380 :
2381 140160 : static void ivas_param_mc_dec_copy_diffuse_proto(
2382 : PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
2383 : 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) */
2384 : 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) */
2385 : const Word16 nY, /* i : number of decorrelated channels */
2386 : const Word16 slot_idx /* i : current time slot index */
2387 : )
2388 : {
2389 : Word16 k, l;
2390 : Word16 num_freq_bands, num_freq_bands_diff;
2391 : Word32 *p_proto_diff_fx;
2392 140160 : num_freq_bands = hParamMC->num_freq_bands;
2393 140160 : move16();
2394 140160 : num_freq_bands_diff = hParamMC->h_output_synthesis_params.max_band_decorr;
2395 140160 : move16();
2396 :
2397 991680 : FOR( k = 0; k < nY; k++ )
2398 : {
2399 851520 : p_proto_diff_fx = hParamMC->proto_frame_dec_f_fx + imult1616( shl( k, 1 ), num_freq_bands ); // Q11
2400 :
2401 17881920 : FOR( l = 0; l < num_freq_bands_diff; l++ )
2402 : {
2403 17030400 : Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
2404 17030400 : move32();
2405 17030400 : Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); // Q11
2406 17030400 : move32();
2407 : }
2408 : }
2409 :
2410 140160 : return;
2411 : }
2412 :
2413 : /*-------------------------------------------------------------------------
2414 : * ivas_param_mc_bin2dec()
2415 : *
2416 : * decode a number of bits to an integer
2417 : *------------------------------------------------------------------------*/
2418 : /* r : decoded integer */
2419 10112 : static Word16 ivas_param_mc_bin2dec_fx(
2420 : UWord16 bits[PARAM_MC_MAX_BITS], /* i : bit buffer */
2421 : const Word16 N /* i : number of bits to decode */
2422 : )
2423 : {
2424 : Word16 i;
2425 : Word16 out;
2426 :
2427 10112 : assert( N <= 16 );
2428 10112 : out = 0;
2429 10112 : move16();
2430 40448 : FOR( i = 0; i < N; i++ )
2431 : {
2432 30336 : out = add( out, shl( bits[i], sub( sub( N, 1 ), i ) ) );
2433 : }
2434 :
2435 10112 : return out;
2436 : }
2437 :
2438 : /*-------------------------------------------------------------------------
2439 : * ivas_param_mc_uniform_decoder()
2440 : *
2441 : * decode a uniformily coded sequence of float values
2442 : *------------------------------------------------------------------------*/
2443 393 : static Word16 ivas_param_mc_uniform_decoder_fx(
2444 : Word16 *seq, /* o : decoded sequence of float values hParamCodingInfo -> Q-quant*/
2445 : const Word16 sz_seq, /* i : number of values to decode */
2446 : const Word16 *alphabet, /* i : codebook hParamCodingInfo -> Q-quant*/
2447 : const Word16 N, /* i : number of bits per coded index */
2448 : UWord16 bit_buffer[PARAM_MC_MAX_BITS] /* i : bit buffer to decode */
2449 : )
2450 : {
2451 : Word16 i;
2452 : Word16 idx;
2453 : Word16 n_bits;
2454 :
2455 393 : n_bits = 0;
2456 393 : move16();
2457 393 : assert( N * sz_seq < PARAM_MC_MAX_BITS );
2458 :
2459 10505 : FOR( i = 0; i < sz_seq; ++i )
2460 : {
2461 10112 : idx = ivas_param_mc_bin2dec_fx( &bit_buffer[i * N], N );
2462 10112 : seq[i] = alphabet[idx];
2463 10112 : move16();
2464 : }
2465 :
2466 393 : n_bits = imult1616( N, sz_seq );
2467 :
2468 393 : return n_bits;
2469 : }
2470 :
2471 :
2472 : /*-------------------------------------------------------------------------
2473 : * ivas_param_mc_range_decoder_LC()
2474 : *
2475 : * decode a sequency of inidices coded with a range coder
2476 : *------------------------------------------------------------------------*/
2477 17107 : static Word16 ivas_param_mc_range_decoder_LC_fx(
2478 : UWord16 *bit_buffer, /* i : bit buffer to read from */
2479 : Word16 *x, /* o : decoded indices */
2480 : Word16 *BER_detect, /* o : flag for indicating a bit error */
2481 : const Word16 sz_seq, /* i : size of the sequence to be decoded */
2482 : const Word16 sz_alphabet, /* i : size of the alphabet */
2483 : const UWord16 *cft, /* i : cumulative frequency table */
2484 : const UWord16 *sft, /* i : symbol frequency table */
2485 : const Word16 tot_shift, /* i : total frequency as a power of 2 */
2486 : const Word16 nbbits /* i : maximum bit budget */
2487 : )
2488 : {
2489 : RangeUniDecState rc_st_dec; /* State of the range decoder */
2490 : Word16 cur_bit_pos;
2491 : Word16 k;
2492 : Word16 r;
2493 :
2494 : /* Start Decoding */
2495 : /* Initialize range decoder */
2496 17107 : cur_bit_pos = 0;
2497 17107 : move16();
2498 17107 : rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, sub( nbbits, 32 ) ); /* (nbbits + 30) entries are read by the decoder */
2499 :
2500 : /* Main Loop through the indices */
2501 540205 : FOR( k = 0; k < sz_seq; k++ )
2502 : {
2503 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) */
2504 : /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1} */
2505 :
2506 : /* Update bitstream pointer */
2507 523098 : cur_bit_pos = rc_uni_dec_virtual_finish_fx( &rc_st_dec );
2508 :
2509 : /* Confirm that there is no overflow */
2510 523098 : IF( GT_16( cur_bit_pos, nbbits ) )
2511 : {
2512 0 : *BER_detect = s_or( *BER_detect, 1 );
2513 0 : move16();
2514 : }
2515 :
2516 523098 : x[k] = r;
2517 523098 : move16();
2518 : }
2519 :
2520 : /* We don't need to finish because virtual_finish() already does the same */
2521 : /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/
2522 :
2523 : /* Check for bitstream errors */
2524 17107 : IF( rc_st_dec.bit_error_detected != 0 )
2525 : {
2526 0 : *BER_detect = s_or( *BER_detect, 1 );
2527 0 : move16();
2528 : }
2529 :
2530 17107 : return cur_bit_pos;
2531 : }
2532 :
2533 : /*-------------------------------------------------------------------------
2534 : * param_mc_compute_interpolator()
2535 : *
2536 : * compute the interpolator used in the final synthesis
2537 : *------------------------------------------------------------------------*/
2538 :
2539 9057 : static void ivas_param_mc_dec_compute_interpolator_fx(
2540 : const UWord16 bAttackPresent, /* i : flag indicating if we have a transient in the current frame */
2541 : const UWord16 attackPos, /* i : position of the transient */
2542 : const UWord16 interp_length, /* i : number of interpolation values to be calculated */
2543 : Word16 *interpolator /* o : interpolator */
2544 : )
2545 : {
2546 : Word16 idx;
2547 :
2548 9057 : IF( bAttackPresent )
2549 : {
2550 3156 : FOR( idx = 0; idx < attackPos * 2; idx++ )
2551 : {
2552 2750 : interpolator[idx] = 0;
2553 2750 : move16();
2554 : }
2555 4152 : FOR( ; idx < interp_length; idx++ )
2556 : {
2557 3746 : interpolator[idx] = 32767; /* 1.0f Q15 */
2558 3746 : move16();
2559 : }
2560 : }
2561 : ELSE
2562 : {
2563 8651 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, interp_length, interpolator );
2564 : }
2565 :
2566 9057 : return;
2567 : }
2568 :
2569 :
2570 : /*-------------------------------------------------------------------------
2571 : * remove_lfe_from_cy()
2572 : *
2573 : * remove all LFE related values from a covariance matrix
2574 : *------------------------------------------------------------------------*/
2575 :
2576 112316 : static void remove_lfe_from_cy_fx(
2577 : const Word16 nY, /* i : dimension of the covariance matrix */
2578 : Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP], /* i : LFE index */
2579 : Word16 num_lfe, /* i : number of LFEs */
2580 : Word32 *cy, /* i : covariance matrix */
2581 : Word32 *cy_woLFE /* o : covariance matrix with LFE removed */
2582 : )
2583 : {
2584 : Word16 ch_idx1, ch_idx2;
2585 : Word16 lfe_idx1, lfe_idx2;
2586 : Word32 *ptrCy;
2587 : Word32 *ptrCy_out;
2588 :
2589 112316 : ptrCy = cy;
2590 112316 : ptrCy_out = cy_woLFE;
2591 :
2592 336948 : FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ )
2593 : {
2594 794472 : FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
2595 : {
2596 1709520 : FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ )
2597 : {
2598 4059180 : FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
2599 : {
2600 2919500 : *( ptrCy_out++ ) = *( ptrCy++ );
2601 2919500 : move32();
2602 : }
2603 1139680 : ptrCy++;
2604 : }
2605 569840 : ptrCy--;
2606 : }
2607 224632 : ptrCy += nY;
2608 : }
2609 :
2610 112316 : return;
2611 : }
2612 :
2613 :
2614 : /*-------------------------------------------------------------------------
2615 : * ivas_param_mc_get_mixing_matrices()
2616 : *
2617 : * calculate the direct and residual mixing matrices
2618 : * using the covariance method
2619 : *------------------------------------------------------------------------*/
2620 :
2621 113120 : static void ivas_param_mc_get_mixing_matrices_fx(
2622 : PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
2623 : IVAS_OUTPUT_SETUP *hSynthesisOutputSetup,
2624 : 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)*/
2625 : Word16 Cx_in_e,
2626 : const Word16 param_band_idx, /* i : parameter band index */
2627 : Word32 *mixing_matrix_fx[], // Q(31 - mixing_matrix_e)
2628 : Word16 *mixing_matrix_e,
2629 : Word32 *mixing_matrix_res_fx[], // Q(31 - mixing_matrix_res_e)
2630 : Word16 *mixing_matrix_res_e,
2631 : const Word16 nY_intern, /* i : number of channels in the transported format */
2632 : const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */
2633 : const Word16 nX, /* i : number of transport channels */
2634 : const Word16 nY_cov /* i : number of covariance synthesis output channels */
2635 : )
2636 : {
2637 113120 : Word16 matSize = MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS;
2638 : Word16 nY_band;
2639 : Word16 num_lfe_bands;
2640 : Word16 brange[2];
2641 : UWord16 i;
2642 : Word16 ch_idx1, ch_idx2, lfe_idx1, lfe_idx2;
2643 : Word16 remove_lfe;
2644 : Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP];
2645 :
2646 : Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
2647 : Word32 Cy_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
2648 :
2649 : Word32 Cy_full_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
2650 :
2651 : Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cr_e)
2652 : Word16 Cr_e;
2653 : Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Cy_diag_buff_e)
2654 : Word16 Cy_diag_buff_e[MAX_OUTPUT_CHANNELS];
2655 : Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; // Q(31 - mixing_matrix_local_e)
2656 113120 : Word16 Cy_diag_e = 0, mixing_matrix_local_e = 0;
2657 : Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cproto_e)
2658 : Word16 Cproto_e;
2659 : Word32 *proto_matrix_ptr_fx; // Q(31 - proto_matrix_ptr_e)
2660 : Word32 *Cx_state_fx; // Q(31 - Cx_state_e)
2661 : Word32 *Cx_old_state_fx;
2662 : Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - Cy_state_e)
2663 : Word32 *Cy_old_state_fx;
2664 : Word16 Cx_state_e;
2665 : Word16 Cy_state_e;
2666 : Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mixing_matrix_res_local_e)
2667 : Word16 mixing_matrix_res_local_e;
2668 : Word32 L_tmp;
2669 : Word16 tmp_e, tmp;
2670 :
2671 113120 : Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
2672 113120 : move16();
2673 : Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; // Q(31 - proto_matrix_noLFE_e)
2674 :
2675 : Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
2676 :
2677 : Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; // Q(31 - Cproto_diag_e)
2678 : Word16 mat_mult_buffer1_e, proto_matrix_ptr_e, Cproto_diag_e;
2679 :
2680 : Word32 *ptrMM_fx;
2681 : Word32 *ptrMM_out_fx;
2682 :
2683 : Word16 Cy_e, Cx_e;
2684 : Word16 Cy_full_e;
2685 113120 : Word16 new_e = 0;
2686 113120 : move16();
2687 :
2688 113120 : set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
2689 113120 : set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
2690 113120 : set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
2691 113120 : set_zero_fx( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
2692 113120 : set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
2693 113120 : Word16 proto_matrix_noLFE_e = 0;
2694 113120 : move16();
2695 :
2696 : Word32 Cx_in_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS];
2697 :
2698 113120 : Copy32( Cx_in_fixed, Cx_in_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS );
2699 :
2700 113120 : nY_band = nY_cov;
2701 113120 : move16();
2702 113120 : num_lfe_bands = 0;
2703 113120 : move16();
2704 113120 : remove_lfe = 0;
2705 113120 : move16();
2706 :
2707 113120 : set16_fx( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP );
2708 113120 : IF( hSynthesisOutputSetup->num_lfe )
2709 : {
2710 : Word32 *proto_matrix_ptr_in_fx;
2711 226240 : FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ )
2712 : {
2713 113120 : lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1];
2714 113120 : move16();
2715 : }
2716 113120 : lfe_indices[hSynthesisOutputSetup->num_lfe + 1] = nY_cov;
2717 113120 : move16();
2718 113120 : proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0];
2719 113120 : proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0];
2720 113120 : proto_matrix_noLFE_e = proto_matrix_e;
2721 113120 : move16();
2722 :
2723 113120 : set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS );
2724 :
2725 339920 : FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
2726 : {
2727 680400 : FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
2728 : {
2729 1608800 : FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
2730 : {
2731 1155200 : *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ );
2732 1155200 : move32();
2733 : }
2734 453600 : proto_matrix_ptr_in_fx++;
2735 : }
2736 226800 : proto_matrix_ptr_in_fx--;
2737 : }
2738 :
2739 113120 : proto_matrix_ptr_e = proto_matrix_e;
2740 113120 : move16();
2741 : }
2742 :
2743 113120 : if ( hParamMC->hMetadataPMC->lfe_on )
2744 : {
2745 10646 : num_lfe_bands = PARAM_MC_MAX_BAND_LFE;
2746 10646 : move16();
2747 : }
2748 113120 : IF( hSynthesisOutputSetup->num_lfe > 0 && param_band_idx >= num_lfe_bands )
2749 : {
2750 112316 : remove_lfe = 1;
2751 112316 : move16();
2752 112316 : nY_band = sub( nY_cov, hSynthesisOutputSetup->num_lfe );
2753 112316 : proto_matrix_ptr_fx = proto_matrix_noLFE_fx;
2754 112316 : proto_matrix_ptr_e = proto_matrix_noLFE_e;
2755 112316 : move16();
2756 : }
2757 : ELSE
2758 : {
2759 804 : proto_matrix_ptr_fx = hParamMC->h_output_synthesis_params.proto_matrix_fx;
2760 804 : proto_matrix_ptr_e = hParamMC->h_output_synthesis_params.proto_matrix_e;
2761 804 : move16();
2762 : }
2763 :
2764 113120 : brange[0] = hParamMC->band_grouping[param_band_idx];
2765 113120 : move16();
2766 113120 : brange[1] = hParamMC->band_grouping[param_band_idx + 1];
2767 113120 : move16();
2768 :
2769 113120 : Cx_state_fx = Cx_in_fx;
2770 113120 : Cx_old_state_fx = hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx];
2771 113120 : Cy_old_state_fx = hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx];
2772 :
2773 :
2774 : /* Getting mixing mtx */
2775 : /* estimate target cov from input cov and proto_matrix */
2776 :
2777 113120 : Cx_state_e = Cx_in_e;
2778 113120 : move16();
2779 113120 : matrix_product_fx( hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx );
2780 113120 : mat_mult_buffer1_e = add( hParamMC->proto_matrix_int_e, Cx_in_e );
2781 :
2782 113120 : matrix_product_fx( mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx );
2783 113120 : Cproto_e = add( mat_mult_buffer1_e, hParamMC->proto_matrix_int_e );
2784 :
2785 804960 : FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ )
2786 : {
2787 691840 : IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )], Cproto_e, 0, 0 ) < 0 )
2788 : {
2789 0 : Cproto_fx[ch_idx1 + ( ch_idx1 * nY_intern )] = 0;
2790 0 : move32();
2791 : }
2792 : }
2793 :
2794 113120 : set_zero_fx( Cy_state_fx, matSize );
2795 113120 : Cy_state_e = 0;
2796 113120 : move16();
2797 :
2798 339360 : ivas_param_mc_dequantize_cov_fx( hParamMC,
2799 113120 : hParamMC->icld_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ),
2800 113120 : hParamMC->icc_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ),
2801 : param_band_idx, nY_cov,
2802 : synth_config,
2803 : nY_intern,
2804 : nX, Cx_state_fx, Cx_state_e, Cproto_fx, Cproto_e, Cy_state_fx, &Cy_state_e );
2805 :
2806 : // dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state_fx.txt");
2807 :
2808 : /* Smoothing: Sum over two buffers */
2809 113120 : IF( hParamMC->hMetadataPMC->bAttackPresent )
2810 : {
2811 : /* no smoothing on attacks */
2812 5001 : Copy32( Cx_state_fx, Cx_fx, imult1616( nX, nX ) );
2813 5001 : Copy32( Cy_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) );
2814 5001 : Cy_full_e = Cy_state_e;
2815 5001 : move16();
2816 5001 : Cx_e = Cx_state_e;
2817 5001 : move16();
2818 : }
2819 : ELSE
2820 : {
2821 : /* smoothing gains are now identical to one, simply add up */
2822 : // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov );
2823 :
2824 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 );
2825 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 );
2826 : }
2827 :
2828 113120 : Copy32( Cx_state_fx, Cx_old_state_fx, imult1616( nX, nX ) );
2829 :
2830 113120 : Copy32( Cy_state_fx, Cy_old_state_fx, imult1616( nY_cov, nY_cov ) );
2831 :
2832 113120 : hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = Cx_state_e;
2833 113120 : move16();
2834 113120 : hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e;
2835 113120 : move16();
2836 :
2837 113280 : FOR( i = 0; i < nX * nX; i++ )
2838 : {
2839 113240 : if ( Cx_old_state_fx[i] != 0 )
2840 : {
2841 113080 : new_e = hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx];
2842 113080 : move16();
2843 113080 : BREAK;
2844 : }
2845 : }
2846 :
2847 113120 : hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = new_e;
2848 113120 : move16();
2849 :
2850 113120 : new_e = 0;
2851 113120 : move16();
2852 :
2853 114560 : FOR( i = 0; i < nY_cov * nY_cov; i++ )
2854 : {
2855 114520 : if ( Cy_old_state_fx[i] != 0 )
2856 : {
2857 113080 : new_e = hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx];
2858 113080 : move16();
2859 113080 : BREAK;
2860 : }
2861 : }
2862 :
2863 113120 : hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = new_e;
2864 113120 : move16();
2865 :
2866 : /* remove LFE IF necessary */
2867 113120 : IF( remove_lfe )
2868 : {
2869 :
2870 112316 : Cy_e = Cy_full_e;
2871 112316 : remove_lfe_from_cy_fx( nY_cov, lfe_indices, hSynthesisOutputSetup->num_lfe, Cy_full_fx, Cy_fx );
2872 : }
2873 : ELSE
2874 : {
2875 804 : Copy32( Cy_full_fx, Cy_fx, imult1616( nY_band, nY_band ) );
2876 804 : Cy_e = Cy_full_e;
2877 804 : move16();
2878 : }
2879 :
2880 113120 : matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx );
2881 113120 : mat_mult_buffer1_e = add( proto_matrix_ptr_e, Cx_e );
2882 :
2883 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 );
2884 :
2885 : /* make sure we have no negative entries in Cproto_diag due to rounding errors */
2886 :
2887 688444 : FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ )
2888 : {
2889 575324 : if ( Cproto_diag_fx[ch_idx1] < 0 )
2890 : {
2891 0 : Cproto_diag_fx[ch_idx1] = 0;
2892 0 : move16();
2893 : }
2894 : }
2895 :
2896 :
2897 : /* Computing the mixing matrices */
2898 :
2899 : /* bands with decorr */
2900 113120 : IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
2901 : {
2902 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 );
2903 : /* Compute mixing matrix FOR residual */
2904 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 );
2905 :
2906 90900 : IF( NE_16( mixing_matrix_res_local_e, mixing_matrix_local_e ) )
2907 : {
2908 54660 : tmp = getScaleFactor32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
2909 54660 : scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, tmp );
2910 54660 : mixing_matrix_local_e = sub( mixing_matrix_local_e, tmp );
2911 :
2912 54660 : tmp = getScaleFactor32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS );
2913 54660 : scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, tmp );
2914 54660 : mixing_matrix_res_local_e = sub( mixing_matrix_res_local_e, tmp );
2915 :
2916 54660 : 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 ) ) );
2917 54660 : 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 ) ) );
2918 :
2919 54660 : mixing_matrix_res_local_e = mixing_matrix_local_e = s_max( mixing_matrix_local_e, mixing_matrix_res_local_e );
2920 54660 : move16();
2921 : }
2922 90900 : IF( remove_lfe )
2923 : {
2924 90096 : set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
2925 :
2926 90096 : ptrMM_fx = mixing_matrix_res_local_fx;
2927 90096 : ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx];
2928 270288 : FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
2929 : {
2930 637152 : FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ )
2931 : {
2932 1370880 : FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ )
2933 : {
2934 3253680 : FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ )
2935 : {
2936 2339760 : *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
2937 2339760 : move32();
2938 : }
2939 913920 : ptrMM_out_fx++;
2940 : }
2941 456960 : ptrMM_out_fx--;
2942 : }
2943 180192 : ptrMM_out_fx += nY_cov;
2944 : }
2945 90096 : mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
2946 90096 : move16();
2947 : }
2948 : ELSE
2949 : {
2950 804 : Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) );
2951 804 : mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e;
2952 804 : move16();
2953 : }
2954 : }
2955 22220 : ELSE IF( brange[0] < hParamMC->max_band_energy_compensation )
2956 : {
2957 : /* Compute mixing matrices (energy compensation only) */
2958 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 );
2959 : }
2960 : ELSE
2961 : {
2962 : /*IF neither decorrelation nor energy compensation is applied*/
2963 0 : FOR( i = 0; i < nY_band; i++ )
2964 : {
2965 0 : tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i], L_add( Cproto_diag_fx[i], EPSILON_FX ), &tmp_e );
2966 0 : tmp_e = add( Cy_diag_e, Cproto_diag_e );
2967 0 : L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_e );
2968 0 : Cy_diag_fx[i] = L_tmp;
2969 0 : move32();
2970 0 : Cy_diag_buff_e[i] = tmp_e;
2971 0 : move16();
2972 : }
2973 :
2974 :
2975 0 : Cy_diag_e = Cy_diag_buff_e[0];
2976 0 : move16();
2977 :
2978 0 : FOR( i = 1; i < nY_band; i++ )
2979 : {
2980 0 : if ( LT_16( Cy_diag_e, Cy_diag_buff_e[i] ) )
2981 : {
2982 0 : Cy_diag_e = Cy_diag_buff_e[i];
2983 0 : move16();
2984 : }
2985 : }
2986 :
2987 0 : FOR( i = 0; i < nY_band; i++ )
2988 : {
2989 0 : Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], sub( Cy_diag_e, Cy_diag_buff_e[i] ) );
2990 0 : move32();
2991 : }
2992 :
2993 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 );
2994 : }
2995 :
2996 113120 : IF( remove_lfe )
2997 : {
2998 112316 : set_zero_fx( mixing_matrix_fx[param_band_idx], imult1616( nX, nY_cov ) );
2999 112316 : ptrMM_fx = mixing_matrix_local_fx;
3000 112316 : ptrMM_out_fx = mixing_matrix_fx[param_band_idx];
3001 337468 : FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ )
3002 : {
3003 675456 : FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ )
3004 : {
3005 1595704 : FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ )
3006 : {
3007 1145400 : *( ptrMM_out_fx++ ) = *( ptrMM_fx++ );
3008 1145400 : move32();
3009 : }
3010 450304 : ptrMM_out_fx++;
3011 : }
3012 225152 : ptrMM_out_fx--;
3013 : }
3014 :
3015 112316 : mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
3016 112316 : move16();
3017 : }
3018 : ELSE
3019 : {
3020 804 : Copy32( mixing_matrix_local_fx, mixing_matrix_fx[param_band_idx], imult1616( nY_cov, nX ) );
3021 804 : mixing_matrix_e[param_band_idx] = mixing_matrix_local_e;
3022 804 : move16();
3023 : }
3024 :
3025 113120 : return;
3026 : }
3027 :
3028 :
3029 : /*-------------------------------------------------------------------------
3030 : * ivas_param_mc_get_mono_stereo_mixing_matrices()
3031 : *
3032 : * calculate the direct and residual mixing matrices
3033 : * for mono and stereo output
3034 : *------------------------------------------------------------------------*/
3035 :
3036 :
3037 : /*-------------------------------------------------------------------------
3038 : * param_mc_update_mixing_matrices()
3039 : *
3040 : * update mixing matrix buffers
3041 : *------------------------------------------------------------------------*/
3042 :
3043 8760 : static void param_mc_update_mixing_matrices_fx(
3044 : PARAM_MC_DEC_HANDLE hParamMC, /* i/o: Parametric MC handle */
3045 : Word32 *mixing_matrix[], /* i : direct mixing matrices for the frame just processed */
3046 : Word16 *mixing_matrix_exp,
3047 : Word32 *mixing_matrix_res[], /* i : residual mixing matrices for the frame just processed */
3048 : Word16 *mixing_matrix_res_exp,
3049 : const UWord16 nX, /* i : number of transport channels */
3050 : const UWord16 nY ) /* i : number of synthesis channels */
3051 : {
3052 : UWord16 param_band_idx;
3053 :
3054 123780 : FOR( param_band_idx = 0; param_band_idx < hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ )
3055 : {
3056 : Word16 brange[2];
3057 :
3058 115020 : brange[0] = hParamMC->band_grouping[param_band_idx];
3059 115020 : move16();
3060 115020 : brange[1] = hParamMC->band_grouping[param_band_idx + 1];
3061 115020 : move16();
3062 :
3063 115020 : Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nX, nY ) );
3064 115020 : hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = mixing_matrix_exp[param_band_idx];
3065 115020 : move16();
3066 :
3067 115020 : IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) )
3068 : {
3069 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 ) );
3070 90900 : hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = mixing_matrix_res_exp[param_band_idx];
3071 90900 : move16();
3072 : }
3073 : }
3074 :
3075 8760 : return;
3076 : }
3077 :
3078 :
3079 : /*-------------------------------------------------------------------------
3080 : * ivas_param_mc_dequantize_cov()
3081 : *
3082 : * generate the target covariance matrix
3083 : *------------------------------------------------------------------------*/
3084 :
3085 :
3086 : /*-------------------------------------------------------------------------
3087 : * ivas_param_mc_dequantize_cov_fx()
3088 : *
3089 : * generate the target covariance matrix
3090 : *------------------------------------------------------------------------*/
3091 :
3092 113120 : static void ivas_param_mc_dequantize_cov_fx(
3093 : PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */
3094 : Word16 *ild_q_fx, /* i : sequence of dequantized ILD values Q8 */
3095 : Word16 *icc_q_fx, /* i : sequence of dequantized ICC values Q15*/
3096 : const Word16 param_band_index, /* i : current parameter band */
3097 : const Word16 nY_cov, /* i : number of output channels in the covariance synthesis */
3098 : const PARAM_MC_SYNTHESIS_CONF synth_conf, /* i : Parametric MC synthesis configuration */
3099 : const Word16 nY_int, /* i : number of channels in the transported format */
3100 : const Word16 nX, /* i : number of transport channels */
3101 : Word32 *Cx_state_fx, /* i : transport channel covariance matrix */
3102 : Word16 Cx_state_e, /* i : exponent for transport channel covariance matrix */
3103 : Word32 *Cproto_fx, /* i : prototype matrix */
3104 : Word16 Cproto_e, /* i : exponent for prototype matrix */
3105 : Word32 *Cy_state_fx, /* o : target covariance matrix */
3106 : Word16 *Cy_state_e /* o : exponent for target covariance matrix */
3107 : )
3108 : {
3109 : Word16 Cy_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
3110 : Word16 Cp_buf_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
3111 :
3112 : Word32 Nrqq_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - Nrqq_e)
3113 : Word16 Nrqq_e[MAX_OUTPUT_CHANNELS];
3114 : Word32 a_fx[MAX_OUTPUT_CHANNELS]; // Q(31 - a_e)
3115 : Word16 a_e[MAX_OUTPUT_CHANNELS];
3116 : Word16 k;
3117 : Word16 l;
3118 : Word32 *Cyp_fx; // Q(31 - Cyp_e)
3119 : Word16 *Cyp_e;
3120 : Word32 ap_fx; // Q(31 - ap_e)
3121 : Word16 ap_e;
3122 : Word32 L_tmp;
3123 : Word16 tmp, tmp_e;
3124 : const PARAM_MC_ILD_MAPPING *h_ild_mapping;
3125 : Word32 Cy_state_int_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
3126 : Word16 Cy_state_int_e[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS];
3127 :
3128 113120 : set16_fx( Cp_buf_e, Cproto_e, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
3129 113120 : set32_fx( Nrqq_fx, 0, MAX_OUTPUT_CHANNELS );
3130 113120 : set16_fx( Nrqq_e, 0, MAX_OUTPUT_CHANNELS );
3131 113120 : h_ild_mapping = hParamMC->hMetadataPMC->ild_mapping_conf;
3132 :
3133 : /*get back Nrg*/
3134 113120 : tmp = 0;
3135 113120 : move16();
3136 :
3137 804960 : FOR( k = 0; k < nY_int; k++ )
3138 : {
3139 691840 : Word32 ref_ener_fx = 0; // Q(31 - ref_ener_e)
3140 691840 : move32();
3141 691840 : Word16 ref_ener_e = 0;
3142 691840 : move16();
3143 : Word16 ref_channel_cnt;
3144 : Word16 ref_channel_idx;
3145 :
3146 1608800 : FOR( ref_channel_cnt = 0; ref_channel_cnt < h_ild_mapping->num_ref_channels[k]; ref_channel_cnt++ )
3147 : {
3148 916960 : ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt];
3149 916960 : move16();
3150 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 );
3151 916960 : move32();
3152 : }
3153 :
3154 691840 : L_tmp = Mpy_32_16_1( 713378626, ild_q_fx[k] ); /*Q24 : L_tmp Q31 for log2(10)/10 -> 713378626 */
3155 691840 : L_tmp = BASOP_util_Pow2( L_tmp, 31 - 24, &tmp_e ); /*powf( 10.0f, ild_q_fx[k] / 10.0f )*/
3156 691840 : L_tmp = Mpy_32_32( L_tmp, Mpy_32_16_1( ref_ener_fx, hParamMC->hMetadataPMC->ild_factors_fx[k] ) );
3157 :
3158 691840 : Nrqq_fx[h_ild_mapping->ild_index[k]] = L_tmp;
3159 691840 : move32();
3160 691840 : Nrqq_e[h_ild_mapping->ild_index[k]] = add( tmp_e, ref_ener_e );
3161 691840 : move16();
3162 : }
3163 :
3164 : /* estimate ICCs from estimated Cproto */
3165 :
3166 804960 : FOR( k = 0; k < nY_int; k++ )
3167 : {
3168 : // a_fx[k] = 1.f / ( sqrtf( Cproto_fx[k + nY_int * k] ) + EPSILON );
3169 691840 : tmp_e = Cp_buf_e[k + ( nY_int * k )];
3170 691840 : move16();
3171 :
3172 691840 : IF( Cproto_fx[k + ( nY_int * k )] != 0 )
3173 : {
3174 691600 : L_tmp = ISqrt32( Cproto_fx[k + ( nY_int * k )], &tmp_e );
3175 : }
3176 : ELSE
3177 : {
3178 240 : L_tmp = INV_EPSILON_MANT;
3179 240 : move32();
3180 240 : tmp_e = 15;
3181 240 : move16();
3182 : }
3183 691840 : a_fx[k] = L_tmp;
3184 691840 : move32();
3185 691840 : a_e[k] = tmp_e;
3186 691840 : move16();
3187 :
3188 4961280 : FOR( l = 0; l < nY_int; l++ )
3189 : {
3190 4269440 : Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cproto_fx[( k * nY_int ) + l], a_fx[k] );
3191 4269440 : move32();
3192 4269440 : Cy_state_int_e[( k * nY_int ) + l] = add( Cp_buf_e[( k * nY_int ) + l], a_e[k] );
3193 4269440 : move16();
3194 : }
3195 : }
3196 :
3197 804960 : FOR( k = 0; k < nY_int; k++ )
3198 : {
3199 691840 : Cyp_fx = Cy_state_int_fx + k;
3200 691840 : Cyp_e = Cy_state_int_e + k;
3201 691840 : ap_fx = a_fx[k];
3202 691840 : move32();
3203 691840 : ap_e = a_e[k];
3204 691840 : move16();
3205 :
3206 4961280 : FOR( l = 0; l < nY_int; l++ )
3207 : {
3208 4269440 : ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
3209 4269440 : move32();
3210 4269440 : *Cyp_e = add( *Cyp_e, ap_e );
3211 4269440 : move16();
3212 :
3213 4269440 : Cyp_fx += nY_int;
3214 4269440 : Cyp_e += nY_int;
3215 : }
3216 : }
3217 :
3218 : /*normalizing the Cy_state_int_fx to a common exponent*/
3219 :
3220 : /* replace some estimated ICCs with transmitted values */
3221 691840 : FOR( k = 0; k < hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; k++ )
3222 : {
3223 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 );
3224 578720 : move32();
3225 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;
3226 578720 : move16();
3227 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 );
3228 578720 : move32();
3229 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;
3230 578720 : move16();
3231 : }
3232 :
3233 113120 : test();
3234 113120 : IF( GE_16( param_band_index, PARAM_MC_MAX_BAND_LFE ) || ( hParamMC->hMetadataPMC->lfe_on == 0 ) )
3235 : {
3236 798372 : FOR( k = 0; k < nY_int; k++ )
3237 : {
3238 686056 : Cy_state_int_fx[k + ( 3 * nY_int )] = ONE_IN_Q31;
3239 686056 : move32();
3240 686056 : Cy_state_int_e[k + ( 3 * nY_int )] = 0;
3241 686056 : move16();
3242 686056 : Cy_state_int_fx[3 + ( k * nY_int )] = ONE_IN_Q31;
3243 686056 : move32();
3244 686056 : Cy_state_int_e[3 + ( k * nY_int )] = 0;
3245 686056 : move16();
3246 : }
3247 112316 : Nrqq_fx[3] = 0;
3248 112316 : move32();
3249 : }
3250 :
3251 : /* Generate back Covariance Mtx */
3252 804960 : FOR( k = 0; k < nY_int; k++ )
3253 : {
3254 691840 : tmp_e = Nrqq_e[k];
3255 691840 : move16();
3256 691840 : a_fx[k] = Sqrt32( Nrqq_fx[k], &tmp_e );
3257 691840 : move32();
3258 691840 : a_e[k] = tmp_e;
3259 691840 : move16();
3260 :
3261 : /* v_multc( Cy_state_int_fx + k * nY_int, a_fx[k], Cy_state_int_fx + k * nY_int, nY_int ) */
3262 4961280 : FOR( l = 0; l < nY_int; l++ )
3263 : {
3264 4269440 : Cy_state_int_fx[( k * nY_int ) + l] = Mpy_32_32( Cy_state_int_fx[( k * nY_int ) + l], a_fx[k] );
3265 4269440 : move32();
3266 4269440 : Cy_state_int_e[( k * nY_int ) + l] = add( Cy_state_int_e[( k * nY_int ) + l], a_e[k] );
3267 4269440 : move16();
3268 : }
3269 : }
3270 :
3271 804960 : FOR( k = 0; k < nY_int; k++ )
3272 : {
3273 691840 : Cyp_fx = Cy_state_int_fx + k;
3274 691840 : Cyp_e = Cy_state_int_e + k;
3275 691840 : ap_fx = a_fx[k];
3276 691840 : move32();
3277 691840 : ap_e = a_e[k];
3278 691840 : move16();
3279 :
3280 4961280 : FOR( l = 0; l < nY_int; l++ )
3281 : {
3282 4269440 : ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
3283 4269440 : move32();
3284 4269440 : ( *Cyp_e ) = add( *Cyp_e, ap_e );
3285 4269440 : move16();
3286 :
3287 4269440 : Cyp_fx += nY_int;
3288 4269440 : Cyp_e += nY_int;
3289 : }
3290 : }
3291 :
3292 113120 : IF( EQ_32( synth_conf, PARAM_MC_SYNTH_LS_CONV_COV ) )
3293 : {
3294 : /* Cy = dmx*Cy*dmx' */
3295 : Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; // Q(31 - mat_mult_buffer1_e)
3296 : Word16 mat_mult_buffer1_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
3297 : Word32 target_ch_ener_fx[MAX_CICP_CHANNELS]; // Q(31 - target_ch_ener_e)
3298 : Word16 target_ch_ener_e[MAX_CICP_CHANNELS];
3299 : Word32 dmx_ch_ener_fx[MAX_CICP_CHANNELS];
3300 :
3301 : Word16 ls_conv_dmx_matrix_e[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS];
3302 :
3303 2100 : set32_fx( target_ch_ener_fx, 0, MAX_CICP_CHANNELS );
3304 2100 : set16_fx( target_ch_ener_e, 0, MAX_CICP_CHANNELS );
3305 2100 : set32_fx( dmx_ch_ener_fx, 0, MAX_CICP_CHANNELS );
3306 2100 : set16_fx( ls_conv_dmx_matrix_e, 1, MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS );
3307 :
3308 2100 : matrix_product_mant_exp( hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 0,
3309 : Cy_state_int_fx, Cy_state_int_e, nY_int, nY_int, 0,
3310 : mat_mult_buffer1_fx, mat_mult_buffer1_e );
3311 :
3312 2100 : matrix_product_mant_exp( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_cov, nY_int, 0,
3313 2100 : hParamMC->ls_conv_dmx_matrix_fx, ls_conv_dmx_matrix_e, nY_cov, nY_int, 1,
3314 : Cy_state_fx, Cy_buf_e );
3315 :
3316 14700 : FOR( k = 0; k < nY_cov; k++ )
3317 : {
3318 113400 : FOR( l = 0; l < nY_int; l++ )
3319 : {
3320 100800 : L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[k + ( l * nY_cov )], Nrqq_fx[l] );
3321 100800 : tmp_e = add( ls_conv_dmx_matrix_e[k + ( l + nY_cov )], Nrqq_e[l] );
3322 100800 : L_tmp = BASOP_Util_Add_Mant32Exp( target_ch_ener_fx[k], target_ch_ener_e[k], L_tmp, tmp_e, &tmp_e );
3323 100800 : target_ch_ener_fx[k] = L_tmp;
3324 100800 : move32();
3325 100800 : target_ch_ener_e[k] = tmp_e;
3326 100800 : move16();
3327 : }
3328 :
3329 12600 : dmx_ch_ener_fx[k] = Cy_state_fx[k + ( nY_cov * k )];
3330 12600 : move32();
3331 :
3332 12600 : IF( dmx_ch_ener_fx[k] < 0 )
3333 : {
3334 0 : Cy_state_fx[k + ( nY_cov * k )] = L_negate( Cy_state_fx[k + ( nY_cov * k )] );
3335 0 : move32();
3336 0 : dmx_ch_ener_fx[k] = L_negate( dmx_ch_ener_fx[k] );
3337 0 : move32();
3338 : }
3339 :
3340 12600 : IF( extract_h( dmx_ch_ener_fx[k] ) == 0 )
3341 : {
3342 1950 : target_ch_ener_fx[k] = 0;
3343 1950 : move32();
3344 1950 : target_ch_ener_e[k] = 0;
3345 1950 : move16();
3346 : }
3347 : ELSE
3348 : {
3349 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 );
3350 10650 : tmp = Sqrt16( tmp, &tmp_e );
3351 10650 : target_ch_ener_fx[k] = L_deposit_h( tmp );
3352 10650 : move32();
3353 10650 : target_ch_ener_e[k] = tmp_e;
3354 10650 : move16();
3355 : }
3356 :
3357 88200 : FOR( l = 0; l < nY_cov; l++ )
3358 : {
3359 75600 : Cy_state_fx[( k * nY_cov ) + l] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[( k * nY_cov ) + l] );
3360 75600 : move32();
3361 75600 : Cy_buf_e[( k * nY_cov ) + l] = add( target_ch_ener_e[k], Cy_buf_e[( k * nY_cov ) + l] );
3362 75600 : move16();
3363 : }
3364 :
3365 12600 : Cyp_fx = Cy_state_fx + k;
3366 12600 : Cyp_e = Cy_buf_e + k;
3367 12600 : ap_fx = target_ch_ener_fx[k];
3368 12600 : move32();
3369 12600 : ap_e = target_ch_ener_e[k];
3370 12600 : move16();
3371 88200 : FOR( l = 0; l < nY_cov; l++ )
3372 : {
3373 75600 : ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx );
3374 75600 : move32();
3375 75600 : *Cyp_e = add( *Cyp_e, ap_e );
3376 75600 : move16();
3377 :
3378 75600 : Cyp_fx += nY_cov;
3379 75600 : Cyp_e += nY_cov;
3380 : }
3381 : }
3382 : }
3383 : ELSE
3384 : {
3385 111020 : Copy32( Cy_state_int_fx, Cy_state_fx, imult1616( nY_int, nY_int ) );
3386 111020 : Copy( Cy_state_int_e, Cy_buf_e, imult1616( nY_int, nY_int ) );
3387 : }
3388 :
3389 : /*normalize output matrix to a common exponent*/
3390 113120 : tmp = 0;
3391 4382560 : FOR( k = 0; k < nY_int * nY_int; k++ )
3392 : {
3393 4269440 : Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] );
3394 4269440 : move32();
3395 4269440 : tmp = s_max( tmp, Cy_buf_e[k] );
3396 : }
3397 4382560 : FOR( k = 0; k < nY_int * nY_int; k++ )
3398 : {
3399 4269440 : L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) );
3400 4269440 : Cy_state_fx[k] = L_tmp;
3401 4269440 : move32();
3402 : }
3403 113120 : *Cy_state_e = tmp;
3404 113120 : move16();
3405 :
3406 113120 : return;
3407 : }
3408 :
3409 : /*-------------------------------------------------------------------------*
3410 : * param_mc_set_num_synth_bands()
3411 : *
3412 : * set the number of frequency bands to be synthesized
3413 : *-------------------------------------------------------------------------*/
3414 :
3415 365 : static void param_mc_set_num_synth_bands(
3416 : const Word32 output_Fs, /* i : output sampling frequency */
3417 : PARAM_MC_DEC_HANDLE hParamMC /* i/o: Parametric MC handle */
3418 : )
3419 : {
3420 : UWord16 max_param_band_synth;
3421 : const Word16 *param_mc_bands_coded;
3422 :
3423 365 : SWITCH( hParamMC->hMetadataPMC->num_parameter_bands )
3424 : {
3425 0 : case 20:
3426 0 : param_mc_bands_coded = param_mc_bands_coded_20;
3427 0 : BREAK;
3428 203 : case 10:
3429 203 : param_mc_bands_coded = param_mc_bands_coded_10;
3430 203 : BREAK;
3431 162 : case 14:
3432 : default:
3433 162 : param_mc_bands_coded = param_mc_bands_coded_14;
3434 162 : BREAK;
3435 : }
3436 365 : move16();
3437 365 : SWITCH( output_Fs )
3438 : {
3439 0 : case 8000:
3440 0 : max_param_band_synth = (UWord16) param_mc_bands_coded[NB];
3441 0 : BREAK;
3442 71 : case 16000:
3443 71 : max_param_band_synth = (UWord16) param_mc_bands_coded[WB];
3444 71 : BREAK;
3445 3 : case 32000:
3446 3 : max_param_band_synth = (UWord16) param_mc_bands_coded[SWB];
3447 3 : BREAK;
3448 291 : case 48000:
3449 : default:
3450 291 : max_param_band_synth = (UWord16) param_mc_bands_coded[FB];
3451 291 : BREAK;
3452 : }
3453 365 : move16();
3454 365 : hParamMC->num_param_bands_synth = s_min( hParamMC->hMetadataPMC->nbands_coded, max_param_band_synth );
3455 365 : move16();
3456 :
3457 365 : return;
3458 : }
3459 :
3460 :
3461 : /*-------------------------------------------------------------------------*
3462 : * param_mc_get_diff_proto_info()
3463 : *
3464 : * calculated the diffuse prototype information
3465 : *-------------------------------------------------------------------------*/
3466 :
3467 :
3468 239 : static ivas_error param_mc_get_diff_proto_info_fx(
3469 : const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */
3470 : const UWord16 nchan_transport, /* i : number of transport channels */
3471 : const UWord16 nchan_out_cov, /* i : number if output channels of the covariance synthesis */
3472 : PARAM_MC_DIFF_PROTO_INFO *p_diff_proto_info, /* o : generated diffuse prototype info */
3473 : Word16 Q_proto_mtx )
3474 : {
3475 : Word32 proto_fac_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS];
3476 : UWord16 cur_out_ch;
3477 : UWord16 cur_diff_proto;
3478 : UWord16 cur_transport_ch;
3479 : UWord16 max_num_src_chan;
3480 :
3481 : /* Initializations */
3482 239 : max_num_src_chan = 0;
3483 239 : move16();
3484 :
3485 239 : set_zero_fx( proto_fac_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS );
3486 239 : IF( ( p_diff_proto_info->proto_index_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
3487 : {
3488 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3489 : }
3490 239 : set16_fx( p_diff_proto_info->proto_index_diff, 0, nchan_out_cov );
3491 :
3492 239 : IF( ( p_diff_proto_info->num_source_chan_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL )
3493 : {
3494 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3495 : }
3496 239 : set16_fx( p_diff_proto_info->num_source_chan_diff, 0, nchan_out_cov );
3497 :
3498 : /* we have at least one prototype, copy the first one */
3499 239 : p_diff_proto_info->num_protos_diff = 1;
3500 239 : move16();
3501 :
3502 239 : mvr2r_inc_fixed( proto_mtx, nchan_out_cov, proto_fac_fx, nchan_out_cov, nchan_transport );
3503 239 : p_diff_proto_info->proto_index_diff[0] = 0;
3504 239 : move16();
3505 :
3506 : /* search for distinct prototypes */
3507 1496 : FOR( cur_out_ch = 1; cur_out_ch < nchan_out_cov; cur_out_ch++ )
3508 : {
3509 1257 : UWord16 found = 0;
3510 1257 : move16();
3511 :
3512 2728 : FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
3513 : {
3514 2248 : Word32 diff_fx = 0;
3515 2248 : move32();
3516 2248 : Word32 *proto_fac_ptr_fx = proto_fac_fx + cur_diff_proto;
3517 2248 : const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
3518 6888 : FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
3519 : {
3520 4640 : diff_fx = L_add( diff_fx, L_abs( L_sub( *proto_fac_ptr_fx, *proto_mtx_ptr ) ) );
3521 4640 : proto_fac_ptr_fx += nchan_out_cov;
3522 4640 : proto_mtx_ptr += nchan_out_cov;
3523 : }
3524 :
3525 : /* we already have this prototype, save the index */
3526 2248 : IF( LT_64( W_mult0_32_32( diff_fx, 10 ), L_shl_sat( 1, Q_proto_mtx ) ) )
3527 : {
3528 777 : found = 1;
3529 777 : move16();
3530 777 : p_diff_proto_info->proto_index_diff[cur_out_ch] = cur_diff_proto;
3531 777 : move16();
3532 777 : BREAK;
3533 : }
3534 : }
3535 :
3536 : /* new distinct prototype, add it */
3537 1257 : IF( found == 0 )
3538 : {
3539 480 : const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch;
3540 : Word16 cur_num_src_chan;
3541 :
3542 480 : cur_num_src_chan = 0;
3543 480 : move16();
3544 1456 : FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
3545 : {
3546 976 : if ( GT_32( *proto_mtx_ptr, 0 /*EPSILON*/ ) )
3547 : {
3548 711 : cur_num_src_chan = add( cur_num_src_chan, 1 );
3549 : }
3550 976 : proto_mtx_ptr += nchan_out_cov;
3551 : }
3552 :
3553 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 );
3554 :
3555 480 : p_diff_proto_info->proto_index_diff[cur_out_ch] = p_diff_proto_info->num_protos_diff;
3556 480 : move16();
3557 480 : p_diff_proto_info->num_protos_diff = add( p_diff_proto_info->num_protos_diff, 1 );
3558 480 : move16();
3559 480 : max_num_src_chan = s_max( max_num_src_chan, cur_num_src_chan );
3560 : }
3561 : }
3562 :
3563 : /* set up the prototype info struct */
3564 239 : IF( ( p_diff_proto_info->source_chan_idx = (Word16 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word16 * ) ) ) == NULL )
3565 : {
3566 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3567 : }
3568 :
3569 239 : IF( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL )
3570 : {
3571 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3572 : }
3573 958 : FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ )
3574 : {
3575 : Word32 *proto_fac_ptr;
3576 :
3577 719 : IF( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (Word16 *) malloc( max_num_src_chan * sizeof( Word16 ) ) ) == NULL )
3578 : {
3579 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3580 : }
3581 :
3582 719 : IF( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL )
3583 : {
3584 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
3585 : }
3586 :
3587 719 : proto_fac_ptr = proto_fac_fx + cur_diff_proto;
3588 2181 : FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ )
3589 : {
3590 1462 : IF( GT_32( *proto_fac_ptr, EPSILON_FX_SMALL ) )
3591 : {
3592 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;
3593 950 : move16();
3594 950 : 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
3595 950 : move16();
3596 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 );
3597 950 : move16();
3598 : }
3599 1462 : proto_fac_ptr += nchan_out_cov;
3600 : }
3601 : }
3602 239 : return IVAS_ERR_OK;
3603 : }
3604 :
3605 :
3606 : /*-------------------------------------------------------------------------*
3607 : * ivas_param_mc_bs_decode_parameter_values()
3608 : *
3609 : * reads and decodes a sequence of Parametric MC parameters from the bitstream
3610 : *-------------------------------------------------------------------------*/
3611 :
3612 17500 : static void ivas_param_mc_bs_decode_parameter_values_fx(
3613 : UWord16 bit_buffer[], /* i : bitstream buffer */
3614 : Word16 *bit_pos, /* i/o: current bitstream buffer position */
3615 : const Word16 max_bits, /* i : maximum available bits in the buffer */
3616 : Word16 *BER_detect, /* i/o: bit error detection flag */
3617 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC, /* i : Parametric MC metadata information */
3618 : HANDLE_PARAM_MC_PARAMETER_CODING_INFO hParamCodingInfo, /* i : Parametric MC parameter quantization and coding tables */
3619 : const Word16 map_size_wo_lfe, /* i : number of parameters per band (w/o LFEs) */
3620 : const Word16 map_size, /* i : number of parameters per band (total) */
3621 : const Word16 num_lfe_bands, /* i : number of parameter bands with coded LFE */
3622 : const Word16 band_step, /* i : parameter band step */
3623 : const Word16 num_param_bands, /* i : number of parameter bands to decode */
3624 : Word16 *value_buffer /* o : output buffer for decoded parameter values hParamCodingInfo -> Q-quant*/
3625 : )
3626 : {
3627 : Word16 range_coding;
3628 : Word16 sz_seq;
3629 : Word16 delta_coding;
3630 : Word16 delta_idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
3631 : Word16 idx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
3632 : Word16 idx_prev;
3633 : Word16 idx_offset;
3634 : Word16 sz_alphabet;
3635 : Word16 i, j, k;
3636 : Word16 dequant_seq_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
3637 : Word16 dequant_ordered_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE];
3638 : Word16 n_lfe_idx;
3639 :
3640 17500 : range_coding = bit_buffer[*bit_pos];
3641 17500 : move16();
3642 17500 : *bit_pos = add( *bit_pos, 1 );
3643 17500 : move16();
3644 :
3645 : /* Decoding the sequence */
3646 17500 : n_lfe_idx = sub( map_size, map_size_wo_lfe );
3647 17500 : sz_seq = add( imult1616( num_param_bands, map_size_wo_lfe ), imult1616( num_lfe_bands, n_lfe_idx ) );
3648 :
3649 17500 : set16_fx( idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
3650 17500 : set16_fx( dequant_ordered_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
3651 17500 : set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
3652 17500 : IF( range_coding )
3653 : {
3654 17107 : delta_coding = bit_buffer[*bit_pos];
3655 17107 : move16();
3656 17107 : *bit_pos = add( *bit_pos, 1 );
3657 17107 : move16();
3658 :
3659 17107 : IF( delta_coding )
3660 : {
3661 16896 : idx_prev = sub( add( shr( hParamCodingInfo->quantizer_size, 1 ), hParamCodingInfo->quantizer_size % 2 ), 1 );
3662 16896 : sz_alphabet = sub( shl( hParamCodingInfo->quantizer_size, 1 ), 1 );
3663 16896 : idx_offset = sub( hParamCodingInfo->quantizer_size, 1 );
3664 :
3665 : /* read range coded delta ICC indices */
3666 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,
3667 16896 : hParamCodingInfo->cum_freq_delta, hParamCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
3668 16896 : move16();
3669 :
3670 : /* delta index to absolute index */
3671 534457 : FOR( j = 0; j < sz_seq; j++ )
3672 : {
3673 517561 : idx[j] = add( idx_prev, sub( delta_idx[j], idx_offset ) );
3674 517561 : idx_prev = idx[j];
3675 517561 : move16();
3676 : }
3677 : }
3678 : ELSE
3679 : {
3680 : /* read range coded absolute ICC indices */
3681 211 : sz_alphabet = hParamCodingInfo->quantizer_size;
3682 211 : move16();
3683 211 : *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], idx, BER_detect, sz_seq, sz_alphabet,
3684 211 : hParamCodingInfo->cum_freq, hParamCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) );
3685 211 : move16();
3686 : }
3687 :
3688 : /* dequantize */
3689 540205 : FOR( j = 0; j < sz_seq; j++ )
3690 : {
3691 523098 : dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; // hParamCodingInfo -> Q-quant
3692 523098 : move16();
3693 : }
3694 : }
3695 : ELSE
3696 : {
3697 393 : set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE );
3698 : /* read uniformly coded ICCs */
3699 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] ) );
3700 393 : move16();
3701 : }
3702 :
3703 : /* reorder from sequential to parameter-band-wise */
3704 17500 : k = 0;
3705 98339 : FOR( j = 0; j < map_size_wo_lfe; ++j )
3706 : {
3707 613108 : FOR( i = 0; i < num_param_bands; ++i )
3708 : {
3709 532269 : dequant_ordered_fx[j + ( i * map_size )] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
3710 532269 : move16();
3711 532269 : k = add( k, 1 );
3712 : }
3713 : }
3714 :
3715 18404 : FOR( i = 0; i < num_lfe_bands; i++ )
3716 : {
3717 1845 : FOR( j = 0; j < n_lfe_idx; j++ )
3718 : {
3719 941 : dequant_ordered_fx[map_size - n_lfe_idx + j + i * map_size] = dequant_seq_fx[k]; // hParamCodingInfo -> Q-quant
3720 941 : move16();
3721 941 : k = add( k, 1 );
3722 : }
3723 : }
3724 :
3725 17500 : IF( !( *BER_detect ) )
3726 : {
3727 17500 : j = 0;
3728 242326 : FOR( k = 0; k < hMetadataPMC->nbands_coded; k += band_step )
3729 : {
3730 224826 : test();
3731 224826 : IF( hMetadataPMC->bAttackPresent || EQ_16( hMetadataPMC->param_frame_idx, hMetadataPMC->coding_band_mapping[k] ) )
3732 : {
3733 115068 : Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); // hParamCodingInfo -> Q-quant
3734 115068 : j++;
3735 : }
3736 224826 : IF( hMetadataPMC->bAttackPresent && k + 1 < hMetadataPMC->nbands_coded )
3737 : {
3738 5166 : Copy( value_buffer + imult1616( k, map_size ), value_buffer + imult1616( add( k, 1 ), map_size ), map_size );
3739 : }
3740 : }
3741 : }
3742 :
3743 17500 : return;
3744 : }
|