Skip to content

Commit 292e99f

Browse files
DRC: math: Replace exponential function for performance
For DRC performance, replace "exp_small_fixed()" with "sofm_exp_int32()". Included supporting change to include "sofm_exp_int32()" within exp_fixed() ,HiFi intrinsic function was added to replace C macros,and removed "exp_small_fixed()" from future use. Signed-off-by: shastry <malladi.sastry@intel.com>
1 parent 4d4421a commit 292e99f

19 files changed

Lines changed: 236 additions & 111 deletions

File tree

src/audio/Kconfig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ rsource "selector/Kconfig"
120120

121121
rsource "crossover/Kconfig"
122122

123-
rsource "drc/Kconfig"
123+
config COMP_DRC
124+
bool "Dynamic Range Compressor component"
125+
select CORDIC_FIXED
126+
select NUMBERS_NORM
127+
select COMP_BLOB
128+
select MATH_EXP
129+
default n
130+
help
131+
Select for Dynamic Range Compressor (DRC) component. A DRC can be used
132+
to reduce the volume of loud sounds and amplify silent sounds thus
133+
compressing an audio signal's dynamic range.
124134

125135
rsource "multiband_drc/Kconfig"
126136

src/audio/drc/drc_generic.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sof/audio/drc/drc_math.h>
1111
#include <sof/audio/format.h>
1212
#include <sof/math/decibels.h>
13+
#include <sof/math/exp_fcn.h>
1314
#include <sof/math/numbers.h>
1415
#include <stdint.h>
1516

@@ -35,7 +36,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x)
3536
* beta = -expf(k * linear_threshold) / k
3637
* gamma = -k * x
3738
*/
38-
knee_exp_gamma = exp_fixed(Q_MULTSR_32X32((int64_t)x, -p->K, 31, 20, 27)); /* Q12.20 */
39+
knee_exp_gamma = sofm_exp_fixed(Q_MULTSR_32X32((int64_t)x, -p->K, 31, 20, 27)); /* Q12.20 */
3940
return p->knee_alpha + Q_MULTSR_32X32((int64_t)p->knee_beta, knee_exp_gamma, 24, 20, 24);
4041
}
4142

@@ -65,8 +66,10 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x)
6566
* => y/x = ratio_base * x^(s - 1)
6667
* => y/x = ratio_base * e^(log(x) * (s - 1))
6768
*/
68-
exp_knee = exp_fixed(Q_MULTSR_32X32((int64_t)drc_log_fixed(Q_SHIFT_RND(x, 31, 26)),
69-
(p->slope - ONE_Q30), 26, 30, 27)); /* Q12.20 */
69+
exp_knee = sofm_exp_fixed(
70+
Q_MULTSR_32X32((int64_t)
71+
drc_log_fixed(Q_SHIFT_RND(x, 31, 26)),
72+
(p->slope - ONE_Q30), 26, 30, 27)); /* Q12.20 */
7073
y = Q_MULTSR_32X32((int64_t)p->ratio_base, exp_knee, 30, 20, 30);
7174
}
7275

src/audio/drc/drc_hifi3.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sof/audio/drc/drc_math.h>
1111
#include <sof/audio/format.h>
1212
#include <sof/math/decibels.h>
13+
#include <sof/math/exp_fcn.h>
1314
#include <sof/math/numbers.h>
1415
#include <stdint.h>
1516

@@ -41,7 +42,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x)
4142
* gamma = -k * x
4243
*/
4344
gamma = drc_mult_lshift(x, -p->K, drc_get_lshift(31, 20, 27));
44-
knee_exp_gamma = exp_fixed(gamma);
45+
knee_exp_gamma = sofm_exp_fixed(gamma);
4546
knee_curve_k = drc_mult_lshift(p->knee_beta, knee_exp_gamma, drc_get_lshift(24, 20, 24));
4647
knee_curve_k = AE_ADD32(knee_curve_k, p->knee_alpha);
4748
return knee_curve_k;
@@ -77,7 +78,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x)
7778
tmp = AE_SRAI32R(x, 5); /* Q1.31 -> Q5.26 */
7879
tmp = drc_log_fixed(tmp); /* Q6.26 */
7980
tmp2 = AE_SUB32(p->slope, ONE_Q30); /* Q2.30 */
80-
exp_knee = exp_fixed(drc_mult_lshift(tmp, tmp2, drc_get_lshift(26, 30, 27)));
81+
exp_knee = sofm_exp_fixed(drc_mult_lshift(tmp, tmp2, drc_get_lshift(26, 30, 27)));
8182
y = drc_mult_lshift(p->ratio_base, exp_knee, drc_get_lshift(30, 20, 30));
8283
}
8384

src/audio/drc/drc_math_generic.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sof/audio/drc/drc_math.h>
88
#include <sof/audio/format.h>
99
#include <sof/math/decibels.h>
10+
#include <sof/math/exp_fcn.h>
1011
#include <sof/math/numbers.h>
1112
#include <sof/math/trig.h>
1213

@@ -219,8 +220,6 @@ inline int32_t drc_inv_fixed(int32_t x, int32_t precision_x, int32_t precision_y
219220
#undef qc
220221
}
221222

222-
#endif /* DRC_GENERIC */
223-
224223
/*
225224
* Input x is Q6.26; valid range: (0.0, 32.0); x <= 0 is not supported
226225
* y is Q2.30: (-2.0, 2.0)
@@ -233,8 +232,8 @@ inline int32_t drc_pow_fixed(int32_t x, int32_t y)
233232
return 0;
234233

235234
/* x^y = expf(y * log(x)) */
236-
return exp_fixed(q_mult(y, drc_log_fixed(x), 30, 26, 27));
235+
return sofm_exp_fixed(q_mult(y, drc_log_fixed(x), 30, 26, 27));
237236
}
238-
237+
#endif
239238
#undef q_multq
240239
#undef q_mult

src/audio/mfcc/mfcc_setup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <sof/audio/component.h>
99
#include <sof/audio/audio_stream.h>
1010
#include <sof/math/auditory.h>
11+
#include <sof/math/decibels.h>
12+
#include <sof/math/exp_fcn.h>
1113
#include <sof/math/trig.h>
1214
#include <sof/math/window.h>
1315
#include <sof/trace/trace.h>

src/audio/multiband_drc/multiband_drc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static int multiband_drc_init(struct processing_module *mod)
258258
*/
259259
cd->process_enabled = true;
260260
#else
261-
cd->process_enabled = false;
261+
cd->process_enabled = true;
262262
#endif
263263

264264
/* Handler for configuration data */

src/include/sof/math/decibels.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
#include <stdint.h>
1313

14-
#define EXP_FIXED_INPUT_QY 27
15-
#define EXP_FIXED_OUTPUT_QY 20
16-
#define DB2LIN_FIXED_INPUT_QY 24
17-
#define DB2LIN_FIXED_OUTPUT_QY 20
18-
19-
int32_t exp_fixed(int32_t x); /* Input is Q5.27, output is Q12.20 */
2014
int32_t db2lin_fixed(int32_t x); /* Input is Q8.24, output is Q12.20 */
2115

2216
#endif /* __SOF_MATH_DECIBELS_H__ */

src/include/sof/math/exp_fcn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626

2727
#endif
2828

29-
int32_t sofm_exp_int32(int32_t x);
30-
29+
int32_t sofm_exp_int32(int32_t x); /* Input is Q4.28, Output is Q9.23 */
30+
int32_t sofm_exp_fixed(int32_t x); /* Input is Q5.27, output is Q12.20 */
3131
#endif

src/math/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ config MATH_EXP
4747
an input range of -5 to +5 gives positive numbers between 0.00673794699908547 and
4848
148.413159102577. The precision of this function is 1e-4.
4949

50+
config MATH_EXP_SMALL_FXD
51+
bool "Small Exponential functions"
52+
default n
53+
help
54+
By selecting this, the 32-bit exp_small_fixed() function can be used to calculate
55+
exponential values. With a mean thdn of -131.205(dBc), an exponential function with
56+
an input range of -2 to +2 gives positive numbers between 0.135335255 and
57+
7.38905609. The precision of this function is 1e-6.
58+
5059
config NATURAL_LOGARITHM_FIXED
5160
bool "Natural Logarithm function"
5261
default n

src/math/auditory/auditory.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <rtos/alloc.h>
99
#include <sof/math/auditory.h>
1010
#include <sof/math/decibels.h>
11+
#include <sof/math/exp_fcn.h>
1112
#include <sof/math/fft.h>
1213
#include <sof/math/log.h>
1314
#include <sof/math/numbers.h>
@@ -80,7 +81,7 @@ int16_t psy_mel_to_hz(int16_t mel)
8081
return 0;
8182

8283
exp_arg = Q_MULTSR_32X32((int64_t)mel, ONE_OVER_MELDIV_Q31, 2, 31, 27);
83-
exp = exp_fixed(exp_arg) - ONE_Q20;
84+
exp = sofm_exp_fixed(exp_arg) - ONE_Q20;
8485
hz = Q_MULTSR_32X32((int64_t)exp, 700, 20, 0, 0);
8586
return hz;
8687
}

0 commit comments

Comments
 (0)