blob: 2dd9f83b16bb3b0114bab00d54ead5b0b775de00 (
plain) (
tree)
|
|
#ifndef SYNTH_MATH_H
#define SYNTH_MATH_H
#include <stddef.h>
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, int min, int max)
{
if (f <= min) return min + 0.0001;
if (f >= max) return max - 0.0001;
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 */
|