History

added modalres node

Paul Batchelor committed 5 years ago

Commit fb5d24c1 parent 6c101107 files · +150 −0Browse files

Unified · Split

7 files
  1. nodes/config.mk +1 −0
  2. nodes/loader.c +2 −0
  3. nodes/modalres/config.mk +2 −0
  4. nodes/modalres/l_modalres.c +32 −0
  5. nodes/modalres/modalres.c +103 −0
  6. nodes/modalres/modalres.h +4 −0
  7. nodes/modalres/test.lil +6 −0
nodes/config.mk+1−0
@@ -22,3 +22,4 @@ include nodes/expmap/config.mk · 21 unmodified lines
22include nodes/phasewarp/config.mk22include nodes/phasewarp/config.mk
23include nodes/oscf/config.mk23include nodes/oscf/config.mk
24include nodes/biramp/config.mk24include nodes/biramp/config.mk
25include nodes/modalres/config.mk
nodes/loader.c+2−0
@@ -29,6 +29,7 @@ void sklil_load_expmap(lil_t lil); · 28 unmodified lines
29void sklil_load_oscf(lil_t lil);29void sklil_load_oscf(lil_t lil);
30void sklil_load_phasewarp(lil_t lil);30void sklil_load_phasewarp(lil_t lil);
31void sklil_load_biramp(lil_t lil);31void sklil_load_biramp(lil_t lil);
32void sklil_load_modalres(lil_t lil);
32 33
33void sklil_nodes(lil_t lil)34void sklil_nodes(lil_t lil)
34{35{
@@ -56,6 +57,7 @@ void sklil_nodes(lil_t lil) · 21 unmodified lines
56 sklil_load_oscf(lil);57 sklil_load_oscf(lil);
57 sklil_load_phasewarp(lil);58 sklil_load_phasewarp(lil);
58 sklil_load_biramp(lil);59 sklil_load_biramp(lil);
60 sklil_load_modalres(lil);
59}61}
60 62
61static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv)63static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv)
nodes/modalres/config.mk+2−0
@@ -0,0 +1,2 @@
1OBJ+=nodes/modalres/modalres.o
2OBJ+=nodes/modalres/l_modalres.o
nodes/modalres/l_modalres.c+32−0
@@ -0,0 +1,32 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include "lil/lil.h"
5#include "patchwerk/patchwerk.h"
6#include "core.h"
7#include "sklil.h"
8#include "modalres.h"
9
10static lil_value_t modalres(lil_t lil, size_t argc, lil_value_t *argv)
11{
12 sk_core *core;
13 int rc;
14 int i;
15 core = lil_get_data(lil);
16
17 SKLIL_ARITY_CHECK(lil, "modalres", argc, 3);
18
19 for (i = 0; i < 3; i++) {
20 rc = sklil_param(core, argv[i]);
21 SKLIL_PARAM_CHECK(lil, rc, "modalres");
22 }
23
24 rc = sk_node_modalres(core);
25 SKLIL_ERROR_CHECK(lil, rc, "modalres didn't work out.");
26 return NULL;
27}
28
29void sklil_load_modalres(lil_t lil)
30{
31 lil_register(lil, "modalres", modalres);
32}
nodes/modalres/modalres.c+103−0
@@ -0,0 +1,103 @@
1#include <math.h>
2#include <stdlib.h>
3#include <stdint.h>
4#include "patchwerk.h"
5#include "core.h"
6#define SK_MODALRES_PRIV
7#include "dsp/modalres.h"
8
9struct modalres_n {
10 pw_cable *in;
11 pw_cable *freq;
12 pw_cable *q;
13 pw_cable *out;
14 sk_modalres modalres;
15};
16
17static void compute(pw_node *node)
18{
19 int blksize;
20 int n;
21 struct modalres_n *modalres;
22
23 blksize = pw_node_blksize(node);
24
25 modalres = (struct modalres_n *)pw_node_get_data(node);
26
27 for (n = 0; n < blksize; n++) {
28 PWFLT in, freq, q, out;
29 in = pw_cable_get(modalres->in, n);
30
31 freq = pw_cable_get(modalres->freq, n);
32 sk_modalres_freq(&modalres->modalres, freq);
33 q = pw_cable_get(modalres->q, n);
34 sk_modalres_q(&modalres->modalres, q);
35
36 out = sk_modalres_tick(&modalres->modalres, in);
37 pw_cable_set(modalres->out, n, out);
38 }
39}
40
41static void destroy(pw_node *node)
42{
43 pw_patch *patch;
44 int rc;
45 void *ud;
46 rc = pw_node_get_patch(node, &patch);
47 if (rc != PW_OK) return;
48 pw_node_cables_free(node);
49 ud = pw_node_get_data(node);
50 pw_memory_free(patch, &ud);
51}
52
53int sk_node_modalres(sk_core *core)
54{
55 pw_patch *patch;
56 pw_node *node;
57 int rc;
58 sk_param in, freq, q;
59 void *ud;
60 struct modalres_n *modalres;
61 int sr;
62
63 rc = sk_param_get(core, &q);
64 SK_ERROR_CHECK(rc);
65
66 rc = sk_param_get(core, &freq);
67 SK_ERROR_CHECK(rc);
68
69 rc = sk_param_get(core, &in);
70 SK_ERROR_CHECK(rc);
71
72 patch = sk_core_patch(core);
73
74 rc = pw_memory_alloc(patch, sizeof(struct modalres_n), &ud);
75 SK_PW_ERROR_CHECK(rc);
76 modalres = (struct modalres_n *)ud;
77
78 sr = pw_patch_srate_get(patch);
79 sk_modalres_init(&modalres->modalres, sr);
80
81 rc = pw_patch_new_node(patch, &node);
82 SK_PW_ERROR_CHECK(rc);
83
84 rc = pw_node_cables_alloc(node, 4);
85 SK_PW_ERROR_CHECK(rc);
86
87 pw_node_set_block(node, 3);
88
89 pw_node_get_cable(node, 0, &modalres->in);
90 pw_node_get_cable(node, 1, &modalres->freq);
91 pw_node_get_cable(node, 2, &modalres->q);
92 pw_node_get_cable(node, 3, &modalres->out);
93
94 pw_node_set_data(node, modalres);
95 pw_node_set_compute(node, compute);
96 pw_node_set_destroy(node, destroy);
97
98 sk_param_set(core, node, &in, 0);
99 sk_param_set(core, node, &freq, 1);
100 sk_param_set(core, node, &q, 2);
101 sk_param_out(core, node, 3);
102 return 0;
103}
nodes/modalres/modalres.h+4−0
@@ -0,0 +1,4 @@
1#ifndef SK_NODE_MODALRES_H
2#define SK_NODE_MODALRES_H
3int sk_node_modalres(sk_core *core);
4#endif
nodes/modalres/test.lil+6−0
@@ -0,0 +1,6 @@
1metro 6
2modalres zz [mtof 74] [rline 10 400 5]
3dcblocker zz
4mul zz 0.5
5wavout zz "test.wav"
6computes 10

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t