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 "cnst.h" 36 : #include "ivas_cnst.h" 37 : #include "ivas_prot.h" 38 : #ifdef DEBUGGING 39 : #include "debug.h" 40 : #endif 41 : #include <math.h> 42 : #include "wmc_auto.h" 43 : #include "prot.h" 44 : 45 : /*------------------------------------------------------------------------------------------* 46 : * Local constants 47 : *------------------------------------------------------------------------------------------*/ 48 : 49 : #define SQRKMAX ( 1.5f ) 50 : #define NBITS_DIFFG ( 2 ) 51 : #define DBSTEP ( -6.f ) /* desired dB step value in dB*/ 52 : #define ABS_EMIN_MAX ( 3 ) 53 : #define MAXATTEXP ( 1 ) /* the desired maximum attenuation exponent range per frame*/ 54 : 55 : /*-----------------------------------------------------------------------------------------* 56 : * Function ivas_agc_initWindowFunc() 57 : * 58 : * Get a window function 59 : *-----------------------------------------------------------------------------------------*/ 60 : 61 5475 : void ivas_agc_initWindowFunc( 62 : float *pWinFunc, 63 : const int16_t length ) 64 : { 65 : int16_t i; 66 : float N; 67 : float a; 68 : 69 5475 : N = (float) ( length - 1 ); 70 5475 : a = 0.5f * ( 1.f - powf( 10.f, DBSTEP / 20.f ) ); 71 : 72 1825635 : for ( i = 0; i < length; i++ ) 73 : { 74 1820160 : pWinFunc[i] = 1.f + a * ( cosf( EVS_PI * i / N ) - 1.f ); 75 : } 76 : 77 5475 : return; 78 : } 79 : 80 : /*-----------------------------------------------------------------------------------------* 81 : * Function ivas_agc_calcGainParams() 82 : * 83 : * Calculate gain parameters 84 : *-----------------------------------------------------------------------------------------*/ 85 : 86 5475 : void ivas_agc_calcGainParams( 87 : uint16_t *absEmin, 88 : uint16_t *betaE, 89 : uint16_t *maxAttExp, 90 : const int16_t numCoeffs ) 91 : { 92 : int16_t totExp; 93 : int16_t Bm; 94 : int16_t nbits; 95 : 96 5475 : nbits = NBITS_DIFFG; 97 : 98 5475 : *absEmin = max( ABS_EMIN_MAX, (uint16_t) ceilf( logf( ceilf( SQRKMAX * numCoeffs ) ) * INV_LOG_2 ) ); 99 : 100 5475 : totExp = *absEmin + AGC_EMAX + 1; 101 5475 : *betaE = (uint16_t) ceilf( logf( totExp ) * INV_LOG_2 ); 102 : 103 5475 : Bm = (uint16_t) ceilf( logf( ( AGC_EMAX + 1 + 1 ) ) * INV_LOG_2 ); 104 : 105 5475 : if ( nbits > 0 ) 106 : { 107 5475 : Bm = min( AGC_BITS_PER_CH - 1, NBITS_DIFFG ); 108 : } 109 : 110 5475 : *maxAttExp = ( (uint16_t) powf( 2, Bm ) ) - 2; 111 5475 : *maxAttExp = min( MAXATTEXP, *maxAttExp ); 112 : 113 5475 : return; 114 : } 115 : 116 : #ifdef DEBUG_AGC 117 : /*-----------------------------------------------------------------------------------------* 118 : * Function ivas_agc_debug_inout() 119 : * 120 : * 121 : *-----------------------------------------------------------------------------------------*/ 122 : int16_t ivas_agc_debug_inout( FILE *inStream, float **in, int16_t n_channels, int16_t frame_len ) 123 : { 124 : if ( inStream == NULL ) 125 : { 126 : return TRUE; 127 : } 128 : 129 : for ( int16_t i = 0; i < n_channels; i++ ) 130 : { 131 : fwrite( &in[i][0], sizeof( float ), frame_len, inStream ); 132 : } 133 : 134 : return FALSE; 135 : } 136 : #endif