Wrap Trig

Wrap Trig

Super niche node. Takes an input signal (presumably a phasor), and sends a trigger when the phasor wraps around (aka, the current sample is less than previous sample).

<<wraptrig.c>>=
#include <stdlib.h>
#include "graforge.h"
static void compute(gf_node *node)
{
    int blksize;
    gf_cable *c[2];
    int n;
    GFFLT *last;

    blksize = gf_node_blksize(node);
    last = gf_node_get_data(node);

    gf_node_get_cable(node, 0, &c[0]);
    gf_node_get_cable(node, 1, &c[1]);

    for (n = 0; n < blksize; n++) {
        GFFLT tick;
        GFFLT in;
        tick = 0;

        in = gf_cable_get(c[0], n);

        if (in < *last) tick = 1;

        gf_cable_set(c[1], n, tick);
        *last = in;
    }
}

static void destroy(gf_node *node)
{
    GFFLT *last;
    last = gf_node_get_data(node);
    gf_node_cables_free(node);
    free(last);
}

int node_wraptrig(gf_node *node)
{
    GFFLT *last;

    last = calloc(1, sizeof(GFFLT));
    gf_node_cables_alloc(node, 2);
    gf_node_set_block(node, 1);
    gf_node_set_compute(node, compute);
    gf_node_set_destroy(node, destroy);
    gf_node_set_data(node, last);
    return GF_OK;
}



prev | home | next