~pbatch/patchwerk

ref: e85df2e0b071415a143ebd8a4091638b801c4b58 patchwerk/dsp/eqfil.c -rw-r--r-- 1.5 KiB
e85df2e0 — paul re-enabled eqfil 1 year, 1 month 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
#include <stdlib.h>
#include <soundpipe.h>
#include "patchwerk.h"
#include "eqfil.h"
#include "ugen_enums.h"

static void destroy(pw_node *node)
{
    eqfil_d *eqfil;

    eqfil = (eqfil_d *) pw_node_get_data(node);

    sp_peakeq_destroy(&eqfil->eqfil);

    pw_node_cables_free(node);

    free(eqfil);
}

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

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

    for(i = 0; i < blksize; i++) {
        in = pw_cable_get(eqfil->in, i);
        eqfil->eqfil->freq = pw_cable_get(eqfil->p_freq, i);
        eqfil->eqfil->bw = pw_cable_get(eqfil->p_bw, i);
        eqfil->eqfil->gain = pw_cable_get(eqfil->p_gain, i);
        sp_peakeq_compute(eqfil->sp, eqfil->eqfil, &in, &out);
        pw_cable_set(eqfil->out, i, out);
    }
}

void node_eqfil(sp_data *sp, pw_node *node)
{
    eqfil_d *eqfil;

    eqfil = malloc(sizeof(eqfil_d));
    eqfil->sp = sp;

    sp_peakeq_create(&eqfil->eqfil);
    sp_peakeq_init(sp, eqfil->eqfil);
    pw_node_cables_alloc(node, 5);
    pw_node_get_cable(node, 0, &eqfil->in);

    pw_node_get_cable(node, 1, &eqfil->p_freq);
    pw_node_get_cable(node, 2, &eqfil->p_bw);
    pw_node_get_cable(node, 3, &eqfil->p_gain);
    pw_node_get_cable(node, 4, &eqfil->out);
    pw_node_set_block(node, 4);

    pw_node_set_type(node, TYPE_EQFIL);
    pw_node_set_data(node, eqfil);
    pw_node_set_compute(node, compute);
    pw_node_set_destroy(node, destroy);
}