~pbatch/patchwerk

patchwerk/examples/adder.c -rw-r--r-- 1.1 KiB
9c265356 — paul plan9 additions from Sigrid 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdlib.h>
#include <soundpipe.h>
#include "patchwerk.h"
#include "adder.h"

static void compute(pw_node *node)
{
    int i;
    int blksize;
    SPFLOAT in1;
    SPFLOAT in2;
    adder_d *adder;

    adder = pw_node_get_data(node);
    blksize = pw_node_blksize(node); 
    for(i = 0; i < blksize; i++) {
        in1 = pw_cable_get(adder->in1, i);
        in2 = pw_cable_get(adder->in2, i);
        pw_cable_set(adder->out, i, in1 + in2);
    }
}

static void destroy(pw_node *node)
{
    adder_d *adder;

    adder = (adder_d *) pw_node_get_data(node);

    pw_node_cables_free(node);

    free(adder);
}

void node_adder(pw_node *node)
{
    adder_d *adder;

    adder = malloc(sizeof(adder_d));

    pw_node_cables_alloc(node, 3);
    pw_node_get_cable(node, 0, &adder->in1);
    pw_node_get_cable(node, 1, &adder->in2);
    pw_node_get_cable(node, 2, &adder->out);
    pw_node_set_block(node, 2);
    
    pw_cable_set_constant(adder->in1, 0);
    pw_cable_set_constant(adder->in2, 0);

    pw_node_set_type(node, 0);
    pw_node_set_data(node, adder);
    pw_node_set_compute(node, compute);
    pw_node_set_destroy(node, destroy);
}