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" /* for wmc_tool */
7 : #include "cnst.h"
8 : //#include "prot_fx.h"
9 : #include "rom_com_fx.h"
10 : #include "rom_com.h"
11 : #include "stat_com.h"
12 : #include "prot_fx.h" /* Function prototypes */
13 : #include "prot_fx_enc.h" /* Function prototypes */
14 :
15 : /*-------------------------------------------------------------------*
16 : * SFM_Cal_fx()
17 : *
18 : *
19 : *--------------------------------------------------------------------*/
20 :
21 0 : Word32 SFM_Cal_fx(
22 : Word32 magn[], /*Q = Qx*/
23 : Word16 n /*Q = Q0*/
24 : )
25 : {
26 : /* Counted Dymamic RAM: 16 words */
27 : Word32 logCurFlatness;
28 : Word32 magn_abs, frac, logMagn, sumLogMagn, sumMagn;
29 : Word16 i, norm_value, logSumMagn, logn;
30 0 : sumLogMagn = L_deposit_l( 0 );
31 0 : sumMagn = L_deposit_l( 0 );
32 0 : FOR( i = 0; i < n; i++ )
33 : {
34 : /* log2(magn(i)) */
35 0 : magn_abs = L_abs( magn[i] );
36 0 : norm_value = norm_l( L_max( magn_abs, 1 ) );
37 : /* next two codes lost precision. */
38 0 : frac = L_and( L_shr( L_shl( magn_abs, norm_value ), 22 ), 0xFF );
39 0 : logMagn = L_deposit_l( add( shl( sub( 30, norm_value ), 8 ), kLog2TableFrac_x[frac] ) );
40 : ; /* Q8 */
41 : /* sum(log2(magn(i))) */
42 0 : sumLogMagn = L_add( sumLogMagn, logMagn ); /* Q8 */
43 :
44 0 : sumMagn = L_add_sat( sumMagn, magn_abs ); /*Qx*/
45 : }
46 :
47 0 : IF( EQ_32( sumMagn, MAX_32 ) )
48 : {
49 0 : sumMagn = L_deposit_l( 0 );
50 0 : FOR( i = 0; i < n; i++ )
51 : {
52 0 : magn_abs = L_shr( L_abs( magn[i] ), 8 ); /* Qx-8 */
53 0 : sumMagn = L_add( sumMagn, magn_abs );
54 : }
55 : /* log2(sumMagn) */
56 0 : norm_value = norm_l( sumMagn );
57 0 : frac = L_and( L_shr( L_shl( sumMagn, norm_value ), 22 ), 0xFF );
58 0 : logSumMagn = add( shl( sub( 38, norm_value ), 8 ), kLog2TableFrac_x[frac] ); /* Q8 */
59 : }
60 : ELSE
61 : {
62 : /* log2(sumMagn) */
63 0 : norm_value = norm_l( sumMagn );
64 0 : frac = L_and( L_shr( L_shl( sumMagn, norm_value ), 22 ), 0xFF );
65 0 : logSumMagn = add( shl( sub( 30, norm_value ), 8 ), kLog2TableFrac_x[frac] ); /* Q8 */
66 : }
67 :
68 : /* log2(n) */
69 0 : norm_value = norm_l( n );
70 0 : frac = L_and( L_shr( L_shl( n, norm_value ), 22 ), 0xFF );
71 0 : logn = add( shl( sub( 30, norm_value ), 8 ), kLog2TableFrac_x[frac] ); /* Q8 */
72 :
73 :
74 0 : logMagn = L_sub( L_mult0( n, sub( logSumMagn, logn ) ), sumLogMagn );
75 0 : logMagn = (Word32) L_max( 0, logMagn );
76 :
77 0 : logCurFlatness = L_deposit_l( div_l( L_shl( logMagn, 1 ), n ) );
78 0 : frac = L_and( logCurFlatness, 0xFF );
79 0 : norm_value = (Word16) L_shr( logCurFlatness, 8 );
80 :
81 0 : logCurFlatness = L_sub( kExp2TableFrac_x[frac], 33 );
82 0 : logCurFlatness = L_shl( logCurFlatness, sub( 16, norm_value ) ); /* Q31 */
83 :
84 :
85 0 : return logCurFlatness;
86 : }
|