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.h" 37 : #include "ivas_cnst.h" 38 : #include <assert.h> 39 : #include "prot.h" 40 : #include "wmc_auto.h" 41 : 42 : /*--------------------------------------------------------------- 43 : * ECSQ_init_instance() 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 66226 : void ECSQ_init_instance( 51 : ECSQ_instance *ecsq_inst, 52 : const int16_t config_index, 53 : void *ac_handle ) 54 : { 55 66226 : ecsq_inst->config_index = config_index; 56 66226 : ecsq_inst->encoding_active = 1; 57 66226 : ecsq_inst->bit_count_estimate = 0; 58 66226 : ecsq_inst->ac_handle = ac_handle; 59 : 60 66226 : return; 61 : } 62 : 63 : /*--------------------------------------------------------------- 64 : * ECSQ_dequantize_gain() 65 : * 66 : * dequantize global gain index 67 : * ---------------------------------------------------------------*/ 68 : 69 93702 : float ECSQ_dequantize_gain( 70 : const int16_t index ) 71 : { 72 : float global_gain; 73 : #ifdef DEBUGGING 74 : assert( ( index >= 0 ) && ( index <= 126 ) ); 75 : #endif 76 : 77 93702 : global_gain = powf( 10.0f, (float) index * ECLVQ_INV_GLOBAL_GAIN_FACTOR ); 78 : 79 93702 : return global_gain; 80 : } 81 : 82 : /*--------------------------------------------------------------- 83 : * ECSQ_dequantize_vector() 84 : * 85 : * dequantize an integer-valued vector using optimal reconstruction points, which depend on the value of config_index 86 : * ---------------------------------------------------------------*/ 87 : 88 48828 : void ECSQ_dequantize_vector( 89 : const int16_t *input, 90 : const float global_gain, 91 : const int16_t N, 92 : float *output ) 93 : { 94 : int16_t i; 95 : #ifdef DEBUGGING 96 : assert( N > 0 ); 97 : assert( global_gain > 0.0f ); 98 : #endif 99 : 100 2001948 : for ( i = 0; i < N; ++i ) 101 : { 102 1953120 : output[i] = (float) input[i] * global_gain; 103 : } 104 : 105 48828 : return; 106 : }