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 "prot.h"
43 : #include "rom_com.h"
44 : #include "cnst.h"
45 : #include "wmc_auto.h"
46 :
47 : /*-------------------------------------------------------------------*
48 : * core_encode_update()
49 : *
50 : * Common updates of buffers
51 : *-------------------------------------------------------------------*/
52 :
53 1132914 : void core_encode_update(
54 : Encoder_State *st /* i/o: Encoder state structure */
55 : )
56 : {
57 1132914 : TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
58 : int16_t n;
59 :
60 : /* Update Input Signal Buffers */
61 1132914 : n = st->encoderPastSamples_enc + st->encoderLookahead_enc;
62 :
63 1132914 : mvr2r( st->buf_speech_enc_pe + st->L_frame, st->buf_speech_enc_pe, n );
64 1132914 : mvr2r( st->buf_speech_enc + st->L_frame, st->buf_speech_enc, n );
65 :
66 1132914 : if ( !st->tcxonly )
67 : {
68 304318 : n = st->L_frame + st->L_frame / 4;
69 304318 : mvr2r( st->buf_wspeech_enc + st->L_frame, st->buf_wspeech_enc, n );
70 : }
71 :
72 1132914 : if ( hTcxEnc != NULL )
73 : {
74 1129123 : if ( st->core == ACELP_CORE || st->core == AMR_WB_CORE || st->core_brate == SID_2k40 || st->core_brate == FRAME_NO_DATA )
75 : {
76 178910 : mvr2r( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame );
77 : }
78 : }
79 :
80 1132914 : n = st->encoderPastSamples_enc + st->encoderLookahead_enc;
81 1132914 : mvr2r( st->buf_synth + st->L_frame, st->buf_synth, st->L_frame + L_SUBFR );
82 1132914 : if ( hTcxEnc != NULL )
83 : {
84 1129123 : mvr2r( hTcxEnc->buf_speech_ltp + st->L_frame, hTcxEnc->buf_speech_ltp, n );
85 :
86 1129123 : if ( st->element_mode != IVAS_CPE_MDCT )
87 : {
88 414353 : st->hTcxEnc->kernel_switch_corr_past = 0.f;
89 414353 : st->hTcxEnc->kernel_type[0] = MDCT_IV;
90 414353 : st->hTcxEnc->kernel_symmetry_past = 0;
91 414353 : st->hTcxEnc->enc_ste_pre_corr_past = 0;
92 : }
93 : }
94 :
95 1132914 : if ( ( st->Opt_DTX_ON && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG ) || ( st->tcxonly && ( st->codec_mode == MODE2 || st->element_mode > EVS_MONO ) ) )
96 : {
97 : /* reset LP memories */
98 840510 : set_zero( st->mem_MA, M );
99 840510 : mvr2r( GEWB_Ave, st->mem_AR, M );
100 : }
101 :
102 1132914 : return;
103 : }
104 :
105 :
106 : /*-------------------------------------------------------------------*
107 : * core_encode_update_cng()
108 : *
109 : * Common updates in case of CNG
110 : *-------------------------------------------------------------------*/
111 :
112 0 : void core_encode_update_cng(
113 : Encoder_State *st,
114 : float *timeDomainBuffer,
115 : float *A,
116 : const float Aw[] /* i : weighted A(z) unquant. for subframes*/
117 : )
118 : {
119 : float lsp[M], lsf[M];
120 : float *synth, synth_buf[M + 1 + L_FRAME_PLUS + L_FRAME_PLUS / 2], wsyn[L_FRAME_PLUS];
121 : float tmp;
122 : float enr;
123 : int16_t enr_index;
124 0 : int16_t L_frame = st->L_frame;
125 :
126 0 : LPD_state_HANDLE hLPDmem = st->hLPDmem;
127 :
128 : /* LPC -> LSP/lsp */
129 0 : a2lsp_stab( A, lsp, st->lsp_old );
130 :
131 : /* LSP/lsp -> LSF/lsf */
132 0 : if ( L_frame == L_FRAME16k )
133 : {
134 0 : lsp2lsf( lsp, lsf, M, INT_FS_16k );
135 : }
136 : else
137 : {
138 0 : lsp2lsf( lsp, lsf, M, INT_FS_12k8 );
139 : }
140 :
141 : /* Update synth memory */
142 0 : synth = synth_buf + ( 1 + M );
143 0 : mvr2r( hLPDmem->syn, synth_buf, 1 + M );
144 0 : mvr2r( timeDomainBuffer, synth, L_frame );
145 0 : mvr2r( synth + L_frame - ( 1 + M ), hLPDmem->syn, 1 + M );
146 0 : mvr2r( synth, st->synth, L_frame );
147 :
148 : /* Update ZIR */
149 0 : set_zero( synth + L_frame, L_frame / 2 );
150 0 : syn_filt( A, M, synth + L_frame, synth + L_frame, L_frame / 2, &synth[L_frame - M], 0 );
151 0 : if ( st->hTcxEnc != NULL )
152 : {
153 0 : mvr2r( synth + L_frame - ( L_frame / 2 ), st->hTcxEnc->Txnq, L_frame / 2 );
154 : }
155 :
156 : /* Update pe-synth memory */
157 0 : tmp = synth[-( 1 + M )];
158 0 : preemph( synth - M, st->preemph_fac, M + L_frame, &tmp );
159 0 : mvr2r( synth + L_frame - M, hLPDmem->mem_syn, M );
160 0 : mvr2r( synth + L_frame - M, hLPDmem->mem_syn2, M );
161 :
162 : /* Update excitation memory */
163 0 : mvr2r( hLPDmem->old_exc + L_frame, hLPDmem->old_exc, max( L_EXC_MEM - L_frame, 0 ) );
164 0 : residu( A, M, synth, hLPDmem->old_exc + max( L_EXC_MEM - L_frame, 0 ), L_frame );
165 :
166 0 : if ( st->core_brate == SID_2k40 )
167 : {
168 0 : enr = cng_energy( st->element_mode, st->bwidth, st->hDtxEnc->CNG_mode, st->hTdCngEnc->CNG_att, hLPDmem->old_exc + max( L_EXC_MEM - L_frame, 0 ), L_frame );
169 :
170 0 : enr_index = (int16_t) ( ( enr + 2.0f ) * STEP_SID );
171 0 : enr_index = min( max( enr_index, 0 ), 127 );
172 0 : st->hTdCngEnc->old_enr_index = enr_index;
173 : }
174 :
175 : /* Update weighted synthesis memory */
176 0 : calc_residu( synth, wsyn, Aw, L_frame );
177 0 : tmp = st->wspeech_enc[-1] - hLPDmem->mem_w0;
178 0 : deemph( wsyn, st->preemph_fac, L_frame, &tmp );
179 0 : hLPDmem->mem_w0 = st->wspeech_enc[L_frame - 1] - wsyn[L_frame - 1];
180 :
181 : /* Update LPC-related memories */
182 0 : mvr2r( lsp, st->lsp_old, M );
183 0 : mvr2r( lsf, st->lsf_old, M );
184 0 : st->envWeighted = 0;
185 0 : mvr2r( A, st->old_Aq_12_8, M + 1 );
186 0 : st->old_Es_pred = 0;
187 :
188 : /* Reset acelp memories */
189 0 : set_zero( hLPDmem->dispMem, 8 );
190 0 : hLPDmem->tilt_code = TILT_CODE;
191 0 : hLPDmem->gc_threshold = 0.0f;
192 :
193 : /* Update ace/tcx mode */
194 0 : st->core = ACELP_CORE;
195 :
196 : /* Reset TCX overlap */
197 0 : st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
198 :
199 0 : if ( st->hDtxEnc->first_CNG == 0 )
200 : {
201 0 : mvr2r( st->lsp_old, st->hDtxEnc->lspCNG, M );
202 : }
203 :
204 0 : return;
205 : }
|