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 <assert.h> 38 : #include <stdint.h> 39 : #include "options.h" 40 : #include <math.h> 41 : #include "prot.h" 42 : #include "wmc_auto.h" 43 : 44 : /*-------------------------------------------------------------------* 45 : * spec_flatness() 46 : * 47 : * 48 : *-------------------------------------------------------------------*/ 49 : 50 3100 : void spec_flatness( 51 : float spec_amp[], /* i : spectral amplitude */ 52 : float smooth_spec_amp[], /* i : smoothed spectral amplitude */ 53 : float sSFM[] /* o : spectral flatness rate */ 54 : ) 55 : { 56 : int16_t i; 57 : double prods, sums; 58 : float SFM; 59 : 60 189100 : for ( i = MIN_AMP_ID; i <= MAX_AMP_ID; i++ ) 61 : { 62 186000 : smooth_spec_amp[i - MIN_AMP_ID] = smooth_spec_amp[i - MIN_AMP_ID] * 0.7f + spec_amp[i] * 0.3f; 63 : } 64 : 65 : /* sSFM1 */ 66 3100 : prods = 1; 67 3100 : sums = 0; 68 : assert( MIN_AMP_ID <= 5 ); 69 49600 : for ( i = ( 5 - MIN_AMP_ID ); i < ( 20 - MIN_AMP_ID ); i++ ) 70 : { 71 46500 : prods = smooth_spec_amp[i] * prods; 72 46500 : sums = sums + smooth_spec_amp[i]; 73 : } 74 : 75 3100 : if ( prods > 0 ) 76 : { 77 3100 : prods = pow( prods, 1.0 / 15 ); 78 : } 79 : else 80 : { 81 0 : prods = 0; 82 : } 83 3100 : sums = sums / 15; 84 : 85 3100 : SFM = (float) ( ( prods + 3276.8f ) / ( sums + 3276.8f ) ); 86 3100 : sSFM[0] = 0.85f * sSFM[0] + 0.15f * SFM; 87 : 88 : /* sSFM2 */ 89 3100 : prods = 1; 90 3100 : sums = 0; 91 65100 : for ( i = ( 20 - MIN_AMP_ID ); i < ( 40 - MIN_AMP_ID ); i++ ) 92 : { 93 62000 : prods = smooth_spec_amp[i] * prods; 94 62000 : sums = sums + smooth_spec_amp[i]; 95 : } 96 : 97 3100 : if ( prods > 0 ) 98 : { 99 3100 : prods = pow( prods, 1.0 / 20 ); 100 : } 101 : else 102 : { 103 0 : prods = 0; 104 : } 105 3100 : sums = sums / 20; 106 3100 : SFM = (float) ( ( prods + 3276.8f ) / ( sums + 3276.8f ) ); 107 3100 : sSFM[1] = 0.85f * sSFM[1] + 0.15f * SFM; 108 : /* sSFM3 */ 109 3100 : prods = 1; 110 3100 : sums = 0; 111 80600 : for ( i = ( 40 - MIN_AMP_ID ); i <= ( MAX_AMP_ID - MIN_AMP_ID ); i++ ) 112 : { 113 77500 : prods = smooth_spec_amp[i] * prods; 114 77500 : sums = sums + smooth_spec_amp[i]; 115 : } 116 : 117 3100 : if ( prods > 0 ) 118 : { 119 3100 : prods = pow( prods, 0.04 ); 120 : } 121 : else 122 : { 123 0 : prods = 0; 124 : } 125 3100 : sums = sums / 25; 126 3100 : SFM = (float) ( ( prods + 3276.8f ) / ( sums + 3276.8f ) ); 127 3100 : sSFM[2] = 0.85f * sSFM[2] + 0.15f * SFM; 128 : 129 : 130 3100 : return; 131 : }