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 41165 : 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 41165 : int16_t num_subframes = 4; 74 41165 : int16_t bands_per_subframe = 9; 75 : 76 41165 : if ( HQ_mode == HQ_HVQ ) 77 : { 78 9007 : e_frame = 0.0f; 79 : 80 2171055 : for ( i = 0; i < bin_th; i++ ) 81 : { 82 2162048 : e_frame += coeff[i] * coeff[i]; 83 : } 84 : 85 9007 : e_frame = (float) sqrt( e_frame / bin_th ); 86 : 87 9007 : if ( e_frame > ENERGY_TH ) 88 : { 89 8706 : *energy_lt = ENERGY_LT_BETA * ( *energy_lt ) + ( 1 - ENERGY_LT_BETA ) * e_frame; 90 : } 91 : 92 9007 : if ( *no_att_hangover > 0 ) 93 : { 94 0 : ( *no_att_hangover )--; 95 : } 96 : } 97 : else 98 : { 99 32158 : d_max = 0.0f; 100 32158 : e_frame = 0.0f; 101 32158 : if ( is_transient && length == L_FRAME32k ) 102 : { 103 : /* Measure subframe energies */ 104 8745 : for ( blk = 0; blk < num_subframes; blk++ ) 105 : { 106 6996 : E_sub[blk] = 0.0f; 107 69960 : for ( i = 0; i < bands_per_subframe; i++ ) 108 : { 109 62964 : norm_ind = subf_norm_groups[blk][i]; 110 62964 : E_sub[blk] += dicn[norm[norm_ind]]; 111 : } 112 6996 : E_sub[blk] = E_sub[blk] / bands_per_subframe; 113 6996 : e_frame += E_sub[blk]; 114 : } 115 : /* Test for transient */ 116 1749 : if ( e_frame > ENERGY_TH * num_subframes ) 117 : { 118 3644 : for ( blk = 0; blk < num_subframes - 1; blk++ ) 119 : { 120 2733 : delta_e_sub = ( E_sub[blk + 1] - E_sub[blk] ) / *energy_lt; 121 2733 : if ( delta_e_sub > d_max ) 122 : { 123 1305 : d_max = delta_e_sub; 124 : } 125 : } 126 : } 127 : } 128 : else 129 : { 130 : /* Update long-term energy measure */ 131 30409 : e_frame = 0.0f; 132 : 133 851452 : for ( i = 0; i < SFM_N_ENV_STAB; i++ ) 134 : { 135 821043 : e_frame += dicn[norm[i]]; 136 : } 137 : 138 30409 : e_frame = e_frame / SFM_N_ENV_STAB; 139 : 140 30409 : if ( e_frame > ENERGY_TH ) 141 : { 142 21167 : *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 32158 : if ( d_max > DELTA_TH ) 148 : { 149 1 : *no_att_hangover = ATT_LIM_HANGOVER; 150 : } 151 32157 : else if ( *no_att_hangover > 0 ) 152 : { 153 150 : ( *no_att_hangover )--; 154 : } 155 : } 156 : 157 41165 : return; 158 : }