|
6 | 6 |
|
7 | 7 | #include <sof/audio/format.h> |
8 | 8 | #include <sof/math/decibels.h> |
| 9 | +#include <sof/math/exp_fcn.h> |
9 | 10 | #include <stdint.h> |
10 | 11 |
|
11 | 12 | #define ONE_Q20 Q_CONVERT_FLOAT(1.0, 20) /* Use Q12.20 */ |
12 | | -#define ONE_Q23 Q_CONVERT_FLOAT(1.0, 23) /* Use Q9.23 */ |
13 | 13 | #define TWO_Q27 Q_CONVERT_FLOAT(2.0, 27) /* Use Q5.27 */ |
14 | 14 | #define MINUS_TWO_Q27 Q_CONVERT_FLOAT(-2.0, 27) /* Use Q5.27 */ |
15 | 15 | #define LOG10_DIV20_Q27 Q_CONVERT_FLOAT(0.1151292546, 27) /* Use Q5.27 */ |
16 | 16 |
|
17 | | -/* Exponent function for small values of x. This function calculates |
18 | | - * fairly accurately exponent for x in range -2.0 .. +2.0. The iteration |
19 | | - * uses first 11 terms of Taylor series approximation for exponent |
20 | | - * function. With the current scaling the numerator just remains under |
21 | | - * 64 bits with the 11 terms. |
22 | | - * |
23 | | - * See https://en.wikipedia.org/wiki/Exponential_function#Computation |
24 | | - * |
25 | | - * The input is Q3.29 |
26 | | - * The output is Q9.23 |
27 | | - */ |
28 | | - |
29 | | -static int32_t exp_small_fixed(int32_t x) |
30 | | -{ |
31 | | - int64_t p; |
32 | | - int64_t num = Q_SHIFT_RND(x, 29, 23); |
33 | | - int32_t y0 = (int32_t)num; |
34 | | - int32_t den = 1; |
35 | | - int32_t inc; |
36 | | - int k; |
37 | | - |
38 | | - /* Numerator is x^k, denominator is k! */ |
39 | | - for (k = 2; k < 12; k++) { |
40 | | - p = num * x; /* Q9.23 x Q3.29 -> Q12.52 */ |
41 | | - num = Q_SHIFT_RND(p, 52, 23); |
42 | | - den = den * k; |
43 | | - inc = (int32_t)(num / den); |
44 | | - y0 += inc; |
45 | | - } |
46 | | - |
47 | | - return y0 + ONE_Q23; |
48 | | -} |
49 | | - |
50 | 17 | /* Decibels to linear conversion: The function uses exp() to calculate |
51 | 18 | * the linear value. The argument is multiplied by log(10)/20 to |
52 | 19 | * calculate equivalent of 10^(db/20). |
@@ -105,10 +72,10 @@ int32_t exp_fixed(int32_t x) |
105 | 72 | n++; |
106 | 73 | } |
107 | 74 |
|
108 | | - /* exp_small_fixed() input is Q3.29, while x1 is Q5.27 |
109 | | - * exp_small_fixed() output is Q9.23, while y0 is Q12.20 |
| 75 | + /* sofm_exp_int32() input is Q4.28, while x1 is Q5.27 |
| 76 | + * sofm_exp_int32() output is Q9.23, while y0 is Q12.20 |
110 | 77 | */ |
111 | | - y0 = Q_SHIFT_RND(exp_small_fixed(Q_SHIFT_LEFT(xs, 27, 29)), 23, 20); |
| 78 | + y0 = Q_SHIFT_RND(sofm_exp_int32(Q_SHIFT_LEFT(xs, 27, 28)), 23, 20); |
112 | 79 | y = ONE_Q20; |
113 | 80 | for (i = 0; i < (1 << n); i++) |
114 | 81 | y = (int32_t)Q_MULTSR_32X32((int64_t)y, y0, 20, 20, 20); |
|
0 commit comments