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 : /*==================================================================================== 34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 35 : ====================================================================================*/ 36 : 37 : #include <stdint.h> 38 : #include "options.h" 39 : #ifdef DEBUGGING 40 : #include "debug.h" 41 : #endif 42 : #include <math.h> 43 : #include "cnst.h" 44 : #include "prot.h" 45 : #include "rom_com.h" 46 : #include "wmc_auto.h" 47 : 48 : /*--------------------------------------------------------------------------* 49 : * env_stab_transient_detect() 50 : * 51 : * Transient detector for envelope stability measure 52 : *--------------------------------------------------------------------------*/ 53 : 54 4581 : void env_stab_transient_detect( 55 : const int16_t is_transient, /* i : Transient flag */ 56 : const int16_t length, /* i : Length of spectrum (32 or 48 kHz) */ 57 : const int16_t norm[], /* i : quantization indices for norms */ 58 : int16_t *no_att_hangover, /* i/o: Frame counter for attenuation hangover */ 59 : float *energy_lt, /* i/o: Long-term energy measure for transient detection */ 60 : const int16_t HQ_mode, /* i : HQ coding mode */ 61 : const int16_t bin_th, /* i : HVQ cross-over frequency bin */ 62 : const float *coeff /* i : Coded spectral coefficients */ 63 : ) 64 : { 65 : float d_max; 66 : float e_frame; 67 : int16_t blk; 68 : int16_t i; 69 : float E_sub[4]; 70 : float delta_e_sub; 71 : int16_t norm_ind; 72 : 73 4581 : int16_t num_subframes = 4; 74 4581 : int16_t bands_per_subframe = 9; 75 : 76 4581 : if ( HQ_mode == HQ_HVQ ) 77 : { 78 543 : e_frame = 0.0f; 79 : 80 123903 : for ( i = 0; i < bin_th; i++ ) 81 : { 82 123360 : e_frame += coeff[i] * coeff[i]; 83 : } 84 : 85 543 : e_frame = (float) sqrt( e_frame / bin_th ); 86 : 87 543 : if ( e_frame > ENERGY_TH ) 88 : { 89 543 : *energy_lt = ENERGY_LT_BETA * ( *energy_lt ) + ( 1 - ENERGY_LT_BETA ) * e_frame; 90 : } 91 : 92 543 : if ( *no_att_hangover > 0 ) 93 : { 94 0 : ( *no_att_hangover )--; 95 : } 96 : } 97 : else 98 : { 99 4038 : d_max = 0.0f; 100 4038 : e_frame = 0.0f; 101 4038 : if ( is_transient && length == L_FRAME32k ) 102 : { 103 : /* Measure subframe energies */ 104 1920 : for ( blk = 0; blk < num_subframes; blk++ ) 105 : { 106 1536 : E_sub[blk] = 0.0f; 107 15360 : for ( i = 0; i < bands_per_subframe; i++ ) 108 : { 109 13824 : norm_ind = subf_norm_groups[blk][i]; 110 13824 : E_sub[blk] += dicn[norm[norm_ind]]; 111 : } 112 1536 : E_sub[blk] = E_sub[blk] / bands_per_subframe; 113 1536 : e_frame += E_sub[blk]; 114 : } 115 : /* Test for transient */ 116 384 : if ( e_frame > ENERGY_TH * num_subframes ) 117 : { 118 528 : for ( blk = 0; blk < num_subframes - 1; blk++ ) 119 : { 120 396 : delta_e_sub = ( E_sub[blk + 1] - E_sub[blk] ) / *energy_lt; 121 396 : if ( delta_e_sub > d_max ) 122 : { 123 144 : d_max = delta_e_sub; 124 : } 125 : } 126 : } 127 : } 128 : else 129 : { 130 : /* Update long-term energy measure */ 131 3654 : e_frame = 0.0f; 132 : 133 102312 : for ( i = 0; i < SFM_N_ENV_STAB; i++ ) 134 : { 135 98658 : e_frame += dicn[norm[i]]; 136 : } 137 : 138 3654 : e_frame = e_frame / SFM_N_ENV_STAB; 139 : 140 3654 : if ( e_frame > ENERGY_TH ) 141 : { 142 2073 : *energy_lt = ENERGY_LT_BETA * ( *energy_lt ) + ( 1 - ENERGY_LT_BETA ) * e_frame; 143 : } 144 : } 145 : 146 : /* Add hang-over for conservative application of stability-dependent attenuation */ 147 4038 : if ( d_max > DELTA_TH ) 148 : { 149 0 : *no_att_hangover = ATT_LIM_HANGOVER; 150 : } 151 4038 : else if ( *no_att_hangover > 0 ) 152 : { 153 0 : ( *no_att_hangover )--; 154 : } 155 : } 156 : 157 4581 : return; 158 : }