Bitter

Bitter

A one bit bitcrusher. Takes in a floating input signal, truncates it to an on/off state, then sends it out at full scale.

<<bitter.c>>=
#include <math.h>
#include "graforge.h"
static void compute(gf_node *node)
{
    int n;
    int blksize;
    gf_cable *in;
    gf_cable *out;
    GFFLT tmp;

    blksize = gf_node_blksize(node);

    in = NULL;
    out = NULL;
    gf_node_get_cable(node, 0, &in);
    gf_node_get_cable(node, 1, &out);

    for (n = 0; n < blksize; n++) {
        tmp = gf_cable_get(in, n);
        tmp = (tmp + 1) * 0.5;
        if (tmp < 0) tmp = 0;
        else if (tmp > 1) tmp = 1;
        tmp = round(tmp);
        tmp = (2 * tmp) - 1;
        gf_cable_set(out, n, tmp);
    }
}

int node_bitter(gf_node *node)
{
    gf_node_cables_alloc(node, 2);
    gf_node_set_block(node, 1);
    gf_node_set_compute(node, compute);
    return GF_OK;
}



prev | home | next