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"
7 : #include "basop_util.h"
8 : #include "cnst.h"
9 : //#include "prot_fx.h"
10 : #include "prot_fx.h" /* Function prototypes */
11 : #include "prot_fx_enc.h" /* Function prototypes */
12 :
13 : /*-------------------------------------------------------------------*
14 : * tfaCalcEnv()
15 : *
16 : *
17 : *-------------------------------------------------------------------*/
18 :
19 604 : void tfaCalcEnv_fx(
20 : const Word16 *shb_speech,
21 : Word32 *enr )
22 : {
23 : Word16 i, j, k;
24 :
25 604 : k = 0;
26 604 : move16();
27 10268 : FOR( i = 0; i < N_TEC_TFA_SUBFR; i++ )
28 : {
29 9664 : enr[i] = L_deposit_l( 0 );
30 9664 : move32();
31 202944 : FOR( j = 0; j < L_TEC_TFA_SUBFR16k; j++ )
32 : {
33 193280 : enr[i] = L_mac0_sat( enr[i], shb_speech[k], shb_speech[k] );
34 193280 : move32();
35 193280 : k = add( k, 1 );
36 : }
37 : }
38 604 : return;
39 : }
40 :
41 604 : Word16 tfaEnc_TBE_fx(
42 : const Word32 *enr,
43 : const Word16 last_core,
44 : const Word16 *voicing, /* Q15 */
45 : const Word16 *pitch_buf, /* Q6 */
46 : const Word16 Q_enr )
47 : {
48 : Word16 i;
49 : Word32 m_g, m_a; /* m_g: geometrical mean, m_a: arithmetical mean */
50 : Word16 voicing_sum;
51 : Word16 pitch_buf_sum;
52 : Word32 m_a_bottom;
53 : Word16 tfa_flag;
54 :
55 : Word32 L_tmp, L_tmp1;
56 : Word16 exp;
57 :
58 604 : m_a_bottom = L_shl( 625, Q_enr ); /* 10000.0 / N_TEC_TFA_SUBFR in Q_enr */
59 :
60 604 : tfa_flag = 0;
61 604 : move16();
62 :
63 604 : L_tmp = L_deposit_l( 0 );
64 604 : m_a = L_deposit_l( 0 );
65 604 : m_g = L_deposit_l( 0 );
66 :
67 10268 : FOR( i = 0; i < N_TEC_TFA_SUBFR; i++ )
68 : {
69 9664 : IF( enr[i] != 0 )
70 : {
71 9560 : m_a = L_add( m_a, L_shr( enr[i], 4 ) ); /* Q_enr */
72 9560 : exp = norm_l( enr[i] );
73 9560 : L_tmp = BASOP_Util_Log2( L_shl( enr[i], exp ) );
74 9560 : exp = sub( sub( 31, exp ), Q_enr );
75 9560 : L_tmp = L_add( L_shl( L_deposit_h( exp ), 9 ), L_tmp );
76 9560 : m_g = L_add( m_g, L_shr( L_tmp, 4 ) );
77 : }
78 : }
79 :
80 : /* energy lower limit */
81 604 : IF( LT_32( m_a, m_a_bottom ) )
82 : {
83 68 : tfa_flag = 0;
84 68 : move16();
85 : }
86 : ELSE
87 : {
88 536 : exp = norm_l( m_a );
89 536 : L_tmp = BASOP_Util_Log2( L_shl( m_a, exp ) );
90 536 : exp = sub( sub( 31, exp ), Q_enr );
91 536 : m_a = L_add( L_shl( L_deposit_h( exp ), 9 ), L_tmp ); /* Q25 */
92 536 : L_tmp = L_add( m_a, -17266211l /*log10(0.7f)/log10(2.f) Q25*/ );
93 536 : L_tmp1 = L_add( m_a, -33554432l /*log10(0.5f)/log10(2.f) Q25*/ );
94 :
95 536 : voicing_sum = add( shr( voicing[0], 1 ), shr( voicing[1], 1 ) );
96 :
97 536 : pitch_buf_sum = shr( add( shr( pitch_buf[0], 1 ), shr( pitch_buf[1], 1 ) ), 1 );
98 536 : pitch_buf_sum = add( pitch_buf_sum, shr( add( shr( pitch_buf[2], 1 ), shr( pitch_buf[3], 1 ) ), 1 ) );
99 :
100 536 : test();
101 536 : test();
102 536 : test();
103 536 : test();
104 536 : test();
105 1020 : if ( ( GT_32( m_g, L_tmp ) && GT_16( pitch_buf_sum, 7040 /*110 Q6*/ ) && GT_16( voicing_sum, 22938 /*0.70 Q15*/ ) ) ||
106 507 : ( EQ_16( last_core, TCX_20_CORE ) && GT_32( m_g, L_tmp1 ) && LT_16( voicing_sum, 22938 /*0.70 Q15*/ ) ) )
107 : {
108 58 : tfa_flag = 1;
109 58 : move16();
110 : }
111 : }
112 :
113 604 : return tfa_flag;
114 : }
|