shithub: soundpipe

Download patch

ref: 7de74a9d01cbb87b74def34099ce2f30a0fb6e6e
parent: f2e11903bc2d80a73e21916e2929a18b6042c5f6
author: Paul Batchelor <thisispaulbatchelor@gmail.com>
date: Fri Oct 30 05:01:45 EDT 2020

added gen_triangle

--- a/h/ftbl.h
+++ b/h/ftbl.h
@@ -14,3 +14,4 @@
 int sp_ftbl_loadspa(sp_data *sp, sp_ftbl **ft, const char *filename);
 int sp_gen_vals(sp_data *sp, sp_ftbl *ft, const char *string);
 int sp_gen_sine(sp_data *sp, sp_ftbl *ft);
+void sp_gen_triangle(sp_data *sp, sp_ftbl *ft);
--- a/modules/ftbl.c
+++ b/modules/ftbl.c
@@ -104,3 +104,26 @@
     }
     return SP_OK;
 }
+
+void sp_gen_triangle(sp_data *sp, sp_ftbl *ft)
+{
+    unsigned int i;
+    unsigned int counter;
+    SPFLOAT incr;
+    int step;
+
+    incr = 1.0f / (SPFLOAT)ft->size;
+    incr *= 2;
+
+    step = 1;
+
+    counter = 0;
+
+    for (i = 0; i < ft->size; i++) {
+        if (i == ft->size / 2) {
+            step = -1;
+        }
+        ft->tbl[i] = (2.f*(counter * incr) - 1.f);
+        counter += step;
+    }
+}