bitosc

bitosc

A stateless 1-bit table-lookup oscillator.

The oscillator takes in 3 parameters as inputs:

position, a normalized value between 0-1. This is assumed to be a phasor signal.

table, a polypulse "wavetable" stored as an integer.

<<bitosc.c>>=
#include <math.h>
#include "graforge.h"
static int tick = 1;

static void compute(gf_node *node)
{
    int blksize;
    gf_cable *c[4];
    int n;

    blksize = gf_node_blksize(node);

    for (n = 0; n < 4; n++) {
        gf_node_get_cable(node, n, &c[n]);
    }

    for (n = 0; n < blksize; n++) {
        unsigned long wt;
        int sz;
        int pos;
        GFFLT out;

        sz = floor(gf_cable_get(c[2], n));
        wt = floor(gf_cable_get(c[1], n));
        pos = floor(gf_cable_get(c[0], n) * sz);

        if (pos >= sz) pos = sz - 1;


        out = (wt & (1 << pos)) >> pos;

        if (tick) {
            printf("sz: %d\n", sz);
            printf("wt: %ld\n", wt);
            printf("pos: %d\n", pos);
            tick = 0;
            printf("out: %g\n", out);
        }

        out = (out * 2) - 1;

        gf_cable_set(c[3], n, out);
    }
}

int node_bitosc(gf_node *node)
{
    gf_node_cables_alloc(node, 4);
    gf_node_set_block(node, 3);
    gf_node_set_compute(node, compute);
    return GF_OK;
}



prev | home | next