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 49368 : 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 49368 : att_state = 0;
71 49368 : len = 0;
72 49368 : start = 0;
73 :
74 : /* Find attenuation levels */
75 1409119 : for ( i = 0; i <= last_sfm; i++ )
76 : {
77 1359751 : group = ( sfmsize[i] >> 3 ) - 1;
78 1359751 : npul = pulses[i];
79 :
80 1359751 : if ( length == L_FRAME32k )
81 : {
82 751373 : if ( npul == 0 )
83 : {
84 : /* Noise filled band */
85 218821 : if ( group <= 1 )
86 : {
87 175546 : if ( i > 0 && pulses[i - 1] != 0 && pulses[i + 1] != 0 )
88 : {
89 32511 : adj[i] = 0.36f;
90 : }
91 143035 : else if ( i > 0 && ( pulses[i - 1] == 0 || pulses[i + 1] == 0 ) )
92 : {
93 141725 : adj[i] = 0.54f;
94 : }
95 : else
96 : {
97 1310 : adj[i] = 0.72f;
98 : }
99 : }
100 43275 : else if ( i < last_sfm )
101 : {
102 34468 : if ( pulses[i - 1] != 0 && pulses[i + 1] != 0 )
103 : {
104 3682 : adj[i] = 0.54f;
105 : }
106 : else
107 : {
108 30786 : adj[i] = 0.72f;
109 : }
110 : }
111 : else
112 : {
113 8807 : adj[i] = 0.72f;
114 : }
115 :
116 218821 : if ( att_state == 0 )
117 : {
118 75463 : start = i;
119 : }
120 :
121 218821 : len++;
122 218821 : att_state = 1;
123 : }
124 : else
125 : {
126 532552 : adj[i] = 1.0f;
127 532552 : if ( att_state == 1 ) /* End of attenuation region found */
128 : {
129 66656 : tmp = min( 1, max( 0, len - ENV_ADJ_START ) * ( 1.0f / ENV_ADJ_INCL ) );
130 231200 : for ( j = start; j < i; j++ )
131 : {
132 164544 : adj[j] = max( tmp + ( 1 - tmp ) * adj[j], env_stab );
133 : }
134 66656 : len = 0;
135 66656 : att_state = 0;
136 : }
137 : }
138 : }
139 : /* length == L_FRAME16k */
140 : else
141 : {
142 : /* Calculate low accuracy band attenuation */
143 608378 : gain_adj = 1.0f;
144 608378 : if ( npul > 0 && npul < MAX_P_ATT )
145 : {
146 518411 : idx = (int16_t) ( npul * att_step[group] + 0.5f ) - 1;
147 518411 : if ( idx < MAX_P_ATT )
148 : {
149 430818 : gain_adj = gain_att[idx];
150 : }
151 : }
152 608378 : adj[i] = gain_adj;
153 : }
154 : }
155 :
156 : /* Check if the sequence ended with an attenuation region */
157 49368 : if ( att_state == 1 )
158 : {
159 8807 : tmp = min( 1, max( 0, len - ENV_ADJ_START ) * ( 1.0f / ENV_ADJ_INCL ) );
160 :
161 63084 : for ( j = start; j < i; j++ )
162 : {
163 54277 : adj[j] = max( tmp + ( 1 - tmp ) * adj[j], env_stab );
164 : }
165 : }
166 :
167 49368 : return;
168 : }
|