#ifndef SYNTH_MATH_H #define SYNTH_MATH_H #include static long long gcd(long long a, long long b) { long long rem; rem=a-(a/b*b); if(rem==0) return b; else gcd(b,rem); } // Function to return LCM of two numbers 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 */