Line data Source code
1 : /****************************************************************************************************** 2 : 3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, 4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., 5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, 6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other 7 : contributors to this repository. All Rights Reserved. 8 : 9 : This software is protected by copyright law and by international treaties. 10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, 11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., 12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, 13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other 14 : contributors to this repository retain full ownership rights in their respective contributions in 15 : the software. This notice grants no license of any kind, including but not limited to patent 16 : license, nor is any license granted by implication, estoppel or otherwise. 17 : 18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making 19 : contributions. 20 : 21 : This software is provided "AS IS", without any express or implied warranties. The software is in the 22 : development stage. It is intended exclusively for experts who have experience with such software and 23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability 24 : and fitness for a particular purpose are hereby disclaimed and excluded. 25 : 26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be 27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in 28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and 29 : the United Nations Convention on Contracts on the International Sales of Goods. 30 : 31 : *******************************************************************************************************/ 32 : 33 : #include <assert.h> 34 : #include <stdint.h> 35 : #include <math.h> 36 : #include "options.h" 37 : #include "ivas_cnst.h" 38 : #include "prot.h" 39 : #include "ivas_prot.h" 40 : #include "ivas_stat_com.h" 41 : #include "ivas_rom_com.h" 42 : #ifdef DEBUGGING 43 : #include "debug.h" 44 : #endif 45 : #include "wmc_auto.h" 46 : 47 : 48 : /*------------------------------------------------------------------------- 49 : * Local function prototypes 50 : *------------------------------------------------------------------------*/ 51 : 52 : static void ivas_param_mc_set_coding_scheme( const MC_LS_SETUP mc_ls_setup, const int32_t ivas_total_brate, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC ); 53 : 54 : 55 : /*------------------------------------------------------------------------- 56 : * ivas_param_mc_get_configuration_index() 57 : * 58 : * 59 : *------------------------------------------------------------------------*/ 60 : 61 4145 : uint16_t ivas_param_mc_get_configuration_index( 62 : const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ 63 : const int32_t ivas_total_brate /* i : IVAS total bitrate */ 64 : ) 65 : { 66 : uint16_t cur_idx; 67 : 68 10721 : for ( cur_idx = 0; cur_idx < PARAM_MC_NUM_CONFIGS; cur_idx++ ) 69 : { 70 10721 : if ( ivas_param_mc_conf[cur_idx].mc_ls_setup == mc_ls_setup && ivas_param_mc_conf[cur_idx].ivas_total_brate == ivas_total_brate ) 71 : { 72 4145 : return cur_idx; 73 : } 74 : } 75 : #ifdef DEBUGGING 76 : assert( 0 && "No Parametric MC configuration for this bitrate/channel setup!" ); 77 : #endif 78 0 : return PARAM_MC_NUM_CONFIGS; 79 : } 80 : 81 : 82 : /*------------------------------------------------------------------------- 83 : * ivas_param_mc_metadata_open() 84 : * 85 : * Parametric MC parameter coding state open function 86 : *------------------------------------------------------------------------*/ 87 : 88 1376 : void ivas_param_mc_metadata_open( 89 : const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ 90 : const int32_t ivas_total_brate, /* i : IVAS total bitrate */ 91 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o : handle for the Parametric MC parameter coding state */ 92 : ) 93 : { 94 : uint16_t config_index; 95 : 96 : /* get coding band mappings */ 97 1376 : set_s( hMetadataPMC->coding_band_mapping, 0, PARAM_MC_MAX_PARAMETER_BANDS ); 98 : 99 : /* set coding scheme */ 100 1376 : ivas_param_mc_set_coding_scheme( mc_ls_setup, ivas_total_brate, hMetadataPMC ); 101 : 102 : /* get configuration index */ 103 1376 : config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); 104 1376 : if ( config_index == PARAM_MC_NUM_CONFIGS ) 105 : { 106 0 : assert( 0 && "ParamMC configuration index not found!" ); 107 : } 108 : 109 : /* Band Grouping */ 110 1376 : if ( hMetadataPMC->num_parameter_bands == 20 ) 111 : { 112 12 : mvs2s( param_mc_coding_band_mapping_20, hMetadataPMC->coding_band_mapping, 20 ); 113 : } 114 1364 : else if ( hMetadataPMC->num_parameter_bands == 14 ) 115 : { 116 676 : mvs2s( param_mc_coding_band_mapping_14, hMetadataPMC->coding_band_mapping, 14 ); 117 : } 118 688 : else if ( hMetadataPMC->num_parameter_bands == 10 ) 119 : { 120 688 : mvs2s( param_mc_coding_band_mapping_10, hMetadataPMC->coding_band_mapping, 10 ); 121 : } 122 : else 123 : { 124 0 : assert( 0 && "nbands must be 20 or 14!" ); 125 : } 126 : 127 1376 : hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf; 128 1376 : hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf; 129 1376 : hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors; 130 : 131 : /* init remaining flags and indices */ 132 1376 : hMetadataPMC->param_frame_idx = 0; 133 1376 : hMetadataPMC->bAttackPresent = 0; 134 1376 : hMetadataPMC->attackIndex = 0; 135 1376 : hMetadataPMC->lfe_on = 1; 136 : 137 : /* set coded bwidth to FB at the beginning */ 138 1376 : hMetadataPMC->coded_bwidth = FB; 139 1376 : hMetadataPMC->last_coded_bwidth = FB; 140 : 141 1376 : ivas_param_mc_set_coded_bands( hMetadataPMC ); 142 : 143 1376 : return; 144 : } 145 : 146 : 147 : /*------------------------------------------------------------------------- 148 : * ivas_param_mc_set_coded_bands() 149 : * 150 : * Parametric MC: set number of actually coded parameters bands based on the 151 : * coded band width 152 : *------------------------------------------------------------------------*/ 153 : 154 1978 : void ivas_param_mc_set_coded_bands( 155 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */ 156 : ) 157 : { 158 : int16_t i; 159 : 160 : /* set number of coded bands*/ 161 1978 : switch ( hMetadataPMC->num_parameter_bands ) 162 : { 163 15 : case 20: 164 15 : hMetadataPMC->nbands_coded = param_mc_bands_coded_20[hMetadataPMC->coded_bwidth]; 165 15 : break; 166 971 : case 14: 167 971 : hMetadataPMC->nbands_coded = param_mc_bands_coded_14[hMetadataPMC->coded_bwidth]; 168 971 : break; 169 992 : case 10: 170 992 : hMetadataPMC->nbands_coded = param_mc_bands_coded_10[hMetadataPMC->coded_bwidth]; 171 : } 172 : 173 : /* set number of bands per parameter frame set */ 174 5934 : for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ ) 175 : { 176 3956 : hMetadataPMC->nbands_in_param_frame[i] = 0; 177 : } 178 : 179 25380 : for ( i = 0; i < hMetadataPMC->nbands_coded; i++ ) 180 : { 181 23402 : hMetadataPMC->nbands_in_param_frame[hMetadataPMC->coding_band_mapping[i]]++; 182 : } 183 : 184 1978 : return; 185 : } 186 : 187 : 188 : /*------------------------------------------------------------------------- 189 : * ivas_param_mc_getNumTransportChannels() 190 : * 191 : * 192 : *------------------------------------------------------------------------*/ 193 : 194 : /* r : number of IVAS transport channels */ 195 1393 : int16_t ivas_param_mc_getNumTransportChannels( 196 : const int32_t ivas_total_bitrate, /* i : IVAS total bitrate */ 197 : const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ 198 : ) 199 : { 200 : int16_t nchan_transport; 201 : int16_t config_index; 202 : 203 1393 : config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_bitrate ); 204 : 205 1393 : nchan_transport = ivas_param_mc_conf[config_index].num_transport_chan; 206 : 207 1393 : return nchan_transport; 208 : } 209 : 210 : 211 : /*------------------------------------------------------------------------- 212 : * ivas_param_mc_get_num_param_bands() 213 : * 214 : * 215 : *------------------------------------------------------------------------*/ 216 : 217 1376 : static int16_t ivas_param_mc_get_num_param_bands( 218 : const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ 219 : const int32_t ivas_total_brate /* i : IVAS total bitrate */ 220 : ) 221 : { 222 : int16_t num_parameter_bands; 223 : 224 1376 : num_parameter_bands = 0; 225 : 226 : /* parameter bands */ 227 1376 : switch ( mc_ls_setup ) 228 : { 229 1224 : case MC_LS_SETUP_5_1: 230 : switch ( ivas_total_brate ) 231 : { 232 668 : case IVAS_48k: 233 668 : num_parameter_bands = 10; 234 668 : break; 235 556 : case IVAS_64k: 236 : case IVAS_80k: 237 556 : num_parameter_bands = 14; 238 556 : break; 239 0 : default: 240 0 : assert( 0 && "PARAM_MC: bitrate for CICP6 not supported!" ); 241 : } 242 1224 : break; 243 : 244 52 : case MC_LS_SETUP_7_1: 245 : switch ( ivas_total_brate ) 246 : { 247 12 : case IVAS_48k: 248 12 : num_parameter_bands = 10; 249 12 : break; 250 32 : case IVAS_64k: 251 : case IVAS_80k: 252 32 : num_parameter_bands = 14; 253 32 : break; 254 8 : case IVAS_96k: 255 8 : num_parameter_bands = 20; 256 8 : break; 257 : } 258 52 : break; 259 44 : case MC_LS_SETUP_5_1_2: 260 : switch ( ivas_total_brate ) 261 : { 262 8 : case IVAS_48k: 263 8 : num_parameter_bands = 10; 264 8 : break; 265 32 : case IVAS_64k: 266 : case IVAS_80k: 267 32 : num_parameter_bands = 14; 268 32 : break; 269 4 : case IVAS_96k: 270 4 : num_parameter_bands = 20; 271 4 : break; 272 : } 273 44 : break; 274 0 : case MC_LS_SETUP_5_1_4: 275 : switch ( ivas_total_brate ) 276 : { 277 0 : case IVAS_96k: 278 0 : num_parameter_bands = 14; 279 0 : break; 280 0 : case IVAS_128k: 281 0 : num_parameter_bands = 20; 282 0 : break; 283 : } 284 0 : break; 285 56 : case MC_LS_SETUP_7_1_4: 286 : switch ( ivas_total_brate ) 287 : { 288 56 : case IVAS_128k: 289 56 : num_parameter_bands = 14; 290 56 : break; 291 : } 292 56 : break; 293 0 : default: 294 0 : assert( 0 && "PARAM_MC: channel configuration not supportet!" ); 295 : } 296 : 297 1376 : return num_parameter_bands; 298 : } 299 : 300 : 301 : /*------------------------------------------------------------------------- 302 : * Local functions 303 : *------------------------------------------------------------------------*/ 304 : 305 : /*------------------------------------------------------------------------- 306 : * ivas_param_mc_set_coding_scheme() 307 : * 308 : * set Parametric MC parameter coding tables based on format and bitrate 309 : *------------------------------------------------------------------------*/ 310 : 311 1376 : static void ivas_param_mc_set_coding_scheme( 312 : const MC_LS_SETUP mc_ls_setup, /* i : MC ls setup */ 313 : const int32_t ivas_total_brate, /* i : IVAS total bitrate */ 314 : HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: Parametric MC metadata handle */ 315 : ) 316 : { 317 : /* quantizer and coding tables */ 318 1376 : switch ( mc_ls_setup ) 319 : { 320 1224 : case MC_LS_SETUP_5_1: 321 : /* ICC */ 322 1224 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp6_48_16bits[0]; 323 1224 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0]; 324 1224 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0]; 325 1224 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0]; 326 1224 : hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; 327 1224 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; 328 1224 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; 329 : /* ILD */ 330 1224 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp6_48_16bits[0]; 331 1224 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0]; 332 1224 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0]; 333 1224 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0]; 334 1224 : hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; 335 1224 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; 336 1224 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; 337 1224 : break; 338 52 : case MC_LS_SETUP_7_1: 339 : /* ICC */ 340 52 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp12_48_16bits[0]; 341 52 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0]; 342 52 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0]; 343 52 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0]; 344 52 : hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; 345 52 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; 346 52 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; 347 : /* ILD */ 348 52 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp12_48_16bits[0]; 349 52 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0]; 350 52 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0]; 351 52 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0]; 352 52 : hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; 353 52 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; 354 52 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; 355 52 : break; 356 44 : case MC_LS_SETUP_5_1_2: 357 : /* ICC */ 358 44 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp14_48_16bits[0]; 359 44 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0]; 360 44 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0]; 361 44 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0]; 362 44 : hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; 363 44 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; 364 44 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; 365 : /* ILD */ 366 44 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp14_48_16bits[0]; 367 44 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0]; 368 44 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0]; 369 44 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0]; 370 44 : hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; 371 44 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; 372 44 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; 373 44 : break; 374 56 : case MC_LS_SETUP_5_1_4: 375 : case MC_LS_SETUP_7_1_4: 376 : /* ICC */ 377 56 : hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_combined_48_16bits[0]; 378 56 : hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0]; 379 56 : hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0]; 380 56 : hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0]; 381 56 : hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; 382 56 : hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; 383 56 : hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; 384 : /* ILD */ 385 56 : hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_combined_48_16bits[0]; 386 56 : hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0]; 387 56 : hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0]; 388 56 : hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0]; 389 56 : hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; 390 56 : hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; 391 56 : hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; 392 56 : break; 393 0 : default: 394 0 : assert( 0 && "PARAM_MC: channel configuration not supported!" ); 395 : } 396 : 397 1376 : hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands( mc_ls_setup, ivas_total_brate ); 398 : 399 1376 : return; 400 : }