|
1 | 1 | /* SPDX-License-Identifier: BSD-3-Clause
|
2 | 2 | *
|
3 |
| - * Copyright(c) 2022 Intel Corporation. All rights reserved. |
| 3 | + * Copyright(c) 2022-2025 Intel Corporation. |
4 | 4 | *
|
5 | 5 | * Author: Shriram Shastry <[email protected]>
|
| 6 | + * Seppo Ingalsuo <[email protected]> |
6 | 7 | *
|
7 | 8 | */
|
8 | 9 | #ifndef __SOFM_EXP_FCN_H__
|
|
26 | 27 |
|
27 | 28 | #endif
|
28 | 29 |
|
29 |
| -/* TODO: Is there a MCPS difference */ |
30 |
| -#define USING_QCONVERT 1 |
| 30 | +/* Q5.27 int32(round(log((2^31 - 1)/2^20) * 2^27)) */ |
| 31 | +#define SOFM_EXP_FIXED_INPUT_MAX 1023359037 |
31 | 32 |
|
32 |
| -#if USING_QCONVERT |
| 33 | +/* Q8.24 int32(round((log((2^31 - 1)/2^20) * 20 / log(10)) * 2^24)) */ |
| 34 | +#define SOFM_DB2LIN_INPUT_MAX 1111097957 |
33 | 35 |
|
34 |
| -#include <sof/audio/format.h> |
35 |
| -#define SOFM_EXP_FIXED_INPUT_MIN Q_CONVERT_FLOAT(-11.5, 27) /* Q5.27 */ |
36 |
| -#define SOFM_EXP_FIXED_INPUT_MAX Q_CONVERT_FLOAT(7.6245, 27) /* Q5.27 */ |
37 |
| -#define SOFM_EXP_TWO_Q27 Q_CONVERT_FLOAT(2.0, 27) /* Q5.27 */ |
38 |
| -#define SOFM_EXP_MINUS_TWO_Q27 Q_CONVERT_FLOAT(-2.0, 27) /* Q5.27 */ |
39 |
| -#define SOFM_EXP_ONE_Q20 Q_CONVERT_FLOAT(1.0, 20) /* Q12.20 */ |
40 |
| -#define SOFM_EXP_MINUS_100_Q24 Q_CONVERT_FLOAT(-100.0, 24) /* Q8.24 */ |
41 |
| -#define SOFM_EXP_LOG10_DIV20_Q27 Q_CONVERT_FLOAT(0.1151292546, 27) /* Q5.27 */ |
42 |
| - |
43 |
| -#else |
44 |
| - |
45 |
| -#define SOFM_EXP_FIXED_INPUT_MIN -1543503872 /* Q_CONVERT_FLOAT(-11.5, 27) */ |
46 |
| -#define SOFM_EXP_FIXED_INPUT_MAX 1023343067 /* Q_CONVERT_FLOAT(7.6245, 27) */ |
47 |
| -#define SOFM_EXP_TWO_Q27 268435456 /* Q_CONVERT_FLOAT(2.0, 27) */ |
48 |
| -#define SOFM_EXP_MINUS_TWO_Q27 -268435456 /* Q_CONVERT_FLOAT(-2.0, 27) */ |
49 |
| -#define SOFM_EXP_ONE_Q20 1048576 /* Q_CONVERT_FLOAT(1.0, 20) */ |
50 |
| -#define SOFM_EXP_MINUS_100_Q24 -1677721600 /* Q_CONVERT_FLOAT(-100.0, 24) */ |
51 |
| -#define SOFM_EXP_LOG10_DIV20_Q27 15452387 /* Q_CONVERT_FLOAT(0.1151292546, 27) */ |
| 36 | +/** |
| 37 | + * Calculates exponent function exp(x) = e^x with accurate and efficient technique that |
| 38 | + * includes range reduction operations, approximation with Taylor series, and reconstruction |
| 39 | + * operations to compensate the range reductions. |
| 40 | + * @param x The input argument as Q4.28 from -8 to +8 |
| 41 | + * @return The calculated e^x value as Q13.19 from 3.3546e-04 to 2981.0 |
| 42 | + */ |
| 43 | +int32_t sofm_exp_approx(int32_t x); |
52 | 44 |
|
53 |
| -#endif |
| 45 | +/** |
| 46 | + * Calculated exponent function exp(x) = e^x by using sofm_exp_approx(). The input range for |
| 47 | + * large arguments is internally reduced to -8 to +8 with rule exp(x) = exp(x/2) * exp(x/2) |
| 48 | + * and reconstructed back. This function is essentially a wrapper for compatibility with |
| 49 | + * existing usage of exp() function and Q-format choice. Note that the return value saturates |
| 50 | + * to INT32_MAX with input arguments larger than 7.6246. |
| 51 | + * @param x The input argument as Q5.27 from -16 to +16 |
| 52 | + * @return The calculated e^x value as Q12.20 |
| 53 | + */ |
| 54 | +int32_t sofm_exp_fixed(int32_t x); |
54 | 55 |
|
55 |
| -#define SOFM_EXP_BIT_MASK_LOW_Q27P5 0x0000000008000000 |
56 |
| -#define SOFM_EXP_BIT_MASK_Q62P2 0x4000000000000000LL |
57 |
| -#define SOFM_EXP_QUOTIENT_SCALE 0x40000000 |
58 |
| -#define SOFM_EXP_TERMS_Q23P9 0x800000 |
59 |
| -#define SOFM_EXP_LSHIFT_BITS 0x2000 |
60 | 56 |
|
61 |
| -int32_t sofm_exp_int32(int32_t x); |
62 |
| -int32_t sofm_exp_fixed(int32_t x); |
| 57 | +/** |
| 58 | + * Converts a decibels value to liner amplitude lin = 10^(db/20) value with optimized |
| 59 | + * equation exp(db * log(10)/20). Note that due to range limitation of sofm_exp_fixed() |
| 60 | + * the output saturates to maximum with about +66 dB input. |
| 61 | + * @param db Decibels value in Q8.24 format, from -128 to +66.226 |
| 62 | + * @return Linear value in Q12.20 format, from 3.9811e-07 to 2048 |
| 63 | + */ |
63 | 64 | int32_t sofm_db2lin_fixed(int32_t db);
|
64 | 65 |
|
65 | 66 | #endif /* __SOFM_EXP_FCN_H__ */
|
0 commit comments