Line data Source code
1 : /*====================================================================================
2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
3 : ====================================================================================*/
4 :
5 :
6 : #include <stdint.h>
7 : #include "options.h"
8 : #include <assert.h>
9 : #include "basop_util.h"
10 :
11 : #define PI_HALF_0Q15 51472 /* ~=round(pi/2*2^15) */
12 : #define PI2_15Q16 0x0006487F /* ~=round(2*PI*2^16) */
13 : #define PI2_10Q21 13176795 /* ~=round(2*PI*2^21) */
14 : #define PI2_11Q20 6588397 /* ~=round(2*PI*2^20) */
15 : #define P54_1Q14 8847 /* ~=round(0.54*2^14) */
16 : #define P54_0Q15 17695 /* ~=round(0.54*2^15) */
17 : #define P46_0Q15 15073 /* ~=round(0.46*2^15) */
18 : #define P92_0Q15 30147 /* ~=round(0.92*2^15) */
19 : #include "options.h"
20 : #include "rom_basop_util.h"
21 : #include "prot_fx.h"
22 :
23 2360 : void ham_cos_window(
24 : Word16 *fh, /* o: 0Q15 */
25 : const Word16 n1, /* i: */
26 : const Word16 n2 /* i: */
27 : )
28 : {
29 : Word16 i;
30 : Word32 cte, cc;
31 : #ifndef ISSUE_1836_replace_overflow_libcom__remnant
32 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
33 : Flag Overflow = 0;
34 : move16();
35 : #endif
36 : #endif
37 :
38 :
39 2360 : assert( n1 >= 102 ); /* if n1 is too low -> overflow in div_l */
40 : /* cte = PI2/(Float32)(2*n1 - 1); */
41 : BASOP_SATURATE_WARNING_OFF_EVS
42 2360 : cte = L_deposit_l( div_l( PI2_10Q21, sub( shl( n1, 1 ), 1 ) ) ); /*0Q15*/
43 : BASOP_SATURATE_WARNING_ON_EVS
44 2360 : cc = 0;
45 2360 : move32();
46 1284920 : FOR( i = 0; i < n1; i++ )
47 : {
48 : /* fh_f[i] = 0.54f - 0.46f * (Float32)cos(cc); */
49 : BASOP_SATURATE_WARNING_OFF_EVS
50 : #ifdef ISSUE_1836_replace_overflow_libcom__remnant
51 1282560 : fh[i] = sub_sat( P54_0Q15, mult_r( getCosWord16( round_fx_sat( L_shl_sat( cc, 9 ) ) ), P92_0Q15 ) ); /*0Q15*/
52 : #else
53 : fh[i] = sub_o( P54_0Q15, mult_r( getCosWord16( round_fx_o( L_shl_o( cc, 9, &Overflow ), &Overflow ) ), P92_0Q15 ), &Overflow ); /*0Q15*/
54 : #endif
55 1282560 : move16();
56 : BASOP_SATURATE_WARNING_ON_EVS
57 1282560 : cc = L_add( cc, cte ); /*0Q15*/
58 : }
59 :
60 2360 : assert( n2 >= 26 ); /* if n2 is too low -> overflow in div_l */
61 : /* cte = PI2/(Float32)(4*n2 - 1); */
62 2360 : cte = L_deposit_l( div_l( PI2_11Q20, sub( shl( n2, 2 ), 1 ) ) ); /*0Q15*/
63 2360 : cc = 0;
64 2360 : move32();
65 :
66 2360 : add( n1, n2 );
67 : BASOP_SATURATE_WARNING_OFF_EVS
68 429880 : FOR( i = n1; i < n1 + n2; i++ )
69 : {
70 : /* fh_f[i] = (Float32)cos(cc); */
71 : #ifdef ISSUE_1836_replace_overflow_libcom__remnant
72 427520 : fh[i] = shl_sat( getCosWord16( round_fx( L_shl( cc, 10 ) ) ), 1 ); /*0Q15*/
73 : #else
74 : fh[i] = shl_o( getCosWord16( round_fx( L_shl( cc, 10 ) ) ), 1, &Overflow ); /*0Q15*/
75 : #endif
76 427520 : move16();
77 427520 : cc = L_add( cc, cte );
78 : }
79 : BASOP_SATURATE_WARNING_ON_EVS
80 :
81 :
82 2360 : return;
83 : }
84 :
85 1320 : void ham_cos_window_ivas(
86 : Word16 *fh, /* o: 0Q15 */
87 : const Word16 n1, /* i: */
88 : const Word16 n2 /* i: */
89 : )
90 : {
91 : Word16 cc_fx; // Q15
92 : Word16 i;
93 :
94 : // cte = PI2 / (float) ( 2 * n1 - 1 );
95 : // cte_fx = div_s(1, sub(shl(n1, 1), 1));
96 1320 : cc_fx = 0;
97 1320 : move16();
98 90328 : FOR( i = 0; i < n1; i++ )
99 : {
100 89008 : *fh++ = sub( 17694 /*0.54.Q15*/, mult( getCosWord16R2( cc_fx ), 15073 /*0.46.Q15*/ ) );
101 89008 : move16();
102 89008 : cc_fx = div_s( add( i, 1 ), sub( shl( n1, 1 ), 1 ) ); // add(cc_fx, cte_fx);
103 : }
104 :
105 : // cte = PI2 / (float) ( 4 * n2 - 1 );
106 : // cte_fx = div_s(1, sub(shl(n2, 2), 1));
107 1320 : cc_fx = 0;
108 1320 : move16();
109 90328 : FOR( i = 0; i < n2; i++ )
110 : {
111 89008 : *fh++ = getCosWord16R2( cc_fx );
112 89008 : move16();
113 89008 : cc_fx = div_s( add( i, 1 ), sub( shl( n1, 2 ), 1 ) );
114 : }
115 :
116 1320 : return;
117 : }
|