~pbatch/patchwerk

abf5b62a8d4f1822187e1f79f44331bea5af573c — paul 2 months ago 1b3519a
added verbity node

FossilOrigin-Name: 2e976ba62dc3ddfcba8fbdc2742ad3612014f36540c33a5662cc4ecdcff67061
5 files changed, 169 insertions(+), 0 deletions(-)

M dsp/config.mk
M dsp/ugen_list.h
A dsp/verbity.c
A dsp/verbity.h
A runt/nodes/r_verbity.c
M dsp/config.mk => dsp/config.mk +1 -0
@@ 84,6 84,7 @@ NODES=\
	pdhalf.o\
	tabread.o\
	oscmorph.o\
	verbity.o\

# old list
#NODES=\

M dsp/ugen_list.h => dsp/ugen_list.h +1 -0
@@ 110,3 110,4 @@ UGEN(TYPE_SLICE, slice)
/* UGEN(TYPE_SNDWARP, sndwarp) */
/* UGEN(TYPE_CONV, conv) */
UGEN(TYPE_OSCMORPH, oscmorph)
UGEN(TYPE_VERBITY, verbity)

A dsp/verbity.c => dsp/verbity.c +93 -0
@@ 0,0 1,93 @@
#include <soundpipe.h>
#include "patchwerk.h"
#include "verbity.h"
#include "ugen_enums.h"

static void compute(pw_node *node)
{
    verbity_d *vd;
    int blksize;
    int n;

    vd = (verbity_d *)pw_node_get_data(node);

    blksize = pw_node_blksize(node);

    for (n = 0; n < blksize; n++) {
        PWFLT in[2], out[2];
        PWFLT bigness, longness, darkness;

        in[0] = pw_cable_get(vd->in[0], n);
        in[1] = pw_cable_get(vd->in[1], n);

        bigness = pw_cable_get(vd->bigness, n);
        sp_verbity_bigness(&vd->v, bigness);
        longness = pw_cable_get(vd->longness, n);
        sp_verbity_longness(&vd->v, longness);
        darkness = pw_cable_get(vd->darkness, n);
        sp_verbity_darkness(&vd->v, darkness);

        sp_verbity_compute(NULL, &vd->v,
                           &in[0], &in[1],
                           &out[0], &out[1]);

        pw_cable_set(vd->out[0], n, out[0]);
        pw_cable_set(vd->out[1], n, out[1]);
    }
}

static void destroy(pw_node *node)
{
    int rc;
    pw_patch *patch;
    void *ud;

    pw_node_cables_free(node);

    rc = pw_node_get_patch(node, &patch);
    if (rc != PW_OK) return;

    ud = pw_node_get_data(node);

    pw_memory_free(patch, &ud);
}

int node_verbity(pw_node *node)
{
    verbity_d *vd;
    pw_patch *patch;
    int rc;
    void *ud;
    int sr;

    rc = pw_node_get_patch(node, &patch);

    if (rc != PW_OK) return rc;

    rc = pw_memory_alloc(patch, sizeof(verbity_d), &ud);
    if (rc != PW_OK) return rc;

    vd = (verbity_d *)ud;

    sr = pw_patch_srate_get(patch);
    sp_verbity_reset(&vd->v, sr);

    pw_node_cables_alloc(node, 7);
    pw_node_set_block(node, 5);
    pw_node_set_block(node, 6);

    pw_node_get_cable(node, 0, &vd->in[0]);
    pw_node_get_cable(node, 1, &vd->in[1]);
    pw_node_get_cable(node, 2, &vd->bigness);
    pw_node_get_cable(node, 3, &vd->longness);
    pw_node_get_cable(node, 4, &vd->darkness);
    pw_node_get_cable(node, 5, &vd->out[0]);
    pw_node_get_cable(node, 6, &vd->out[1]);

    pw_node_set_data(node, vd);
    pw_node_set_compute(node, compute);
    pw_node_set_destroy(node, destroy);
    pw_node_set_type(node, TYPE_VERBITY);

    return PW_OK;
}

A dsp/verbity.h => dsp/verbity.h +12 -0
@@ 0,0 1,12 @@
#ifndef PW_VERBITY_H
#define PW_VERBITY_H
typedef struct {
    sp_verbity v;
    pw_cable *in[2];
    pw_cable *bigness;
    pw_cable *longness;
    pw_cable *darkness;
    pw_cable *out[2];
} verbity_d;
int node_verbity(pw_node *node);
#endif

A runt/nodes/r_verbity.c => runt/nodes/r_verbity.c +62 -0
@@ 0,0 1,62 @@
#include <stdio.h>
#include <runt.h>
#include <soundpipe.h>
#include "patchwerk.h"
#include "runt_patchwerk.h"
#include "verbity.h"

static runt_int rproc_node_verbity(runt_vm *vm, runt_ptr p)
{
    runt_int rc;
    pw_node *node;
    pw_patch *patch;
    rpw_param in[2];
    rpw_param bigness;
    rpw_param longness;
    rpw_param darkness;
    runt_stacklet *out[2];

    rc = rpw_get_param(vm, &darkness);
    RUNT_ERROR_CHECK(rc);

    rc = rpw_get_param(vm, &longness);
    RUNT_ERROR_CHECK(rc);

    rc = rpw_get_param(vm, &bigness);
    RUNT_ERROR_CHECK(rc);

    rc = rpw_get_param(vm, &in[1]);
    RUNT_ERROR_CHECK(rc);

    rc = rpw_get_param(vm, &in[0]);
    RUNT_ERROR_CHECK(rc);

    rc = runt_ppush(vm, &out[0]);
    RUNT_ERROR_CHECK(rc);
    rc = runt_ppush(vm, &out[1]);
    RUNT_ERROR_CHECK(rc);

    patch = rpw_get_patch(p);
    rc = pw_patch_new_node(patch, &node);
    PW_RUNT_ERROR_CHECK(rc);

    rc = node_verbity(node);
    PW_RUNT_ERROR_CHECK(rc);

    rpw_set_param(vm, node, &in[0], 0);
    rpw_set_param(vm, node, &in[1], 1);
    rpw_set_param(vm, node, &bigness, 2);
    rpw_set_param(vm, node, &longness, 3);
    rpw_set_param(vm, node, &darkness, 4);
    rpw_push_output(vm, node, out[0], 5);
    rpw_push_output(vm, node, out[1], 6);
    return RUNT_OK;
}

runt_int rpw_node_verbity(runt_vm *vm, runt_ptr p)
{
    patchwerk_word_define(vm, p,
                          "verbity", 7,
                          rproc_node_verbity);
    return RUNT_OK;
}