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 <stdint.h> 34 : #include "options.h" 35 : #include <math.h> 36 : #include "ivas_prot_fx.h" 37 : #include "ivas_cnst.h" 38 : #include <assert.h> 39 : #include "prot_fx.h" 40 : #include "wmc_auto.h" 41 : 42 : /*--------------------------------------------------------------- 43 : * ECSQ_init_instance_fx() 44 : * 45 : * initialize the encoder or decoder instance ecsq_inst, using the configuration index config_index; 46 : * ac_handle is a pointer to a structure containing the bitstream writer and the arithmetic coding state; 47 : * the return value is the approximate number of bits written, expressed in 22Q10 fixed-point representation 48 : * ---------------------------------------------------------------*/ 49 : 50 33781 : void ECSQ_init_instance_fx( 51 : ECSQ_instance *ecsq_inst, 52 : const Word16 config_index, 53 : void *ac_handle ) 54 : { 55 33781 : ecsq_inst->config_index = config_index; 56 33781 : move16(); 57 33781 : ecsq_inst->encoding_active = 1; 58 33781 : move16(); 59 33781 : ecsq_inst->bit_count_estimate = 0; 60 33781 : move32(); 61 33781 : ecsq_inst->ac_handle = ac_handle; 62 : 63 33781 : return; 64 : } 65 : 66 : /*--------------------------------------------------------------- 67 : * ECSQ_dequantize_gain_fx() 68 : * 69 : * dequantize global gain index 70 : * ---------------------------------------------------------------*/ 71 : 72 60195 : Word32 ECSQ_dequantize_gain_fx( 73 : const Word16 index ) 74 : { 75 : Word32 global_gain; 76 : Word32 L_tmp, L_prod; 77 60195 : Word16 gg_e, tmp_e = 16; 78 60195 : move16(); 79 : 80 : /* pow(10.0, index * ECLVQ_INV_GLOBAL_GAIN_FACTOR) = pow(2.0,(index * ECLVQ_INV_GLOBAL_GAIN_FACTOR)*3.321928 */ 81 60195 : L_prod = Mpy_32_16_1( ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24, shl( index, 8 ) ); /* Q17 */ 82 60195 : L_tmp = Mpy_32_16_1( L_prod, 27213 /*3.321928 q13*/ ); /* Q17 + Q13 >> 15 => Q15 */ 83 : 84 60195 : global_gain = BASOP_util_Pow2( L_tmp, tmp_e, &gg_e ); // 31-gg_e 85 60195 : gg_e = sub( 16, gg_e ); 86 : 87 60195 : global_gain = L_shr( global_gain, gg_e ); // q15 88 : 89 60195 : return global_gain; 90 : } 91 : 92 : /*--------------------------------------------------------------- 93 : * ECSQ_dequantize_vector_fx() 94 : * 95 : * dequantize an integer-valued vector using optimal reconstruction points, which depend on the value of config_index 96 : * ---------------------------------------------------------------*/ 97 : 98 16373 : void ECSQ_dequantize_vector_fx( 99 : const Word16 *input, /*qx*/ 100 : const Word32 global_gain, /*q15*/ 101 : const Word16 N, 102 : Word32 *output /*qx*/ 103 : ) 104 : { 105 : Word16 i; 106 : 107 671293 : FOR( i = 0; i < N; ++i ) 108 : { 109 654920 : output[i] = Mpy_32_16_1( global_gain, input[i] ); /*qx+q15-15->qx*/ 110 654920 : move32(); 111 : } 112 : 113 16373 : return; 114 : }