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 : * nelp_decoder()
50 : *
51 : * NELP decoder
52 : *-------------------------------------------------------------------*/
53 :
54 0 : void nelp_decoder(
55 : Decoder_State *st, /* i/o: decoder static memory */
56 : float *exc_nelp, /* o : adapt. excitation/total exc*/
57 : float *exc, /* o : adapt. excitation exc */
58 : int16_t bfi, /* i : frame error rate */
59 : const int16_t coder_type, /* i : coding type */
60 : float *gain_buf /* o : floating pitch gain for each subframe */
61 : )
62 : {
63 0 : int16_t i, fid = 0;
64 : SC_VBR_DEC_HANDLE hSC_VBR;
65 : float ptr[L_FRAME], filtRes[L_FRAME], gain_fac;
66 : float Gains[10], Gain, E3, E2, R;
67 : float ptr_tmp[L_FRAME];
68 : int16_t iG1, iG2[2];
69 :
70 0 : hSC_VBR = st->hSC_VBR;
71 :
72 0 : if ( ( st->last_nelp_mode_dec == 1 ) && ( st->bwidth != st->last_bwidth ) )
73 : {
74 0 : st->last_nelp_mode_dec = 0;
75 : }
76 :
77 0 : if ( coder_type == UNVOICED && st->bwidth == NB )
78 : {
79 0 : if ( st->last_nelp_mode_dec != 1 )
80 : {
81 0 : set_f( hSC_VBR->bp1_filt_mem_nb_dec, 0, 7 * 2 );
82 : }
83 : }
84 0 : else if ( coder_type == UNVOICED && ( st->bwidth == WB || st->bwidth == SWB ) )
85 : {
86 0 : if ( st->last_nelp_mode_dec != 1 )
87 : {
88 0 : set_f( hSC_VBR->bp1_filt_mem_wb_dec, 0, 4 * 2 );
89 : }
90 : }
91 :
92 0 : if ( st->last_nelp_mode_dec != 1 )
93 : {
94 0 : set_f( hSC_VBR->shape1_filt_mem_dec, 0, 20 );
95 0 : set_f( hSC_VBR->shape2_filt_mem_dec, 0, 20 );
96 0 : set_f( hSC_VBR->shape3_filt_mem_dec, 0, 20 );
97 : }
98 :
99 0 : if ( bfi == 0 )
100 : {
101 0 : if ( st->rf_frame_type == RF_NELP && st->use_partial_copy )
102 : {
103 0 : iG1 = st->rf_indx_nelp_iG1;
104 0 : iG2[0] = st->rf_indx_nelp_iG2[0];
105 0 : iG2[1] = st->rf_indx_nelp_iG2[1];
106 : }
107 : else
108 : {
109 : /* Do Unvoiced/NELP Decoding */
110 0 : iG1 = get_next_indice( st, 5 );
111 0 : iG2[0] = get_next_indice( st, 6 );
112 0 : iG2[1] = get_next_indice( st, 6 );
113 : }
114 :
115 0 : if ( coder_type == UNVOICED && ( st->bwidth == WB || st->bwidth == SWB ) )
116 : {
117 0 : if ( st->rf_frame_type == RF_NELP && st->use_partial_copy )
118 : {
119 0 : fid = st->rf_indx_nelp_fid;
120 : }
121 : else
122 : {
123 0 : fid = get_next_indice( st, 2 );
124 : }
125 : }
126 :
127 0 : dequantize_uvg( iG1, iG2, Gains, st->bwidth );
128 : }
129 : else
130 : {
131 0 : for ( i = 1, Gain = 0.001f; i <= L_SUBFR; i++ )
132 : {
133 0 : Gain += SQR( exc[-i] );
134 : }
135 :
136 0 : Gain = (float) ( sqrt( Gain / L_SUBFR ) );
137 0 : Gain *= 0.8f; /* Some scale down of energy since it is an erasure */
138 :
139 0 : set_f( Gains, Gain, 10 );
140 : }
141 :
142 0 : if ( coder_type == UNVOICED && ( st->bwidth == WB || st->bwidth == SWB ) )
143 : {
144 0 : gain_fac = 1.16f;
145 : }
146 : else
147 : {
148 0 : gain_fac = 1.37f;
149 : }
150 :
151 0 : generate_nelp_excitation( &( hSC_VBR->nelp_dec_seed ), Gains, ptr, gain_fac );
152 :
153 0 : if ( coder_type == UNVOICED && ( st->bwidth == WB || st->bwidth == SWB ) )
154 : {
155 0 : polezero_filter( ptr, ptr_tmp, L_FRAME, bp1_num_coef_wb, bp1_den_coef_wb, 4, hSC_VBR->bp1_filt_mem_wb_dec );
156 0 : mvr2r( ptr_tmp, ptr, L_FRAME );
157 : }
158 :
159 0 : if ( coder_type == UNVOICED && st->bwidth == NB )
160 : {
161 0 : polezero_filter( ptr, ptr_tmp, L_FRAME, bp1_num_coef_nb_fx_order7, bp1_den_coef_nb_fx_order7, 7, hSC_VBR->bp1_filt_mem_nb_dec );
162 0 : mvr2r( ptr_tmp, ptr, L_FRAME );
163 : }
164 :
165 0 : for ( i = 0, E3 = 0.001f; i < L_FRAME; i++ )
166 : {
167 0 : E3 += SQR( ptr[i] );
168 : }
169 :
170 0 : if ( coder_type == UNVOICED && ( st->bwidth == WB || st->bwidth == SWB ) )
171 : {
172 0 : polezero_filter( ptr, ptr_tmp, L_FRAME, shape1_num_coef, shape1_den_coef, 10, hSC_VBR->shape1_filt_mem_dec );
173 0 : mvr2r( ptr_tmp, ptr, L_FRAME );
174 :
175 0 : switch ( fid )
176 : {
177 0 : case 1:
178 : /* Update other filter memory */
179 0 : polezero_filter( ptr, filtRes, L_FRAME, shape3_num_coef, shape3_den_coef, 10, hSC_VBR->shape3_filt_mem_dec );
180 :
181 : /* filter the residual to desired shape */
182 0 : polezero_filter( ptr, ptr_tmp, L_FRAME, shape2_num_coef, shape2_den_coef, 10, hSC_VBR->shape2_filt_mem_dec );
183 0 : mvr2r( ptr_tmp, ptr, L_FRAME );
184 :
185 0 : break;
186 0 : case 2:
187 : /* Update other filter memory */
188 0 : polezero_filter( ptr, filtRes, L_FRAME, shape2_num_coef, shape2_den_coef, 10, hSC_VBR->shape2_filt_mem_dec );
189 :
190 : /* filter the residual to desired shape */
191 0 : polezero_filter( ptr, ptr_tmp, L_FRAME, shape3_num_coef, shape3_den_coef, 10, hSC_VBR->shape3_filt_mem_dec );
192 :
193 0 : mvr2r( ptr_tmp, ptr, L_FRAME );
194 :
195 0 : break;
196 0 : default:
197 : /* Update other filter memory */
198 0 : polezero_filter( ptr, filtRes, L_FRAME, shape2_num_coef, shape2_den_coef, 10, hSC_VBR->shape2_filt_mem_dec );
199 :
200 0 : polezero_filter( ptr, filtRes, L_FRAME, shape3_num_coef, shape3_den_coef, 10, hSC_VBR->shape3_filt_mem_dec );
201 :
202 0 : break;
203 : }
204 :
205 0 : for ( i = 0, E2 = 0.001f; i < L_FRAME; i++ )
206 : {
207 0 : E2 += SQR( ptr[i] );
208 : }
209 :
210 0 : R = (float) sqrt( E3 / E2 );
211 :
212 0 : for ( i = 0; i < L_FRAME; i++ )
213 : {
214 0 : ptr[i] *= R;
215 : }
216 : }
217 :
218 0 : mvr2r( ptr, exc_nelp, L_FRAME );
219 0 : set_f( gain_buf, 0.f, NB_SUBFR16k );
220 :
221 0 : return;
222 : }
|