bitpwm
Creates a pulse wavetable with configurable width. Designed
to be fed into an instance of bitosc
as a wavetable
parameter.
The bitpwm
itself takes in two paramters: position and
wavetable size. Presumably, the size is the same size as
the wavetable size in bitosc
.
<<bitpwm.c>>=
#include <math.h>
#include "graforge.h"
static int tick = 1;
static void compute(gf_node *node)
{
int blksize;
gf_cable *c[3];
int n;
blksize = gf_node_blksize(node);
for (n = 0; n < 3; n++) {
gf_node_get_cable(node, n, &c[n]);
}
for (n = 0; n < blksize; n++) {
int sz;
GFFLT pos;
int ipos;
unsigned long out;
pos = gf_cable_get(c[0], n);
sz = floor(gf_cable_get(c[1], n));
ipos = floor(pos * sz);
if (ipos == sz) ipos--;
out = (1 << ipos) - 1;
if (tick) {
printf("out: %ld\n", out);
tick = 0;
}
gf_cable_set(c[2], n, (GFFLT)out);
}
}
int node_bitpwm(gf_node *node)
{
gf_node_cables_alloc(node, 3);
gf_node_set_block(node, 2);
gf_node_set_compute(node, compute);
return GF_OK;
}
prev | home | next