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 "prot.h"
44 : #include "wmc_auto.h"
45 :
46 : /*-------------------------------------------------------------------
47 : * encod_ppp()
48 : *
49 : * Encode PPP frames in SC-VBR
50 : *-------------------------------------------------------------------*/
51 :
52 0 : ivas_error encod_ppp(
53 : Encoder_State *st, /* i/o: state structure */
54 : const float speech[], /* i : input speech */
55 : const float Aw[], /* i : weighted A(z) unquantized for subframes */
56 : const float Aq[], /* i : 12k8 Lp coefficient */
57 : float *res, /* i/o: residual signal */
58 : float *synth, /* i/o: core synthesis */
59 : float *exc, /* i/o: current non-enhanced excitation */
60 : float *exc2, /* i/o: current enhanced excitation */
61 : float *pitch_buf, /* i/o: floating pitch values for each subframe */
62 : float *voice_factors, /* o : voicing factors */
63 : float *bwe_exc /* o : excitation for SWB TBE */
64 : )
65 : {
66 : float xn[L_SUBFR]; /* Target vector for pitch search */
67 : float h1[L_SUBFR + ( M + 1 )]; /* Impulse response vector */
68 : int16_t i_subfr; /* tmp variables */
69 : const float *p_Aw, *p_Aq; /* pointer to LP filter coeff. vector */
70 : int16_t k;
71 : float p_Aq_old[M + 1], excQ_ppp[L_FRAME], p_Aq_curr[M], pitch[NB_SUBFR];
72 : float LPC_de_old[M + 1], LPC_de_curr[M + 1];
73 : int16_t rate_ctrl;
74 :
75 0 : LPD_state_HANDLE hLPDmem = st->hLPDmem;
76 0 : SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
77 0 : BSTR_ENC_HANDLE hBstr = st->hBstr;
78 : ivas_error error;
79 :
80 0 : error = IVAS_ERR_OK;
81 :
82 0 : rate_ctrl = hSC_VBR->rate_control;
83 :
84 : /*------------------------------------------------------------------*
85 : * ACELP subframe loop
86 : *------------------------------------------------------------------*/
87 :
88 0 : p_Aw = Aw;
89 0 : p_Aq = Aq;
90 :
91 0 : for ( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR )
92 : {
93 : /*----------------------------------------------------------------*
94 : * Bandwidth expansion of A(z) filter coefficients
95 : * Find the the excitation search target "xn" and innovation
96 : * target in residual domain "cn"
97 : * Compute impulse response, h1[], of weighted synthesis filter
98 : *----------------------------------------------------------------*/
99 :
100 0 : mvr2r( &res[i_subfr], &exc[i_subfr], L_SUBFR );
101 :
102 0 : find_targets( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, L_SUBFR, p_Aw, TILT_FAC, xn, NULL, h1 );
103 :
104 : /* call voiced encoder at this point */
105 0 : if ( i_subfr == 0 ) /* generate the L_FRAME exc */
106 : {
107 0 : for ( k = 0; k < M; k++ )
108 : {
109 0 : p_Aq_curr[k] = p_Aq[k + ( 3 * ( M + 1 ) ) + 1];
110 : }
111 :
112 0 : lsp2a_stab( st->lsp_old, p_Aq_old, M );
113 :
114 0 : deemph_lpc( p_Aq_curr, p_Aq_old, LPC_de_curr, LPC_de_old, 1 );
115 :
116 : /* last frame-end lpc and curr frame-end lpc */
117 0 : if ( ( error = ppp_voiced_encoder( hBstr, st->hSC_VBR, st->bwidth, st->last_coder_type_raw, st->old_pitch_buf, res, excQ_ppp, st->pitch[1], LPC_de_old, LPC_de_curr, exc, pitch ) ) != IVAS_ERR_OK )
118 : {
119 0 : return error;
120 : }
121 :
122 :
123 0 : if ( hSC_VBR->bump_up )
124 : {
125 0 : i_subfr = L_FRAME;
126 : }
127 : }
128 :
129 0 : if ( hSC_VBR->bump_up != 1 )
130 : {
131 : /*-----------------------------------------------------------------*
132 : * Gain clipping test to avoid unstable synthesis on frame erasure
133 : * or in case of floating point encoder & fixed p. decoder
134 : *-----------------------------------------------------------------*/
135 :
136 0 : gp_clip( st->element_mode, st->core_brate, st->voicing, i_subfr, st->coder_type, xn, st->clip_var );
137 :
138 : /* run the above to maintain gain clipping memories */
139 0 : gp_clip_test_gain_pit( st->element_mode, st->core_brate, hSC_VBR->prev_ppp_gain_pit, st->clip_var );
140 :
141 : /*-----------------------------------------------------------------*
142 : * Synthesize speech to update mem_syn[].
143 : * Update A(z) filters
144 : *-----------------------------------------------------------------*/
145 :
146 0 : syn_filt( p_Aq, M, &excQ_ppp[i_subfr], &synth[i_subfr], L_SUBFR, hLPDmem->mem_syn, 1 );
147 :
148 0 : p_Aw += ( M + 1 );
149 0 : p_Aq += ( M + 1 );
150 : }
151 :
152 : } /* end of subframe loop */
153 :
154 :
155 0 : if ( hSC_VBR->bump_up )
156 : {
157 : /* PPP failed, bump up */
158 0 : hSC_VBR->ppp_mode = 0;
159 0 : st->core_brate = ACELP_7k20;
160 0 : hSC_VBR->pppcountE = 0;
161 :
162 0 : if ( hSC_VBR->set_ppp_generic )
163 : {
164 0 : st->coder_type = GENERIC;
165 : }
166 : else
167 : {
168 0 : st->coder_type = VOICED;
169 : }
170 :
171 : /* delete previous indices */
172 0 : reset_indices_enc( hBstr, hBstr->nb_ind_tot );
173 :
174 : /* signaling matrix (writing of signaling bits) */
175 0 : signaling_enc( st );
176 : }
177 : else
178 : {
179 0 : mvr2r( excQ_ppp, exc, L_FRAME );
180 :
181 : /*-----------------------------------------------------------------*
182 : * Updates: last value of new target is stored in mem_w0
183 : *-----------------------------------------------------------------*/
184 :
185 0 : hLPDmem->mem_w0 = xn[L_SUBFR - 1] - ( exc[L_FRAME - 1] );
186 :
187 0 : mvr2r( exc, exc2, L_FRAME );
188 :
189 0 : hLPDmem->dispMem[0] = 2;
190 0 : hLPDmem->dispMem[2] = hSC_VBR->prev_ppp_gain_pit;
191 :
192 0 : for ( k = 3; k < 7; k++ )
193 : {
194 0 : hLPDmem->dispMem[k] = hLPDmem->dispMem[k - 1];
195 : }
196 0 : hLPDmem->tilt_code = hSC_VBR->prev_tilt_code;
197 0 : mvr2r( pitch, pitch_buf, NB_SUBFR );
198 0 : pitch_buf[NB_SUBFR16k - 1] = pitch[NB_SUBFR - 1];
199 0 : interp_code_5over2( exc2, bwe_exc, L_FRAME );
200 0 : set_f( voice_factors, 0.0f, NB_SUBFR16k );
201 : }
202 :
203 0 : hSC_VBR->rate_control = rate_ctrl;
204 :
205 0 : set_f( hSC_VBR->nelp_lp_fit_mem, 0, NELP_LP_ORDER * 2 );
206 :
207 0 : return error;
208 : }
|