summaryrefslogtreecommitdiffstats
path: root/src/synth_math.h
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-04-29 14:34:36 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-04-29 14:34:36 +0300
commit402f6791150d503fc29ed75a7b8be9abfdd3867f (patch)
tree1061ae5cd2f9e1728b59a1ae6fbe0dfe8582c849 /src/synth_math.h
parente919ad41b01595d2cd8fb0771bd3542817ec1058 (diff)
downloadsynth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.tar.gz
synth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.tar.bz2
synth-project-402f6791150d503fc29ed75a7b8be9abfdd3867f.zip
midi cc
Diffstat (limited to 'src/synth_math.h')
-rw-r--r--src/synth_math.h36
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 */