1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef AE_MATH_H
5 #define AE_MATH_H
6 
7 #include <stdint.h>
8 #include <math.h>
9 
10 #ifdef __arm__
11 #include "arm_math.h"
12 #endif
13 
14 #define AE_PI       3.14159265358979323846f
15 
16 #define EPS (1e-7f)
17 
18 #define AE_CLAMP(x,lo,hi) ((x) < (lo) ? (lo) : (x) > (hi) ? (hi) : (x))
19 
20 #ifdef __arm__
21 #define AE_SSAT16(x) __SSAT((int32_t)(x), 16)
22 #define AE_SSAT24(x) __SSAT((int32_t)(x), 24)
23 #else
24 #define AE_SSAT16(x) AE_CLAMP(x,-32768,32767)
25 #define AE_SSAT24(x) AE_CLAMP(x,-16777216,16777215)
26 #endif
27 
28 #define AE_ABS(x) ((x) > 0 ? (x) : (-(x)))
29 
30 #define AE_FLOOR(x) (floorf(x))
31 
32 #define AE_ROUND(x) (roundf(x))
33 
34 #define AE_INT(x) ((int)(x))
35 
36 // deal with x > -1 && x < 0
37 #define AE_SIGN(x) ((AE_INT(x) == 0 && (x) < 0) ? "-" : "")
38 
39 #define AE_FRAC(x) ((int)(((x) > 0 ? ((x) - AE_INT(x)) : (AE_INT(x) - (x))) * 1000000))
40 
41 #define AE_MIN(a,b) ((a) < (b) ? (a) : (b))
42 
43 #define AE_MAX(a,b) ((a) > (b) ? (a) : (b))
44 
45 #define SQUARE(x) ((x) * (x))
46 
47 #define DB2LIN(x) (powf(10.f, (x) / 20.f))
48 
49 #ifdef VQE_SIMULATE
50 #define AE_SIN(x) sinf(x)
51 #define AE_COS(x) cosf(x)
52 #else
53 #define AE_SIN(x) arm_sin_f32(x)
54 #define AE_COS(x) arm_cos_f32(x)
55 #endif
56 
57 int ae_gcd(int u, int v);
58 
59 int ipow(int base, int exp);
60 
61 float ipowf(float base, int exp);
62 
63 float pow_int(float base, int exp);
64 
65 float expint(int n, float x);
66 
67 float sqrt_approx(float z);
68 
69 #define AE_RAND_MAX (32767)
70 
71 void ae_srand(unsigned int init);
72 
73 int ae_rand(void);
74 
75 void speech_conv(float *x, float *y, short len1,int len2, float *out);
76 
77 void scale_int16(int16_t *pDst, int16_t *pSrc, float scale, uint32_t blockSize);
78 
79 int32_t nextpow2(int32_t N);
80 
81 #endif
82