~pbatch/patchwerk

ref: 21ff2ef695ea76c09c64a7af842d0ad937cceeb2 patchwerk/dsp/dcblock.c -rw-r--r-- 1.4 KiB
21ff2ef6 — paul bigverb 1 year, 2 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <soundpipe.h>
#include "patchwerk.h"
#include "dcblock.h"
#include "ugen_enums.h"

static void setup(pw_node *node)
{
    sp_data *sp;
    dcblock_d *dcblock;

    sp = (sp_data *)pw_node_get_data(node);

    dcblock = malloc(sizeof(dcblock_d));
    dcblock->sp = sp;

    sp_dcblock_create(&dcblock->dcblock);
    sp_dcblock_init(sp, dcblock->dcblock);

    pw_node_cables_alloc(node, 2);
    pw_node_get_cable(node, 0, &dcblock->in);

    pw_node_get_cable(node, 1, &dcblock->out);
    pw_node_set_block(node, 1);

    pw_node_set_type(node, TYPE_DCBLOCK);
    pw_node_set_data(node, dcblock);
}

static void destroy(pw_node *node)
{
    dcblock_d *dcblock;

    dcblock = (dcblock_d *) pw_node_get_data(node);

    sp_dcblock_destroy(&dcblock->dcblock);

    pw_node_cables_free(node);

    free(dcblock);
}

static void compute(pw_node *node)
{
    int i;
    int blksize;
    dcblock_d *dcblock;
    SPFLOAT in;
    SPFLOAT out;

    dcblock = pw_node_get_data(node);
    blksize = pw_node_blksize(node);

    for(i = 0; i < blksize; i++) {
        in = pw_cable_get(dcblock->in, i);
        sp_dcblock_compute(dcblock->sp, dcblock->dcblock, &in, &out);
        pw_cable_set(dcblock->out, i, out);
    }
}

void node_dcblock(pw_node *node, void *ud)
{
    pw_node_set_setup(node, setup);
    pw_node_set_compute(node, compute);
    pw_node_set_destroy(node, destroy);
    pw_node_set_data(node, ud);
}