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 "cnst.h"
43 : #include "rom_com.h"
44 : #include "prot.h"
45 : #include "wmc_auto.h"
46 :
47 : /*--------------------------------------------------------------------------*
48 : * env_adj()
49 : *
50 : * Adjust the band energies of noise-fill and low resolution bands
51 : *--------------------------------------------------------------------------*/
52 :
53 80009 : void env_adj(
54 : const int16_t *pulses, /* i : number of pulses per band */
55 : const int16_t length, /* i : length of spectrum */
56 : const int16_t last_sfm, /* i : index of the last band */
57 : float *adj, /* o : adjustment factors for the envelope */
58 : const float env_stab, /* i : Envelope stability parameter */
59 : const int16_t *sfmsize /* i : Band widths */
60 : )
61 : {
62 : int16_t i, j, group;
63 : int16_t npul;
64 : int16_t att_state;
65 : int16_t start, len;
66 : float tmp;
67 : float gain_adj;
68 : int16_t idx;
69 :
70 80009 : att_state = 0;
71 80009 : len = 0;
72 80009 : start = 0;
73 :
74 : /* Find attenuation levels */
75 2318550 : for ( i = 0; i <= last_sfm; i++ )
76 : {
77 2238541 : group = ( sfmsize[i] >> 3 ) - 1;
78 2238541 : npul = pulses[i];
79 :
80 2238541 : if ( length == L_FRAME32k )
81 : {
82 1399301 : if ( npul == 0 )
83 : {
84 : /* Noise filled band */
85 406639 : if ( group <= 1 )
86 : {
87 320388 : if ( i > 0 && pulses[i - 1] != 0 && pulses[i + 1] != 0 )
88 : {
89 54342 : adj[i] = 0.36f;
90 : }
91 266046 : else if ( i > 0 && ( pulses[i - 1] == 0 || pulses[i + 1] == 0 ) )
92 : {
93 263624 : adj[i] = 0.54f;
94 : }
95 : else
96 : {
97 2422 : adj[i] = 0.72f;
98 : }
99 : }
100 86251 : else if ( i < last_sfm )
101 : {
102 69473 : if ( pulses[i - 1] != 0 && pulses[i + 1] != 0 )
103 : {
104 6720 : adj[i] = 0.54f;
105 : }
106 : else
107 : {
108 62753 : adj[i] = 0.72f;
109 : }
110 : }
111 : else
112 : {
113 16778 : adj[i] = 0.72f;
114 : }
115 :
116 406639 : if ( att_state == 0 )
117 : {
118 132453 : start = i;
119 : }
120 :
121 406639 : len++;
122 406639 : att_state = 1;
123 : }
124 : else
125 : {
126 992662 : adj[i] = 1.0f;
127 992662 : if ( att_state == 1 ) /* End of attenuation region found */
128 : {
129 115675 : tmp = min( 1, max( 0, len - ENV_ADJ_START ) * ( 1.0f / ENV_ADJ_INCL ) );
130 408803 : for ( j = start; j < i; j++ )
131 : {
132 293128 : adj[j] = max( tmp + ( 1 - tmp ) * adj[j], env_stab );
133 : }
134 115675 : len = 0;
135 115675 : att_state = 0;
136 : }
137 : }
138 : }
139 : /* length == L_FRAME16k */
140 : else
141 : {
142 : /* Calculate low accuracy band attenuation */
143 839240 : gain_adj = 1.0f;
144 839240 : if ( npul > 0 && npul < MAX_P_ATT )
145 : {
146 695687 : idx = (int16_t) ( npul * att_step[group] + 0.5f ) - 1;
147 695687 : if ( idx < MAX_P_ATT )
148 : {
149 574233 : gain_adj = gain_att[idx];
150 : }
151 : }
152 839240 : adj[i] = gain_adj;
153 : }
154 : }
155 :
156 : /* Check if the sequence ended with an attenuation region */
157 80009 : if ( att_state == 1 )
158 : {
159 16778 : tmp = min( 1, max( 0, len - ENV_ADJ_START ) * ( 1.0f / ENV_ADJ_INCL ) );
160 :
161 130289 : for ( j = start; j < i; j++ )
162 : {
163 113511 : adj[j] = max( tmp + ( 1 - tmp ) * adj[j], env_stab );
164 : }
165 : }
166 :
167 80009 : return;
168 : }
|