Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 : #include <stdint.h>
6 : #include "options.h" /* Compilation switches */
7 : #include "cnst.h" /* Common constants */
8 : #include "rom_com.h" /* Static table prototypes */
9 : #include "prot_fx.h" /* Function prototypes */
10 :
11 :
12 : /*-------------------------------------------------------------------*
13 : * Function pred_lt4: *
14 : * ~~~~~~~~~ *
15 : *-------------------------------------------------------------------*
16 : * Compute the result of long term prediction with fractional *
17 : * interpolation of resolution 1/4. *
18 : * *
19 : * On return exc[0..L_subfr-1] contains the interpolated signal *
20 : * (adaptive codebook excitation) *
21 : *-------------------------------------------------------------------*/
22 :
23 2310668 : void pred_lt4(
24 : const Word16 excI[], /* in : excitation buffer Q_exc*/
25 : Word16 excO[], /* out: excitation buffer Q_exc*/
26 : const Word16 T0, /* input : integer pitch lag Q0*/
27 : Word16 frac, /* input : fraction of lag Q0*/
28 : const Word16 L_subfr, /* input : subframe size Q0*/
29 : const Word16 *win, /* i : interpolation window Q14*/
30 : const Word16 nb_coef, /* i : nb of filter coef Q0*/
31 : const Word16 up_sample /* i : up_sample Q0*/
32 : )
33 : {
34 : Word16 i, j;
35 : Word32 s;
36 : const Word16 *x0, *x1, *x2, *c1, *c2;
37 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
38 2310668 : Flag Overflow = 0;
39 2310668 : move32();
40 : #endif
41 2310668 : x0 = &excI[-T0];
42 :
43 :
44 2310668 : frac = negate( frac );
45 :
46 2310668 : IF( frac < 0 )
47 : {
48 1660359 : frac = add( frac, up_sample ); /* Q0 */
49 1660359 : x0--;
50 : }
51 :
52 156278990 : FOR( j = 0; j < L_subfr; j++ )
53 : {
54 153968322 : x1 = x0++; /* Q_exc */
55 153968322 : x2 = x1 + 1; /* Q_exc */
56 153968322 : c1 = ( &win[frac] ); /* Q14 */
57 153968322 : c2 = ( &win[up_sample - frac] ); /* Q14 */
58 :
59 : {
60 153968322 : Word64 s64 = 0;
61 153968322 : move64();
62 1719719192 : FOR( i = 0; i < nb_coef; i++ )
63 : {
64 : /*s += (*x1--) * (*c1) + (*x2++) * (*c2);*/
65 1565750870 : s64 = W_mac0_16_16( s64, ( *x1-- ), ( *c1 ) ); /* Q_exc + Q14 */
66 1565750870 : s64 = W_mac0_16_16( s64, ( *x2++ ), ( *c2 ) ); /* Q_exc + Q14 */
67 :
68 1565750870 : c1 += up_sample;
69 1565750870 : c2 += up_sample;
70 : }
71 153968322 : s = W_sat_l( s64 ); /* Q_exc + Q14 */
72 : }
73 : #if ( INTERP_EXP != -1 )
74 153968322 : s = L_shl_o( s, INTERP_EXP + 1, &Overflow ); /* Q_exc + Q15 */
75 : #endif
76 :
77 153968322 : excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */
78 153968322 : move16();
79 : }
80 2310668 : return;
81 : }
82 :
83 :
84 : /*======================================================================*/
85 : /* FUNCTION : pred_lt4_tc_fx() */
86 : /*-----------------------------------------------------------------------*/
87 : /* PURPOSE : * adapt. search of the second impulse in the same subframe (when appears) */
88 : /* On return, exc[0..L_subfr-1] contains the interpolated signal */
89 : /* (adaptive codebook excitation) */
90 : /* */
91 : /*-----------------------------------------------------------------------*/
92 : /* INPUT ARGUMENTS : */
93 : /* _ (Word16 []) exc : excitation buffer Q0 */
94 : /* _ (Word16) L_subfr : subframe size Q0 */
95 : /* _ (Word16 ) T0 : integer pitch lag Q0 */
96 : /* _ (Word16 ) frac : fraction of lag Q0 */
97 : /* _ (Word16 ) imp_pos : glottal impulse position Q0 */
98 : /* _ (Word16 *) win : Interpolation window used Q14 */
99 : /*-----------------------------------------------------------------------*/
100 : /* OUTPUT ARGUMENTS : */
101 : /* _ (Word16 []) exc : output excitation buffer Q0 */
102 : /*-----------------------------------------------------------------------*/
103 : /* INPUT OUTPUT ARGUMENTS */
104 : /* NONE */
105 : /*-----------------------------------------------------------------------*/
106 : /* RETURN ARGUMENTS : */
107 : /* NONE */
108 : /*=======================================================================*/
109 26849 : void pred_lt4_tc_fx(
110 : Word16 exc[], /* i/o: excitation buffer Q0*/
111 : const Word16 T0, /* i : integer pitch lag Q0*/
112 : Word16 frac, /* i: fraction of lag Q0*/
113 : const Word16 *win, /* i : interpolation window Q14*/
114 : const Word16 imp_pos, /* i : glottal impulse position Q0*/
115 : const Word16 i_subfr /* i : subframe index Q0*/
116 : )
117 : {
118 : Word16 i, j, k, l;
119 : const Word16 *x0;
120 : Word16 excO[L_SUBFR + 1];
121 : Word32 L_sum;
122 : Word16 excI[2 * L_SUBFR];
123 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
124 26849 : Flag Overflow = 0;
125 26849 : move32();
126 : #endif
127 26849 : Copy( exc + sub( i_subfr, L_SUBFR ), excI, L_SUBFR * 2 ); /* Q0 */
128 :
129 26849 : test();
130 26849 : IF( LT_16( add( T0, sub( imp_pos, L_IMPULSE2 ) ), L_SUBFR ) && LT_16( T0, L_SUBFR ) )
131 : {
132 4214 : set16_fx( &excI[L_SUBFR - T0], 0, T0 );
133 4214 : set16_fx( excO, 0, L_SUBFR + 1 );
134 4214 : x0 = excI + ( L_SUBFR - ( L_INTERPOL2 - 1 ) );
135 :
136 4214 : IF( frac > 0 )
137 : {
138 2044 : frac = sub( frac, UP_SAMP ); /* Q0 */
139 2044 : x0--;
140 : }
141 :
142 4214 : l = add( UP_SAMP - 1, frac ); /* Q0 */
143 80508 : FOR( j = T0; j < L_SUBFR + 1; j++ )
144 : {
145 76294 : k = l;
146 76294 : move16();
147 76294 : L_sum = L_mult( x0[0], win[k] ); /* Q15 */
148 2441408 : FOR( i = 1; i < 2 * L_INTERPOL2; i++ )
149 : {
150 : /*
151 : * Here, additions with UP_SAMP are not counted
152 : ki* because, the window could easily be modified
153 : * so that the values needed are contiguous.
154 : */
155 2365114 : k += UP_SAMP;
156 2365114 : L_sum = L_mac( L_sum, x0[i], win[k] ); /* Q15 */
157 : }
158 76294 : L_sum = L_shl_o( L_sum, 1, &Overflow ); /* Q16 */
159 76294 : excO[j] = round_fx_o( L_sum, &Overflow ); /* Q0 */
160 76294 : move16();
161 :
162 76294 : x0++;
163 : }
164 76294 : FOR( i = T0; i < L_SUBFR; i++ )
165 : {
166 72080 : exc[i + i_subfr] = add_o( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ), &Overflow ); /* Q0 */
167 72080 : move16();
168 : }
169 : }
170 :
171 26849 : return;
172 : }
|