summaryrefslogtreecommitdiffstats
path: root/src/osc_saw.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-07-07 22:19:48 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-07-07 22:19:48 +0300
commit3466a5ee2a4e03dae73f6c441d6f1daa5718952d (patch)
treedb6f4d1056bda6042523805c3edcbdbd5abf1b97 /src/osc_saw.c
parentc8cd7f9298de876f2046fddd2e322a63c421a505 (diff)
downloadsynth-project-3466a5ee2a4e03dae73f6c441d6f1daa5718952d.tar.gz
synth-project-3466a5ee2a4e03dae73f6c441d6f1daa5718952d.tar.bz2
synth-project-3466a5ee2a4e03dae73f6c441d6f1daa5718952d.zip
moar
Diffstat (limited to 'src/osc_saw.c')
-rw-r--r--src/osc_saw.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/osc_saw.c b/src/osc_saw.c
new file mode 100644
index 0000000..fc31f6f
--- /dev/null
+++ b/src/osc_saw.c
@@ -0,0 +1,28 @@
+#include "osc.h"
+
+osc_t OSC_saw = MAKE_OSC("f_saw", 20000, WAVE);
+
+OSC_COMMON(saw)
+
+float
+sawX(float sm, int offset, int len)
+{
+ float dOutput = 0.0;
+ for (float n = 1.0; n < sm; n++)
+ dOutput += (sinf(n * 2.0 * M_PI * offset / len)) / n;
+ return 0.5 * dOutput;
+}
+
+float
+osc_saw(float offset)
+{
+ return osc_interpolate(offset,
+ sawX(25, (int)offset, OSC_saw.len),
+ sawX(25, osc_next_index(&OSC_saw, offset), OSC_saw.len));
+}
+
+float
+osc_saw_next(float f, float offset)
+{
+ return osc_next_offset(&OSC_saw, f, offset);
+}