Skip to content

Commit

Permalink
DRC: math: swapout the exponential function and fixing compilation er…
Browse files Browse the repository at this point in the history
…rors.

For improved performance, this checkin substitutes
sofm_exp_int32() for exp_small_fixed(). Changes for
successful compilation are also included; MATH_EXP
was added to the Kconfig file, and an error occurred
when 'unsigned long' was passed as a parameter of an
incompatible type.

Signed-off-by: shastry <[email protected]>
  • Loading branch information
ShriramShastry committed Dec 5, 2023
1 parent cff6a6b commit 87a4019
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/audio/drc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ config COMP_DRC
select CORDIC_FIXED
select NUMBERS_NORM
select MATH_DECIBELS
select MATH_EXP
select COMP_BLOB
default n
help
Expand Down
6 changes: 6 additions & 0 deletions src/include/sof/math/exp_fcn.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@

#endif

#define SOFM_BIT_MASK_LOW_Q27P5 0x0000000008000000
#define SOFM_BIT_MASK_Q62P2 0x4000000000000000LL
#define SOFM_QUOTIENT_SCALE 0x40000000
#define SOFM_TERMS_Q23P9 0x800000
#define SOFM_LSHIFT_BITS 0x2000

int32_t sofm_exp_int32(int32_t x);

#endif
9 changes: 5 additions & 4 deletions src/math/decibels.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
//
// Author: Seppo Ingalsuo <[email protected]>

#include <sof/audio/format.h>
#include <sof/math/decibels.h>
#include <sof/math/exp_fcn.h>
#include <sof/audio/format.h>
#include <stdint.h>

#define ONE_Q20 Q_CONVERT_FLOAT(1.0, 20) /* Use Q12.20 */
Expand Down Expand Up @@ -105,10 +106,10 @@ int32_t exp_fixed(int32_t x)
n++;
}

/* exp_small_fixed() input is Q3.29, while x1 is Q5.27
* exp_small_fixed() output is Q9.23, while y0 is Q12.20
/* sofm_exp_int32() input is Q4.28, while x1 is Q5.27
* sofm_exp_int32() output is Q9.23, while y0 is Q12.20
*/
y0 = Q_SHIFT_RND(exp_small_fixed(Q_SHIFT_LEFT(xs, 27, 29)), 23, 20);
y0 = Q_SHIFT_RND(sofm_exp_int32(Q_SHIFT_LEFT(xs, 27, 28)), 23, 20);
y = ONE_Q20;
for (i = 0; i < (1 << n); i++)
y = (int32_t)Q_MULTSR_32X32((int64_t)y, y0, 20, 20, 20);
Expand Down
5 changes: 0 additions & 5 deletions src/math/exp_fcn.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@

#if defined(EXPONENTIAL_GENERIC)

#define SOFM_BIT_MASK_Q62P2 0x4000000000000000LL
#define SOFM_CONVERG_ERROR 28823037607936LL // error smaller than 1e-4,1/2 ^ -44.7122876200884
#define SOFM_BIT_MASK_LOW_Q27P5 0x8000000
#define SOFM_QUOTIENT_SCALE BIT(30)
#define SOFM_TERMS_Q23P9 8388608
#define SOFM_LSHIFT_BITS 8192

/* inv multiplication lookup table */
/* LUT = ceil(1/factorial(b_n) * 2 ^ 63) */
Expand Down
6 changes: 1 addition & 5 deletions src/math/exp_fcn_hifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
#endif

#define SOFM_CONVERG_ERROR 28823037624320LL /* error smaller than 1e-4,1/2 ^ -44.7122876209085 */
#define SOFM_BIT_MASK_LOW_Q27P5 0x0000000008000000
#define SOFM_BIT_MASK_Q62P2 0x4000000000000000LL
#define SOFM_QUOTIENT_SCALE BIT(30)
#define SOFM_TERMS_Q23P9 0x800000
#define SOFM_LSHIFT_BITS 0x2000

/*
* Arguments : int64_t in_0
* int64_t in_1
Expand Down

0 comments on commit 87a4019

Please sign in to comment.