diff options
Diffstat (limited to 'src/synth_math.h')
-rw-r--r-- | src/synth_math.h | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/synth_math.h b/src/synth_math.h index de6fb26..74dec4c 100644 --- a/src/synth_math.h +++ b/src/synth_math.h @@ -1,8 +1,10 @@ #ifndef SYNTH_MATH_H #define SYNTH_MATH_H -extern long long -gcd(long long int a, long long int b) +#include <stddef.h> + +static long long +gcd(long long a, long long b) { long long rem; rem=a-(a/b*b); @@ -13,10 +15,36 @@ gcd(long long int a, long long int b) } // Function to return LCM of two numbers -extern long long +static long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } - + +static float +clamp(float f) +{ + if (f <= -1) return -0.9999; + if (f >= 1) return 0.9999; + return f; +} + +/* 1d convolution */ +static void +convole(float *signal, float *filter, + size_t signal_size, size_t filter_size, float *out) { + for (size_t i = 0; i < filter_size + signal_size; i++) { + size_t kmin, kmax, k; + out[i] = 0; + /* find overlap */ + kmin = (i >= filter_size - 1) ? i - (filter_size - 1) : 0; + kmax = (i < signal_size - 1) ? i : signal_size - 1; + + /* Add the overlaping values */ + for (k = kmin; k <= kmax; k++) { + out[i] += signal[k] * filter[i - k]; + } + } +} + #endif /* SYNTH_MATH_H */ |