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 1884 : 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 1884 : att_state = 0;
71 1884 : len = 0;
72 1884 : start = 0;
73 :
74 : /* Find attenuation levels */
75 55816 : for ( i = 0; i <= last_sfm; i++ )
76 : {
77 53932 : group = ( sfmsize[i] >> 3 ) - 1;
78 53932 : npul = pulses[i];
79 :
80 53932 : if ( length == L_FRAME32k )
81 : {
82 39332 : if ( npul == 0 )
83 : {
84 : /* Noise filled band */
85 11080 : if ( group <= 1 )
86 : {
87 8845 : if ( i > 0 && pulses[i - 1] != 0 && pulses[i + 1] != 0 )
88 : {
89 1932 : adj[i] = 0.36f;
90 : }
91 6913 : else if ( i > 0 && ( pulses[i - 1] == 0 || pulses[i + 1] == 0 ) )
92 : {
93 6833 : adj[i] = 0.54f;
94 : }
95 : else
96 : {
97 80 : adj[i] = 0.72f;
98 : }
99 : }
100 2235 : else if ( i < last_sfm )
101 : {
102 1790 : if ( pulses[i - 1] != 0 && pulses[i + 1] != 0 )
103 : {
104 220 : adj[i] = 0.54f;
105 : }
106 : else
107 : {
108 1570 : adj[i] = 0.72f;
109 : }
110 : }
111 : else
112 : {
113 445 : adj[i] = 0.72f;
114 : }
115 :
116 11080 : if ( att_state == 0 )
117 : {
118 4131 : start = i;
119 : }
120 :
121 11080 : len++;
122 11080 : att_state = 1;
123 : }
124 : else
125 : {
126 28252 : adj[i] = 1.0f;
127 28252 : if ( att_state == 1 ) /* End of attenuation region found */
128 : {
129 3686 : tmp = min( 1, max( 0, len - ENV_ADJ_START ) * ( 1.0f / ENV_ADJ_INCL ) );
130 12201 : for ( j = start; j < i; j++ )
131 : {
132 8515 : adj[j] = max( tmp + ( 1 - tmp ) * adj[j], env_stab );
133 : }
134 3686 : len = 0;
135 3686 : att_state = 0;
136 : }
137 : }
138 : }
139 : /* length == L_FRAME16k */
140 : else
141 : {
142 : /* Calculate low accuracy band attenuation */
143 14600 : gain_adj = 1.0f;
144 14600 : if ( npul > 0 && npul < MAX_P_ATT )
145 : {
146 12140 : idx = (int16_t) ( npul * att_step[group] + 0.5f ) - 1;
147 12140 : if ( idx < MAX_P_ATT )
148 : {
149 9618 : gain_adj = gain_att[idx];
150 : }
151 : }
152 14600 : adj[i] = gain_adj;
153 : }
154 : }
155 :
156 : /* Check if the sequence ended with an attenuation region */
157 1884 : if ( att_state == 1 )
158 : {
159 445 : tmp = min( 1, max( 0, len - ENV_ADJ_START ) * ( 1.0f / ENV_ADJ_INCL ) );
160 :
161 3010 : for ( j = start; j < i; j++ )
162 : {
163 2565 : adj[j] = max( tmp + ( 1 - tmp ) * adj[j], env_stab );
164 : }
165 : }
166 :
167 1884 : return;
168 : }
|