summaryrefslogtreecommitdiffstats
path: root/src/osc_tri.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2023-07-30 20:51:05 +0300
committergramanas <anastasis.gramm2@gmail.com>2023-07-30 20:51:05 +0300
commit42479d2ed8fcbad5fb3ffb52553dad05a329590f (patch)
treeab0c0f9c1cec48b3b2b465cf8031fd68b53d4fc5 /src/osc_tri.c
parent3466a5ee2a4e03dae73f6c441d6f1daa5718952d (diff)
downloadsynth-project-42479d2ed8fcbad5fb3ffb52553dad05a329590f.tar.gz
synth-project-42479d2ed8fcbad5fb3ffb52553dad05a329590f.tar.bz2
synth-project-42479d2ed8fcbad5fb3ffb52553dad05a329590f.zip
oop
Diffstat (limited to 'src/osc_tri.c')
-rw-r--r--src/osc_tri.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/osc_tri.c b/src/osc_tri.c
index c4a56f5..8d2ef82 100644
--- a/src/osc_tri.c
+++ b/src/osc_tri.c
@@ -28,3 +28,46 @@ osc_tri_next(float f, float offset)
{
return osc_next_offset(&OSC_tri, f, offset);
}
+
+
+static float
+tri_sample(osc_t * osc, float offset)
+{
+ return osc_interpolate(offset,
+ tri((int)offset),
+ tri(osc_next_index(osc, offset)));
+}
+
+static float
+tri_next(osc_t * osc, float f, float offset)
+{
+ return osc_next_offset(osc, f, offset);
+}
+
+static const struct osc_ops osc_operations = {
+ .sample = tri_sample,
+ .next = tri_next,
+};
+
+osc_t *
+make_tri(const char * name)
+{
+ osc_t * osc = (osc_t *)malloc(sizeof(osc_t));
+
+ int len = strlen(name);
+ strncpy(osc->name, name, 16);
+ osc->data = NULL;
+ osc->len = 2;
+ osc->start = 0;
+ osc->end = 2;
+ osc->type = WAVE;
+ osc->ops = &osc_operations;
+
+ return osc;
+}
+
+void
+free_tri(osc_t * osc)
+{
+ free(osc);
+}