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 "rom_com.h"
45 : #include "wmc_auto.h"
46 : #include <math.h>
47 :
48 : /*------------------------------------------------------------------*
49 : * syn_filt()
50 : *
51 : * perform the synthesis filtering 1/A(z)
52 : *------------------------------------------------------------------*/
53 :
54 21437679 : void syn_filt(
55 : const float a[], /* i : LP filter coefficients */
56 : const int16_t m, /* i : order of LP filter */
57 : const float x[], /* i : input signal */
58 : float y[], /* o : output signal */
59 : const int16_t l, /* i : size of filtering */
60 : float mem[], /* i/o: initial filter states */
61 : const int16_t update_m /* i : update memory flag: 0 --> no memory update */
62 : ) /* 1 --> update of memory */
63 : {
64 : int16_t i, j;
65 : float buf[L_FRAME48k + L_FRAME48k / 2 + TCXLTP_LTP_ORDER]; /* temporary synthesis buffer */
66 : float s, *yy;
67 :
68 21437679 : yy = &buf[0];
69 :
70 : /*------------------------------------------------------------------*
71 : * copy initial filter states into synthesis buffer and do synthesis
72 : *------------------------------------------------------------------*/
73 :
74 334225687 : for ( i = 0; i < m; i++ )
75 : {
76 312788008 : *yy++ = mem[i];
77 : }
78 :
79 : /*-----------------------------------------------------------------------*
80 : * Do the filtering
81 : *-----------------------------------------------------------------------*/
82 :
83 1431327423 : for ( i = 0; i < l; i++ )
84 : {
85 1409889744 : s = x[i];
86 21337630088 : for ( j = 1; j <= m; j++ )
87 : {
88 19927740344 : s -= a[j] * yy[i - j];
89 : }
90 :
91 1409889744 : yy[i] = s;
92 1409889744 : y[i] = s;
93 : }
94 :
95 : /*------------------------------------------------------------------*
96 : * Update memory if required
97 : *------------------------------------------------------------------*/
98 :
99 21437679 : if ( update_m )
100 : {
101 135041921 : for ( i = 0; i < m; i++ )
102 : {
103 125955408 : mem[i] = yy[l - m + i];
104 : }
105 : }
106 :
107 21437679 : return;
108 : }
109 :
110 :
111 : /*-------------------------------------------------------------------*
112 : * synth_mem_updt2()
113 : *
114 : * Update of synthesis filter memories in case of ACELP@12k8 <-> ACELP@16k switching
115 : *--------------------------------------------------------------------*/
116 :
117 5056 : void synth_mem_updt2(
118 : const int16_t L_frame, /* i : frame length */
119 : const int16_t last_L_frame, /* i : frame length */
120 : float old_exc[], /* i/o: excitation buffer */
121 : float mem_syn_r[], /* i/o: synthesis filter memory */
122 : float mem_syn2[], /* o : synthesis filter memory for find_target */
123 : float mem_syn[], /* o : synthesis filter memory for find_target */
124 : const int16_t dec /* i : flag for decoder indication */
125 : )
126 : {
127 : int16_t mem_syn_r_size_old, mem_syn_r_size_new;
128 : int16_t i;
129 : float en1, en2, loc_rat;
130 :
131 : /* Residual and update old_exc */
132 5056 : if ( dec >= DEC )
133 : {
134 3759 : lerp( old_exc + L_EXC_MEM_DEC - ( last_L_frame + last_L_frame / 2 ), old_exc + L_EXC_MEM_DEC - ( L_frame + L_frame / 2 ), L_frame + L_frame / 2, last_L_frame + last_L_frame / 2 );
135 : }
136 : else
137 : {
138 1297 : lerp( old_exc + L_EXC_MEM - last_L_frame, old_exc + L_EXC_MEM - L_frame, L_frame, last_L_frame );
139 : }
140 :
141 : /*Resamp memory*/
142 : /*Size of LPC syn memory*/
143 5056 : mem_syn_r_size_old = (int16_t) ( 1.25 * last_L_frame / 20.f );
144 5056 : mem_syn_r_size_new = (int16_t) ( 1.25 * L_frame / 20.f );
145 :
146 5056 : lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
147 :
148 5056 : if ( dec == DEC_IVAS )
149 : {
150 2208 : if ( L_frame == L_FRAME16k )
151 : {
152 : /* find scaling factor */
153 1341 : en1 = 1.25f * sum2_f( mem_syn2, M );
154 1341 : en2 = sum2_f( mem_syn_r + L_SYN_MEM - M, M );
155 :
156 1341 : loc_rat = sqrtf( en2 ) / ( sqrtf( en1 ) + 0.01f );
157 : /* scale synthesis filter memory */
158 22797 : for ( i = 0; i < M; i++ )
159 : {
160 21456 : mem_syn_r[L_SYN_MEM - M + i] *= loc_rat;
161 : }
162 : }
163 : }
164 :
165 5056 : mvr2r( mem_syn_r + L_SYN_MEM - M, mem_syn2, M );
166 :
167 5056 : if ( mem_syn != NULL )
168 : {
169 1297 : mvr2r( mem_syn2, mem_syn, M );
170 : }
171 :
172 5056 : return;
173 : }
|