Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 : #include <stdint.h>
5 : #include "options.h"
6 : #include "cnst.h"
7 : //#include "prot_fx.h"
8 : #include "prot_fx.h" /* Function prototypes */
9 : #include "prot_fx_enc.h" /* Function prototypes */
10 :
11 : /*-------------------------------------------------------------------*
12 : * local constants
13 : * -----------------------------------------------------------------*/
14 :
15 : #define NB_TRACK 4
16 : #define STEP NB_TRACK
17 :
18 : /*-------------------------------------------------------------------*
19 : * corr_xh_fx:
20 : *
21 : * Compute the correlation between the target signal and the impulse
22 : * response of the weighted synthesis filter.
23 : *
24 : * y[i]=sum(j=i,l-1) x[j]*h[j-i], i=0,l-1
25 : *-------------------------------------------------------------------*/
26 2968 : void corr_xh_fx(
27 : const Word16 x[], /* i : target signal Qx*/
28 : Word16 dn[], /* o : correlation between x[] and h[] Qdn = Qx+j-1*/
29 : const Word16 h[] /* i : impulse response (of weighted synthesis filter) Q14*/
30 : )
31 : {
32 : Word16 i, j, k;
33 : Word32 L_tmp, y32[L_SUBFR], L_maxloc, L_tot;
34 : #ifndef ISSUE_1867_replace_overflow_libenc
35 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
36 : Flag Overflow = 0;
37 : move16();
38 : #endif
39 : #endif
40 :
41 : /* first keep the result on 32 bits and find absolute maximum */
42 2968 : L_tot = L_deposit_l( 1 );
43 :
44 14840 : FOR( k = 0; k < NB_TRACK; k++ )
45 : {
46 11872 : L_maxloc = L_deposit_l( 0 );
47 201824 : FOR( i = k; i < L_SUBFR; i += STEP )
48 : {
49 189952 : L_tmp = L_mac( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] Qx+15*/
50 6173440 : FOR( j = i; j < L_SUBFR - 1; j++ )
51 : {
52 : #ifdef ISSUE_1867_replace_overflow_libenc
53 5983488 : L_tmp = L_mac_sat( L_tmp, x[j + 1], h[j + 1 - i] ); /*Qx+15*/
54 : #else
55 : L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); /*Qx+15*/
56 : #endif
57 : }
58 :
59 189952 : y32[i] = L_tmp; /*Qx+15*/
60 189952 : move32();
61 189952 : L_tmp = L_abs( L_tmp );
62 189952 : L_maxloc = L_max( L_tmp, L_maxloc ); /*Qx+15*/
63 : }
64 : /* tot += 3*max / 8 */
65 11872 : L_maxloc = L_shr( L_maxloc, 2 );
66 : #ifdef ISSUE_1867_replace_overflow_libenc
67 11872 : L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */
68 11872 : L_tot = L_add_sat( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */
69 : #else
70 : L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */
71 : L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */
72 : #endif
73 : }
74 :
75 : /* Find the number of right shifts to do on y32[] so that */
76 : /* 6.0 x sumation of max of dn[] in each track not saturate. */
77 :
78 2968 : j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
79 :
80 192920 : FOR( i = 0; i < L_SUBFR; i++ )
81 : {
82 189952 : dn[i] = round_fx( L_shl( y32[i], j ) ); /*Qx+15+j-16*/
83 : }
84 2968 : return;
85 : }
86 :
87 0 : void corr_hh_ivas_fx(
88 : const Word16 *h, /* i : target signal e(norm_s(h1[0])+1) */
89 : Word16 *y, /* o : correlation between x[] and h[] Q_new + 1 */
90 : Word16 *Qy,
91 : const Word16 L_subfr /* i : length of the subframe Q0*/
92 : )
93 : {
94 : Word16 i, j, k;
95 : Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot;
96 : #ifndef ISSUE_1867_replace_overflow_libenc
97 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
98 : Flag Overflow = 0;
99 : move16();
100 : #endif
101 : #endif
102 :
103 : /* first keep the result on 32 bits and find absolute maximum */
104 0 : L_tot = L_deposit_l( 1 );
105 :
106 0 : FOR( k = 0; k < NB_TRACK; k++ )
107 : {
108 0 : L_maxloc = L_deposit_l( 0 );
109 0 : FOR( i = k; i < L_subfr; i += STEP )
110 : {
111 0 : L_tmp = L_mac( 1L, shr( h[i], 3 ), shr( h[0], 3 ) ); /* 1 -> to avoid null dn[] */ // 2*(15 - norm_s(h[0]) -3) - 1
112 0 : FOR( j = i; j < L_subfr - 1; j++ )
113 : {
114 : #ifdef ISSUE_1867_replace_overflow_libenc
115 0 : L_tmp = L_mac_sat( L_tmp, shr( h[j + 1], 3 ), shr( h[j + 1 - i], 3 ) ); // 2*(15 - norm_s(h[0]) -3) - 1 //?sat
116 : #else
117 : L_tmp = L_mac_o( L_tmp, shr( h[j + 1], 3 ), shr( h[j + 1 - i], 3 ), &Overflow ); // 2*(15 - norm_s(h[0]) -3) - 1
118 : #endif
119 : }
120 :
121 0 : y32[i] = L_tmp; // 2*(15 - norm_s(h[0]) -3) - 1
122 0 : move32();
123 0 : L_tmp = L_abs( L_tmp );
124 0 : L_maxloc = L_max( L_tmp, L_maxloc ); // 2*(15 - norm_s(h[0]) -3) - 1
125 : }
126 : /* tot += 3*max / 8 */
127 0 : L_maxloc = L_shr( L_maxloc, 2 );
128 : #ifdef ISSUE_1867_replace_overflow_libenc
129 0 : L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */
130 0 : L_tot = L_add_sat( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */
131 : #else
132 : L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */
133 : L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */
134 : #endif
135 : }
136 :
137 : /* Find the number of right shifts to do on y32[] so that */
138 : /* 6.0 x sumation of max of dn[] in each track not saturate. */
139 :
140 0 : j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
141 :
142 0 : FOR( i = 0; i < L_subfr; i++ )
143 : {
144 0 : y[i] = round_fx( L_shl( y32[i], j ) ); // 2*(15 - norm_s(h[0])) - 1 +j - 16
145 0 : move16();
146 : }
147 :
148 0 : *Qy = sub( add( shl( sub( 15 - 3, norm_s( h[0] ) ), 1 ), j ), 17 ); // h scaled down by 3 to avoid saturation while accumulating Ltmp
149 0 : move16();
150 0 : return;
151 : }
152 :
153 212564 : void corr_xh_ivas_fx(
154 : const Word16 x[], /* i : target signal Qx*/
155 : const Word16 Qx,
156 : Word16 dn[], /* o : correlation between x[] and h[] Qdn*/
157 : Word16 *Qdn,
158 : const Word16 h[], /* i : impulse response (of weighted synthesis filter) (Q14 - norm_s(h[0]))*/
159 : const Word16 L_subfr /* i : length of the subframe Q0*/
160 : )
161 : {
162 : Word16 i, j, k;
163 : Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot;
164 : #ifndef ISSUE_1867_replace_overflow_libenc
165 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
166 : Flag Overflow = 0;
167 : move16();
168 : #endif
169 : #endif
170 :
171 : /* first keep the result on 32 bits and find absolute maximum */
172 212564 : L_tot = L_deposit_l( 0 );
173 :
174 1062820 : FOR( k = 0; k < NB_TRACK; k++ )
175 : {
176 850256 : L_maxloc = L_deposit_l( 0 );
177 14716240 : FOR( i = k; i < L_subfr; i += STEP )
178 : {
179 13865984 : L_tmp = L_mac( 0, x[i], h[0] ); // Qx+(14 - norm_s(h[0])) + 1
180 467405312 : FOR( j = i; j < L_subfr - 1; j++ )
181 : {
182 : #ifdef ISSUE_1867_replace_overflow_libenc
183 453539328 : L_tmp = L_mac_sat( L_tmp, x[j + 1], h[j + 1 - i] ); // Qx+(14 - norm_s(h[0])) + 1
184 : #else
185 : L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); // Qx+(14 - norm_s(h[0])) + 1
186 : #endif
187 : }
188 :
189 13865984 : y32[i] = L_tmp; // Qx+(14 - norm_s(h[0])) + 1
190 13865984 : move32();
191 13865984 : L_tmp = L_abs( L_tmp );
192 13865984 : L_maxloc = L_max( L_tmp, L_maxloc ); // Qx+(14 - norm_s(h[0])) +1
193 : }
194 : /* tot += 3*max / 8 */
195 850256 : L_maxloc = L_shr( L_maxloc, 2 );
196 : #ifdef ISSUE_1867_replace_overflow_libenc
197 850256 : L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */
198 850256 : L_tot = L_add_sat( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */
199 : #else
200 : L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */
201 : L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */
202 : #endif
203 : }
204 :
205 : /* Find the number of right shifts to do on y32[] so that */
206 : /* 6.0 x sumation of max of dn[] in each track not saturate. */
207 :
208 212564 : j = sub( norm_l( L_tot ), 4 ); /* 4 -> 16 x tot */
209 :
210 14078548 : FOR( i = 0; i < L_subfr; i++ )
211 : {
212 13865984 : dn[i] = round_fx( L_shl( y32[i], j ) ); // Qx+(14 - norm_s(h[0])) + 1 +j - 16
213 13865984 : move16();
214 : }
215 :
216 212564 : *Qdn = sub( add( add( Qx, add( sub( 14, norm_s( h[0] ) ), 1 ) ), j ), 16 );
217 212564 : move16();
218 212564 : return;
219 : }
|