Skip to content

Commit e1c8418

Browse files
DRC: math: Rename variables and functions in accordance SOF math regulations.
Rename variables and functions in the code to reflect sof math and hi-fi usage. Signed-off-by: shastry <malladi.sastry@intel.com>
1 parent d8944c1 commit e1c8418

File tree

14 files changed

+34
-34
lines changed

14 files changed

+34
-34
lines changed

src/audio/drc/drc_generic.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,11 @@ 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
70+
((int64_t)drc_log_fixed
71+
(Q_SHIFT_RND(x, 31, 26)),
72+
(p->slope - ONE_Q30),
73+
26, 30, 27)); /* Q12.20 */
7174
y = Q_MULTSR_32X32((int64_t)p->ratio_base, exp_knee, 30, 20, 30);
7275
}
7376

src/audio/drc/drc_hifi3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/audio/drc/drc_hifi4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int32_t knee_curveK(const struct sof_drc_params *p, int32_t x)
6464
* gamma = -k * x
6565
*/
6666
gamma = drc_mult_lshift(x, -p->K, LSHIFT_QX31_QY20_QZ27);
67-
knee_exp_gamma = exp_fixed(gamma);
67+
knee_exp_gamma = sofm_exp_fixed(gamma);
6868
knee_curve_k = drc_mult_lshift(p->knee_beta, knee_exp_gamma, LSHIFT_QX24_QY20_QZ24);
6969
knee_curve_k = AE_ADD32(knee_curve_k, p->knee_alpha);
7070
return knee_curve_k;
@@ -100,7 +100,7 @@ static int32_t volume_gain(const struct sof_drc_params *p, int32_t x)
100100
tmp = AE_SRAI32R(x, 5); /* Q1.31 -> Q5.26 */
101101
tmp = drc_log_fixed(tmp); /* Q6.26 */
102102
tmp2 = AE_SUB32(p->slope, ONE_Q30); /* Q2.30 */
103-
exp_knee = exp_fixed(drc_mult_lshift(tmp, tmp2, LSHIFT_QX26_QY30_QZ27));
103+
exp_knee = sofm_exp_fixed(drc_mult_lshift(tmp, tmp2, LSHIFT_QX26_QY30_QZ27));
104104
y = drc_mult_lshift(p->ratio_base, exp_knee, LSHIFT_QX30_QY20_QZ30);
105105
}
106106

src/audio/drc/drc_math_generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ inline int32_t drc_pow_fixed(int32_t x, int32_t y)
234234
return 0;
235235

236236
/* x^y = expf(y * log(x)) */
237-
return exp_fixed(q_mult(y, drc_log_fixed(x), 30, 26, 27));
237+
return sofm_exp_fixed(q_mult(y, drc_log_fixed(x), 30, 26, 27));
238238
}
239239

240240
#undef q_multq

src/include/sof/math/decibels.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define DB2LIN_FIXED_INPUT_QY 24
1717
#define DB2LIN_FIXED_OUTPUT_QY 20
1818

19-
int32_t exp_fixed(int32_t x); /* Input is Q5.27, output is Q12.20 */
19+
int32_t sofm_exp_fixed(int32_t x); /* Input is Q5.27, output is Q12.20 */
2020
int32_t db2lin_fixed(int32_t x); /* Input is Q8.24, output is Q12.20 */
2121

2222
#endif /* __SOF_MATH_DECIBELS_H__ */

src/include/sof/math/exp_fcn.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@
3131
#define SOFM_QUOTIENT_SCALE 0x40000000
3232
#define SOFM_TERMS_Q23P9 0x800000
3333
#define SOFM_LSHIFT_BITS 0x2000
34+
#define EXP_ONE_Q20 Q_CONVERT_FLOAT(1.0, 20) /* Use Q12.20 */
35+
#define EXP_TWO_Q27 Q_CONVERT_FLOAT(2.0, 27) /* Use Q5.27 */
36+
#define EXP_MINUS_TWO_Q27 Q_CONVERT_FLOAT(-2.0, 27) /* Use Q5.27 */
3437

3538
int32_t sofm_exp_int32(int32_t x);
36-
int32_t exp_fixed(int32_t x);
39+
int32_t sofm_exp_fixed(int32_t x);
3740

3841
#endif

src/math/auditory/auditory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int16_t psy_mel_to_hz(int16_t mel)
8080
return 0;
8181

8282
exp_arg = Q_MULTSR_32X32((int64_t)mel, ONE_OVER_MELDIV_Q31, 2, 31, 27);
83-
exp = exp_fixed(exp_arg) - ONE_Q20;
83+
exp = sofm_exp_fixed(exp_arg) - ONE_Q20;
8484
hz = Q_MULTSR_32X32((int64_t)exp, 700, 20, 0, 0);
8585
return hz;
8686
}

src/math/decibels.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ int32_t db2lin_fixed(int32_t db)
3232

3333
/* Q8.24 x Q5.27, result needs to be Q5.27 */
3434
arg = (int32_t)Q_MULTSR_32X32((int64_t)db, LOG10_DIV20_Q27, 24, 27, 27);
35-
return exp_fixed(arg);
35+
return sofm_exp_fixed(arg);
3636
}

src/math/exp_fcn.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,8 @@ int32_t sofm_exp_int32(int32_t x)
214214
return ts;
215215
}
216216

217-
#define ONE_Q20 Q_CONVERT_FLOAT(1.0, 20) /* Use Q12.20 */
218-
#define TWO_Q27 Q_CONVERT_FLOAT(2.0, 27) /* Use Q5.27 */
219-
#define MINUS_TWO_Q27 Q_CONVERT_FLOAT(-2.0, 27) /* Use Q5.27 */
220217
#define q_mult(a, b, qa, qb, qy) ((int32_t)Q_MULTSR_32X32((int64_t)(a), b, qa, qb, qy))
218+
221219
/* Fixed point exponent function for approximate range -11.5 .. 7.6
222220
* that corresponds to decibels range -100 .. +66 dB.
223221
*
@@ -231,7 +229,7 @@ int32_t sofm_exp_int32(int32_t x)
231229
* Output is Q12.20, 0.0 .. +2048.0
232230
*/
233231

234-
int32_t exp_fixed(int32_t x)
232+
int32_t sofm_exp_fixed(int32_t x)
235233
{
236234
int32_t xs;
237235
int32_t y;
@@ -247,7 +245,7 @@ int32_t exp_fixed(int32_t x)
247245

248246
/* x is Q5.27 */
249247
xs = x;
250-
while (xs >= TWO_Q27 || xs <= MINUS_TWO_Q27) {
248+
while (xs >= EXP_TWO_Q27 || xs <= EXP_MINUS_TWO_Q27) {
251249
xs >>= 1;
252250
n++;
253251
}
@@ -256,7 +254,7 @@ int32_t exp_fixed(int32_t x)
256254
* sofm_exp_int32() output is Q9.23, while y0 is Q12.20
257255
*/
258256
y0 = Q_SHIFT_RND(sofm_exp_int32(Q_SHIFT_LEFT(xs, 27, 28)), 23, 20);
259-
y = ONE_Q20;
257+
y = EXP_ONE_Q20;
260258
for (i = 0; i < (1 << n); i++)
261259
y = (int32_t)Q_MULTSR_32X32((int64_t)y, y0, 20, 20, 20);
262260

src/math/exp_fcn_hifi.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,6 @@ static inline int exp_hifi_q_shift_left(int a, int b, int c)
342342
return xt_o;
343343
}
344344

345-
#define ONE_Q20 exp_hifi_q_convert_float(1.0, 20) /* Use Q12.20 */
346-
#define TWO_Q27 exp_hifi_q_convert_float(2.0, 27) /* Use Q5.27 */
347-
#define MINUS_TWO_Q27 exp_hifi_q_convert_float(-2.0, 27) /* Use Q5.27 */
348345
#define q_mult(a, b, qa, qb, qy) ((int32_t)exp_hifi_q_multsr_32x32((int64_t)(a), b, qa, qb, qy))
349346
/* Fixed point exponent function for approximate range -11.5 .. 7.6
350347
* that corresponds to decibels range -100 .. +66 dB.
@@ -359,7 +356,7 @@ static inline int exp_hifi_q_shift_left(int a, int b, int c)
359356
* Output is Q12.20, 0.0 .. +2048.0
360357
*/
361358

362-
int32_t exp_fixed(int32_t x)
359+
int32_t sofm_exp_fixed(int32_t x)
363360
{
364361
int32_t xs;
365362
int32_t y;
@@ -375,19 +372,19 @@ int32_t exp_fixed(int32_t x)
375372

376373
/* x is Q5.27 */
377374
xs = x;
378-
while (xs >= TWO_Q27 || xs <= MINUS_TWO_Q27) {
375+
while (xs >= EXP_TWO_Q27 || xs <= EXP_MINUS_TWO_Q27) {
379376
xs >>= 1;
380377
n++;
381378
}
382379

383380
/* sofm_exp_int32() input is Q4.28, while x1 is Q5.27
384381
* sofm_exp_int32() output is Q9.23, while y0 is Q12.20
385382
*/
386-
y0 = exp_hifi_q_shift_rnd(
387-
sofm_exp_int32(
388-
exp_hifi_q_shift_left(xs, 27, 28)),
389-
23, 20);
390-
y = ONE_Q20;
383+
y0 = exp_hifi_q_shift_rnd(sofm_exp_int32
384+
(exp_hifi_q_shift_left(xs, 27, 28)
385+
), 23, 20
386+
);
387+
y = EXP_ONE_Q20;
391388
for (i = 0; i < (1 << n); i++)
392389
y = (int32_t)exp_hifi_q_multsr_32x32((int64_t)y, y0, 20, 20, 20);
393390

0 commit comments

Comments
 (0)