diff --git a/src/audio/drc/drc_generic.c b/src/audio/drc/drc_generic.c index 1019aeac3691..298f89d045e8 100644 --- a/src/audio/drc/drc_generic.c +++ b/src/audio/drc/drc_generic.c @@ -36,7 +36,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x) * beta = -expf(k * linear_threshold) / k * gamma = -k * x */ - knee_exp_gamma = exp_fixed(Q_MULTSR_32X32((int64_t)x, -p->K, 31, 20, 27)); /* Q12.20 */ + knee_exp_gamma = sofm_exp_fixed(Q_MULTSR_32X32((int64_t)x, -p->K, 31, 20, 27)); /* Q12.20 */ return p->knee_alpha + Q_MULTSR_32X32((int64_t)p->knee_beta, knee_exp_gamma, 24, 20, 24); } @@ -66,8 +66,11 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) * => y/x = ratio_base * x^(s - 1) * => y/x = ratio_base * e^(log(x) * (s - 1)) */ - exp_knee = exp_fixed(Q_MULTSR_32X32((int64_t)drc_log_fixed(Q_SHIFT_RND(x, 31, 26)), - (p->slope - ONE_Q30), 26, 30, 27)); /* Q12.20 */ + exp_knee = sofm_exp_fixed(Q_MULTSR_32X32 + ((int64_t)drc_log_fixed + (Q_SHIFT_RND(x, 31, 26)), + (p->slope - ONE_Q30), + 26, 30, 27)); /* Q12.20 */ y = Q_MULTSR_32X32((int64_t)p->ratio_base, exp_knee, 30, 20, 30); } diff --git a/src/audio/drc/drc_hifi3.c b/src/audio/drc/drc_hifi3.c index 0371bf6b1f9c..82f403fc435f 100644 --- a/src/audio/drc/drc_hifi3.c +++ b/src/audio/drc/drc_hifi3.c @@ -42,7 +42,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x) * gamma = -k * x */ gamma = drc_mult_lshift(x, -p->K, drc_get_lshift(31, 20, 27)); - knee_exp_gamma = exp_fixed(gamma); + knee_exp_gamma = sofm_exp_fixed(gamma); knee_curve_k = drc_mult_lshift(p->knee_beta, knee_exp_gamma, drc_get_lshift(24, 20, 24)); knee_curve_k = AE_ADD32(knee_curve_k, p->knee_alpha); return knee_curve_k; @@ -78,7 +78,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) tmp = AE_SRAI32R(x, 5); /* Q1.31 -> Q5.26 */ tmp = drc_log_fixed(tmp); /* Q6.26 */ tmp2 = AE_SUB32(p->slope, ONE_Q30); /* Q2.30 */ - exp_knee = exp_fixed(drc_mult_lshift(tmp, tmp2, drc_get_lshift(26, 30, 27))); + exp_knee = sofm_exp_fixed(drc_mult_lshift(tmp, tmp2, drc_get_lshift(26, 30, 27))); y = drc_mult_lshift(p->ratio_base, exp_knee, drc_get_lshift(30, 20, 30)); } diff --git a/src/audio/drc/drc_hifi4.c b/src/audio/drc/drc_hifi4.c index 93447ecabd90..304874bb668c 100644 --- a/src/audio/drc/drc_hifi4.c +++ b/src/audio/drc/drc_hifi4.c @@ -64,7 +64,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x) * gamma = -k * x */ gamma = drc_mult_lshift(x, -p->K, LSHIFT_QX31_QY20_QZ27); - knee_exp_gamma = exp_fixed(gamma); + knee_exp_gamma = sofm_exp_fixed(gamma); knee_curve_k = drc_mult_lshift(p->knee_beta, knee_exp_gamma, LSHIFT_QX24_QY20_QZ24); knee_curve_k = AE_ADD32(knee_curve_k, p->knee_alpha); return knee_curve_k; @@ -100,7 +100,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x) tmp = AE_SRAI32R(x, 5); /* Q1.31 -> Q5.26 */ tmp = drc_log_fixed(tmp); /* Q6.26 */ tmp2 = AE_SUB32(p->slope, ONE_Q30); /* Q2.30 */ - exp_knee = exp_fixed(drc_mult_lshift(tmp, tmp2, LSHIFT_QX26_QY30_QZ27)); + exp_knee = sofm_exp_fixed(drc_mult_lshift(tmp, tmp2, LSHIFT_QX26_QY30_QZ27)); y = drc_mult_lshift(p->ratio_base, exp_knee, LSHIFT_QX30_QY20_QZ30); } diff --git a/src/audio/drc/drc_math_generic.c b/src/audio/drc/drc_math_generic.c index c1fb1171a879..cad152fc6a98 100644 --- a/src/audio/drc/drc_math_generic.c +++ b/src/audio/drc/drc_math_generic.c @@ -234,7 +234,7 @@ inline int32_t drc_pow_fixed(int32_t x, int32_t y) return 0; /* x^y = expf(y * log(x)) */ - return exp_fixed(q_mult(y, drc_log_fixed(x), 30, 26, 27)); + return sofm_exp_fixed(q_mult(y, drc_log_fixed(x), 30, 26, 27)); } #undef q_multq diff --git a/src/include/sof/math/decibels.h b/src/include/sof/math/decibels.h index a0336e9be9b9..8fceed5b2a25 100644 --- a/src/include/sof/math/decibels.h +++ b/src/include/sof/math/decibels.h @@ -16,7 +16,7 @@ #define DB2LIN_FIXED_INPUT_QY 24 #define DB2LIN_FIXED_OUTPUT_QY 20 -int32_t exp_fixed(int32_t x); /* Input is Q5.27, output is Q12.20 */ +int32_t sofm_exp_fixed(int32_t x); /* Input is Q5.27, output is Q12.20 */ int32_t db2lin_fixed(int32_t x); /* Input is Q8.24, output is Q12.20 */ #endif /* __SOF_MATH_DECIBELS_H__ */ diff --git a/src/include/sof/math/exp_fcn.h b/src/include/sof/math/exp_fcn.h index 5b3649040836..0a3bc5a0e6f1 100644 --- a/src/include/sof/math/exp_fcn.h +++ b/src/include/sof/math/exp_fcn.h @@ -33,6 +33,6 @@ #define SOFM_LSHIFT_BITS 0x2000 int32_t sofm_exp_int32(int32_t x); -int32_t exp_fixed(int32_t x); +int32_t sofm_exp_fixed(int32_t x); #endif diff --git a/src/math/auditory/auditory.c b/src/math/auditory/auditory.c index 57c1fe0ee3f8..5a1a9d2b3aa4 100644 --- a/src/math/auditory/auditory.c +++ b/src/math/auditory/auditory.c @@ -80,7 +80,7 @@ int16_t psy_mel_to_hz(int16_t mel) return 0; exp_arg = Q_MULTSR_32X32((int64_t)mel, ONE_OVER_MELDIV_Q31, 2, 31, 27); - exp = exp_fixed(exp_arg) - ONE_Q20; + exp = sofm_exp_fixed(exp_arg) - ONE_Q20; hz = Q_MULTSR_32X32((int64_t)exp, 700, 20, 0, 0); return hz; } diff --git a/src/math/decibels.c b/src/math/decibels.c index b88e2cbf898e..7ee430154d76 100644 --- a/src/math/decibels.c +++ b/src/math/decibels.c @@ -32,5 +32,5 @@ int32_t db2lin_fixed(int32_t db) /* Q8.24 x Q5.27, result needs to be Q5.27 */ arg = (int32_t)Q_MULTSR_32X32((int64_t)db, LOG10_DIV20_Q27, 24, 27, 27); - return exp_fixed(arg); + return sofm_exp_fixed(arg); } diff --git a/src/math/exp_fcn.c b/src/math/exp_fcn.c index a81b5df59e00..6958f9356253 100644 --- a/src/math/exp_fcn.c +++ b/src/math/exp_fcn.c @@ -214,10 +214,11 @@ int32_t sofm_exp_int32(int32_t x) return ts; } -#define ONE_Q20 Q_CONVERT_FLOAT(1.0, 20) /* Use Q12.20 */ -#define TWO_Q27 Q_CONVERT_FLOAT(2.0, 27) /* Use Q5.27 */ -#define MINUS_TWO_Q27 Q_CONVERT_FLOAT(-2.0, 27) /* Use Q5.27 */ #define q_mult(a, b, qa, qb, qy) ((int32_t)Q_MULTSR_32X32((int64_t)(a), b, qa, qb, qy)) +#define EXP_ONE_Q20 Q_CONVERT_FLOAT(1.0, 20) /* Use Q12.20 */ +#define EXP_TWO_Q27 Q_CONVERT_FLOAT(2.0, 27) /* Use Q5.27 */ +#define EXP_MINUS_TWO_Q27 Q_CONVERT_FLOAT(-2.0, 27) /* Use Q5.27 */ + /* Fixed point exponent function for approximate range -11.5 .. 7.6 * that corresponds to decibels range -100 .. +66 dB. * @@ -231,7 +232,7 @@ int32_t sofm_exp_int32(int32_t x) * Output is Q12.20, 0.0 .. +2048.0 */ -int32_t exp_fixed(int32_t x) +int32_t sofm_exp_fixed(int32_t x) { int32_t xs; int32_t y; @@ -247,7 +248,7 @@ int32_t exp_fixed(int32_t x) /* x is Q5.27 */ xs = x; - while (xs >= TWO_Q27 || xs <= MINUS_TWO_Q27) { + while (xs >= EXP_TWO_Q27 || xs <= EXP_MINUS_TWO_Q27) { xs >>= 1; n++; } @@ -256,7 +257,7 @@ int32_t exp_fixed(int32_t x) * sofm_exp_int32() output is Q9.23, while y0 is Q12.20 */ y0 = Q_SHIFT_RND(sofm_exp_int32(Q_SHIFT_LEFT(xs, 27, 28)), 23, 20); - y = ONE_Q20; + y = EXP_ONE_Q20; for (i = 0; i < (1 << n); i++) y = (int32_t)Q_MULTSR_32X32((int64_t)y, y0, 20, 20, 20); diff --git a/src/math/exp_fcn_hifi.c b/src/math/exp_fcn_hifi.c index a14133f477a5..28a16319acb6 100644 --- a/src/math/exp_fcn_hifi.c +++ b/src/math/exp_fcn_hifi.c @@ -359,7 +359,7 @@ static inline int exp_hifi_q_shift_left(int a, int b, int c) * Output is Q12.20, 0.0 .. +2048.0 */ -int32_t exp_fixed(int32_t x) +int32_t sofm_exp_fixed(int32_t x) { int32_t xs; int32_t y; diff --git a/src/math/window.c b/src/math/window.c index 4795112ffc0f..ea3b4e8869fe 100644 --- a/src/math/window.c +++ b/src/math/window.c @@ -114,7 +114,7 @@ void win_povey_16b(int16_t win[], int length) /* Calculate x^0.85 as exp(0.85 * log(x)) */ x2 = (int32_t)(ln_int32((uint32_t)x1) >> 1) - WIN_LOG_2POW31_Q26; x3 = sat_int32(Q_MULTSR_32X32((int64_t)x2, WIN_085_Q31, 26, 31, 27)); /* Q5.27 */ - x4 = exp_fixed(x3); /* Q5.27 -> Q12.20 */ + x4 = sofm_exp_fixed(x3); /* Q5.27 -> Q12.20 */ /* Convert to Q1.15 */ win[n] = sat_int16(Q_SHIFT_RND(x4, 20, 15));