Skip to content

Commit 3ed4ddd

Browse files
ShriramShastrylgirdwood
authored andcommitted
Audio: DRC: Use fast exponent functions
The exp_fixed() function is replaced by fast sofm_exp_fixed() and sofm_db2lin() functions. It saves 40 MCPS, from 123 to 83 MCPS in a test run in TGL platform. Signed-off-by: shastry <malladi.sastry@intel.com>
1 parent 8852db8 commit 3ed4ddd

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/audio/drc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ config COMP_DRC
44
bool "Dynamic Range Compressor component"
55
select CORDIC_FIXED
66
select NUMBERS_NORM
7-
select MATH_DECIBELS
7+
select MATH_EXP
88
select COMP_BLOB
99
default n
1010
help

src/audio/drc/drc_generic.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <sof/audio/component.h>
88
#include <sof/audio/format.h>
9-
#include <sof/math/decibels.h>
9+
#include <sof/math/exp_fcn.h>
1010
#include <sof/math/numbers.h>
1111
#include <stdint.h>
1212

@@ -36,7 +36,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x)
3636
* beta = -expf(k * linear_threshold) / k
3737
* gamma = -k * x
3838
*/
39-
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 */
4040
return p->knee_alpha + Q_MULTSR_32X32((int64_t)p->knee_beta, knee_exp_gamma, 24, 20, 24);
4141
}
4242

@@ -66,8 +66,10 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x)
6666
* => y/x = ratio_base * x^(s - 1)
6767
* => y/x = ratio_base * e^(log(x) * (s - 1))
6868
*/
69-
exp_knee = exp_fixed(Q_MULTSR_32X32((int64_t)drc_log_fixed(Q_SHIFT_RND(x, 31, 26)),
70-
(p->slope - ONE_Q30), 26, 30, 27)); /* Q12.20 */
69+
exp_knee = sofm_exp_fixed(Q_MULTSR_32X32((int64_t)
70+
drc_log_fixed(Q_SHIFT_RND(x, 31, 26)),
71+
(p->slope - ONE_Q30),
72+
26, 30, 27)); /* Q12.20 */
7173
y = Q_MULTSR_32X32((int64_t)p->ratio_base, exp_knee, 30, 20, 30);
7274
}
7375

@@ -149,7 +151,7 @@ void drc_update_detector_average(struct drc_state *state,
149151
p->sat_release_frames_inv_neg,
150152
21, 30, 24); /* Q8.24 */
151153
sat_release_rate =
152-
db2lin_fixed(db_per_frame) - ONE_Q20; /* Q12.20 */
154+
sofm_db2lin_fixed(db_per_frame) - ONE_Q20; /* Q12.20 */
153155
detector_average += Q_MULTSR_32X32((int64_t)gain_diff,
154156
sat_release_rate, 30, 20, 30);
155157
}
@@ -226,7 +228,7 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p
226228
/* db_per_frame = kSpacingDb / release_frames */
227229
db_per_frame = drc_inv_fixed(release_frames, 12, 30); /* Q2.30 */
228230
db_per_frame = Q_MULTSR_32X32((int64_t)db_per_frame, p->kSpacingDb, 30, 0, 24);
229-
envelope_rate = db2lin_fixed(db_per_frame); /* Q12.20 */
231+
envelope_rate = sofm_db2lin_fixed(db_per_frame); /* Q12.20 */
230232
} else {
231233
int32_t sat32;
232234
/* Attack mode - compression_diff_db should be positive dB */

src/audio/drc/drc_hifi3.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <sof/audio/component.h>
88
#include <sof/audio/format.h>
9-
#include <sof/math/decibels.h>
9+
#include <sof/math/exp_fcn.h>
1010
#include <sof/math/numbers.h>
1111
#include <stdint.h>
1212

@@ -42,7 +42,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x)
4242
* gamma = -k * x
4343
*/
4444
gamma = drc_mult_lshift(x, -p->K, drc_get_lshift(31, 20, 27));
45-
knee_exp_gamma = exp_fixed(gamma);
45+
knee_exp_gamma = sofm_exp_fixed(gamma);
4646
knee_curve_k = drc_mult_lshift(p->knee_beta, knee_exp_gamma, drc_get_lshift(24, 20, 24));
4747
knee_curve_k = AE_ADD32(knee_curve_k, p->knee_alpha);
4848
return knee_curve_k;
@@ -78,7 +78,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x)
7878
tmp = AE_SRAI32R(x, 5); /* Q1.31 -> Q5.26 */
7979
tmp = drc_log_fixed(tmp); /* Q6.26 */
8080
tmp2 = AE_SUB32(p->slope, ONE_Q30); /* Q2.30 */
81-
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)));
8282
y = drc_mult_lshift(p->ratio_base, exp_knee, drc_get_lshift(30, 20, 30));
8383
}
8484

@@ -159,7 +159,8 @@ void drc_update_detector_average(struct drc_state *state,
159159
db_per_frame = drc_mult_lshift(drc_lin2db_fixed(gain),
160160
p->sat_release_frames_inv_neg,
161161
drc_get_lshift(21, 30, 24));
162-
sat_release_rate = AE_SUB32(db2lin_fixed(db_per_frame), ONE_Q20);
162+
sat_release_rate = AE_SUB32(sofm_db2lin_fixed(db_per_frame),
163+
ONE_Q20);
163164
tmp = drc_mult_lshift(gain_diff, sat_release_rate,
164165
drc_get_lshift(30, 20, 30));
165166
}
@@ -254,7 +255,7 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p
254255
tmp = p->kSpacingDb << 16; /* Q16.16 */
255256
lshift = drc_get_lshift(30, 16, 24);
256257
db_per_frame = drc_mult_lshift(db_per_frame, tmp, lshift); /* Q8.24 */
257-
envelope_rate = db2lin_fixed(db_per_frame); /* Q12.20 */
258+
envelope_rate = sofm_db2lin_fixed(db_per_frame); /* Q12.20 */
258259
} else {
259260
/* Attack mode - compression_diff_db should be positive dB */
260261

src/audio/drc/drc_hifi4.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <sof/audio/component.h>
88
#include <sof/audio/format.h>
9-
#include <sof/math/decibels.h>
9+
#include <sof/math/exp_fcn.h>
1010
#include <sof/math/numbers.h>
1111
#include <stdint.h>
1212

@@ -65,7 +65,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x)
6565
* gamma = -k * x
6666
*/
6767
gamma = drc_mult_lshift(x, -p->K, LSHIFT_QX31_QY20_QZ27);
68-
knee_exp_gamma = exp_fixed(gamma);
68+
knee_exp_gamma = sofm_exp_fixed(gamma);
6969
knee_curve_k = drc_mult_lshift(p->knee_beta, knee_exp_gamma, LSHIFT_QX24_QY20_QZ24);
7070
knee_curve_k = AE_ADD32(knee_curve_k, p->knee_alpha);
7171
return knee_curve_k;
@@ -101,7 +101,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x)
101101
tmp = AE_SRAI32R(x, 5); /* Q1.31 -> Q5.26 */
102102
tmp = drc_log_fixed(tmp); /* Q6.26 */
103103
tmp2 = AE_SUB32(p->slope, ONE_Q30); /* Q2.30 */
104-
exp_knee = exp_fixed(drc_mult_lshift(tmp, tmp2, LSHIFT_QX26_QY30_QZ27));
104+
exp_knee = sofm_exp_fixed(drc_mult_lshift(tmp, tmp2, LSHIFT_QX26_QY30_QZ27));
105105
y = drc_mult_lshift(p->ratio_base, exp_knee, LSHIFT_QX30_QY20_QZ30);
106106
}
107107

@@ -185,7 +185,8 @@ void drc_update_detector_average(struct drc_state *state,
185185
db_per_frame = drc_mult_lshift(drc_lin2db_fixed(gain),
186186
p->sat_release_frames_inv_neg,
187187
LSHIFT_QX21_QY30_QZ24);
188-
sat_release_rate = AE_SUB32(db2lin_fixed(db_per_frame), ONE_Q20);
188+
sat_release_rate = AE_SUB32(sofm_db2lin_fixed(db_per_frame),
189+
ONE_Q20);
189190
tmp = drc_mult_lshift(gain_diff, sat_release_rate,
190191
LSHIFT_QX30_QY20_QZ30);
191192
}
@@ -278,7 +279,7 @@ void drc_update_envelope(struct drc_state *state, const struct sof_drc_params *p
278279
tmp = p->kSpacingDb << 16; /* Q16.16 */
279280
/* Q8.24 */
280281
db_per_frame = drc_mult_lshift(db_per_frame, tmp, LSHIFT_QX30_QY16_QZ24);
281-
envelope_rate = db2lin_fixed(db_per_frame); /* Q12.20 */
282+
envelope_rate = sofm_db2lin_fixed(db_per_frame); /* Q12.20 */
282283
} else {
283284
/* Attack mode - compression_diff_db should be positive dB */
284285

src/audio/drc/drc_math_generic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <sof/audio/format.h>
88
#include <sof/math/decibels.h>
9+
#include <sof/math/exp_fcn.h>
910
#include <sof/math/numbers.h>
1011
#include <sof/math/trig.h>
1112

@@ -234,7 +235,7 @@ inline int32_t drc_pow_fixed(int32_t x, int32_t y)
234235
return 0;
235236

236237
/* x^y = expf(y * log(x)) */
237-
return exp_fixed(q_mult(y, drc_log_fixed(x), 30, 26, 27));
238+
return sofm_exp_fixed(q_mult(y, drc_log_fixed(x), 30, 26, 27));
238239
}
239240

240241
#undef q_multq

0 commit comments

Comments
 (0)