ref: 8c93ccfb85d09bba58f8997930a110e6be2bbcd4
parent: 7de74a9d01cbb87b74def34099ce2f30a0fb6e6e
author: Paul Batchelor <[email protected]>
date: Fri Oct 30 05:05:16 EDT 2020
added gen_composite
--- a/h/ftbl.h
+++ b/h/ftbl.h
@@ -15,3 +15,4 @@
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);
+void sp_gen_composite(sp_data *sp, sp_ftbl *ft, const char *argstring);
--- a/modules/ftbl.c
+++ b/modules/ftbl.c
@@ -127,3 +127,29 @@
counter += step;
}
}
+
+void sp_gen_composite(sp_data *sp, sp_ftbl *ft, const char *argstring)
+{
+ SPFLOAT phs, inc, amp, dc, tpdlen;
+ int i, n;
+ sp_ftbl *args;
+
+ sp_ftbl_create(sp, &args, 1);
+ sp_gen_vals(sp, args, argstring);
+
+ tpdlen = 2 * M_PI / (SPFLOAT) ft->size;
+
+ for (n = 0; n < args->size; n += 4) {
+ inc = args->tbl[n] * tpdlen;
+ amp = args->tbl[n + 1];
+ phs = args->tbl[n + 2] * tpd360;
+ dc = args->tbl[n + 3];
+
+ for (i = 0; i <ft->size ; i++) {
+ ft->tbl[i] += (SPFLOAT) (sin(phs) * amp + dc);
+ if ((phs += inc) >= 2 * M_PI) phs -= 2 * M_PI;
+ }
+ }
+
+ sp_ftbl_destroy(&args);
+}