On 4/30/18 11:04 AM, Seppo Ingalsuo wrote:
Signed-off-by: Seppo Ingalsuo seppo.ingalsuo@linux.intel.com
src/arch/xtensa/Makefile.am | 2 +- src/audio/src.c | 1 + src/audio/src.h | 3 -- src/include/sof/math/numbers.h | 18 +++++++++++ src/include/sof/ssp.h | 2 -- src/math/numbers.c | 68 ++++++++++++++++++++++++++++++++++++++++++
looks ok, I would add something to find the first non-zero bit (something you use quite a bit to scale factors)
6 files changed, 88 insertions(+), 6 deletions(-)
diff --git a/src/arch/xtensa/Makefile.am b/src/arch/xtensa/Makefile.am index 9f53e88..082b3c2 100644 --- a/src/arch/xtensa/Makefile.am +++ b/src/arch/xtensa/Makefile.am @@ -59,8 +59,8 @@ sof_LDADD = \ ../../platform/$(PLATFORM)/libplatform.a \ ../../ipc/libsof_ipc.a \ ../../audio/libaudio.a \
- ../../math/libsof_math.a \ ../../drivers/libdrivers.a \
- ../../math/libsof_math.a \ libreset.a \ xtos/libxtos.a \ xtos/libxlevel2.a \
diff --git a/src/audio/src.c b/src/audio/src.c index cded8b8..c19828a 100644 --- a/src/audio/src.c +++ b/src/audio/src.c @@ -42,6 +42,7 @@ #include <sof/clock.h> #include <sof/audio/component.h> #include <sof/audio/pipeline.h> +#include <sof/math/numbers.h> #include <uapi/ipc.h>
#include "src_config.h" diff --git a/src/audio/src.h b/src/audio/src.h index 3208693..5268a66 100644 --- a/src/audio/src.h +++ b/src/audio/src.h @@ -32,9 +32,6 @@ #ifndef SRC_H #define SRC_H
-#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b))
- struct src_param { int fir_s1; int fir_s2;
diff --git a/src/include/sof/math/numbers.h b/src/include/sof/math/numbers.h index 927d39c..cadbcf9 100644 --- a/src/include/sof/math/numbers.h +++ b/src/include/sof/math/numbers.h @@ -33,6 +33,24 @@ #ifndef NUMBERS_H #define NUMBERS_H
+#include <stdint.h>
+#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b))
- int gcd(int a, int b); /* Calculate greatest common divisor for a and b */
+/* Divide function that returns ceil() of quotient */ +int ceil_divide(int a, int b);
+/* Find indices of equal values in a vector of integer values */ +int find_equal(int idx[], int vec[], int n, int vec_length, int max_results);
+/* Return the smallest value found in a vector */ +int find_min(int vec[], int vec_length);
+/* Return the largest absolute value found in a vector */ +int32_t find_max_abs_int32(int32_t vec[], int vec_length);
- #endif /* NUMBERS_H */
diff --git a/src/include/sof/ssp.h b/src/include/sof/ssp.h index c66f67b..5a57d58 100644 --- a/src/include/sof/ssp.h +++ b/src/include/sof/ssp.h @@ -38,8 +38,6 @@ #include <sof/trace.h> #include <sof/wait.h>
-#define BIT(x) (1 << (x))
- #define SSP_CLK_AUDIO 0 #define SSP_CLK_NET_PLL 1 #define SSP_CLK_EXT 2
diff --git a/src/math/numbers.c b/src/math/numbers.c index d7a1717..f3ee08d 100644 --- a/src/math/numbers.c +++ b/src/math/numbers.c @@ -36,6 +36,7 @@ */
#include <sof/math/numbers.h> +#include <sof/audio/format.h>
int gcd(int a, int b) { @@ -47,3 +48,70 @@ int gcd(int a, int b) } return a; }
+/* This is a divide function that returns ceil of the quotient.
- E.g. ceil_divide(9, 3) returns 3, ceil_divide(10, 3) returns 4.
- */
+int ceil_divide(int a, int b) +{
- int c;
- c = a / b;
- if (c * b < a)
c++;
- return c;
+}
+/* This function searches from vec[] (of length vec_length) integer values
- of n. The indexes to equal values is returned in idx[]. The function
- returns the number of found matches. The max_results should be set to
- 0 (or negative) or vec_length get all the matches. The max_result can be set
- to 1 to receive only the first match in ascending order. It avoids need
- for an array for idx.
- */
+int find_equal(int idx[], int vec[], int n, int vec_length,
- int max_results)
+{
- int nresults = 0;
- int i;
- for (i = 0; i < vec_length; i++) {
if (vec[i] == n) {
idx[nresults++] = i;
if (nresults == max_results)
break;
}
- }
- return nresults;
+}
+/* Return the smallest value found in the vector */ +int find_min(int vec[], int vec_length) +{
- int i;
- int min = vec[0];
- for (i = 1; i < vec_length; i++)
min = (vec[i] < min) ? vec[i] : min;
- return min;
+}
+/* Return the largest absolute value found in the vector. Note that
- smallest negative value need to be saturated to preset as int32_t.
- */
+int32_t find_max_abs_int32(int32_t vec[], int vec_length) +{
- int i;
- int64_t amax = (vec[0] > 0) ? vec[0] : -vec[0];
- for (i = 1; i < vec_length; i++) {
amax = (vec[i] > amax) ? vec[i] : amax;
amax = (-vec[i] > amax) ? -vec[i] : amax;
- }
- return SATP_INT32(amax); /* Amax is always a positive value */
+}