History

added chaosnoise lil command

Paul Batchelor committed 5 years ago

Commit 1a2cdf91 parent 371e0a68 files · +146 −0Browse files

Unified · Split

8 files
  1. nodes/chaosnoise/chaosnoise.c +100 −0
  2. nodes/chaosnoise/chaosnoise.h +4 −0
  3. nodes/chaosnoise/config.mk +2 −0
  4. nodes/chaosnoise/l_chaosnoise.c +33 −0
  5. nodes/chaosnoise/test.lil +3 −0
  6. nodes/config.mk +1 −0
  7. nodes/loader.c +2 −0
  8. nodes/sknodes.h +1 −0
nodes/chaosnoise/chaosnoise.c+100−0
@@ -0,0 +1,100 @@
1+#include <math.h>
2+#include <stdlib.h>
3+#include <stdint.h>
4+#include "patchwerk.h"
5+#include "core.h"
6+#define SK_CHAOSNOISE_PRIV
7+#include "dsp/chaosnoise.h"
8+
9+struct chaosnoise_n {
10+ pw_cable *chaos;
11+ pw_cable *rate;
12+ pw_cable *out;
13+ sk_chaosnoise chaosnoise;
14+};
15+
16+static void compute(pw_node *node)
17+{
18+ int blksize;
19+ int n;
20+ struct chaosnoise_n *chaosnoise;
21+
22+ blksize = pw_node_blksize(node);
23+
24+ chaosnoise = (struct chaosnoise_n *)pw_node_get_data(node);
25+
26+ for (n = 0; n < blksize; n++) {
27+ PWFLT chaos, rate, out;
28+
29+ chaos = pw_cable_get(chaosnoise->chaos, n);
30+ sk_chaosnoise_chaos(&chaosnoise->chaosnoise, chaos);
31+ rate = pw_cable_get(chaosnoise->rate, n);
32+ sk_chaosnoise_rate(&chaosnoise->chaosnoise, rate);
33+
34+ out = sk_chaosnoise_tick(&chaosnoise->chaosnoise);
35+ pw_cable_set(chaosnoise->out, n, out);
36+ }
37+}
38+
39+static void destroy(pw_node *node)
40+{
41+ pw_patch *patch;
42+ int rc;
43+ void *ud;
44+ rc = pw_node_get_patch(node, &patch);
45+ if (rc != PW_OK) return;
46+ pw_node_cables_free(node);
47+ ud = pw_node_get_data(node);
48+ pw_memory_free(patch, &ud);
49+}
50+
51+int sk_node_chaosnoise(sk_core *core)
52+{
53+ pw_patch *patch;
54+ pw_node *node;
55+ int rc;
56+ sk_param chaos, rate;
57+ SKFLT init;
58+ void *ud;
59+ struct chaosnoise_n *chaosnoise;
60+ int sr;
61+
62+ rc = sk_param_get_constant(core, &init);
63+ SK_ERROR_CHECK(rc);
64+
65+ rc = sk_param_get(core, &rate);
66+ SK_ERROR_CHECK(rc);
67+
68+ rc = sk_param_get(core, &chaos);
69+ SK_ERROR_CHECK(rc);
70+
71+ patch = sk_core_patch(core);
72+
73+ rc = pw_memory_alloc(patch, sizeof(struct chaosnoise_n), &ud);
74+ SK_PW_ERROR_CHECK(rc);
75+ chaosnoise = (struct chaosnoise_n *)ud;
76+
77+ sr = pw_patch_srate_get(patch);
78+ sk_chaosnoise_init(&chaosnoise->chaosnoise, sr, init);
79+
80+ rc = pw_patch_new_node(patch, &node);
81+ SK_PW_ERROR_CHECK(rc);
82+
83+ rc = pw_node_cables_alloc(node, 3);
84+ SK_PW_ERROR_CHECK(rc);
85+
86+ pw_node_set_block(node, 2);
87+
88+ pw_node_get_cable(node, 0, &chaosnoise->chaos);
89+ pw_node_get_cable(node, 1, &chaosnoise->rate);
90+ pw_node_get_cable(node, 2, &chaosnoise->out);
91+
92+ pw_node_set_data(node, chaosnoise);
93+ pw_node_set_compute(node, compute);
94+ pw_node_set_destroy(node, destroy);
95+
96+ sk_param_set(core, node, &chaos, 0);
97+ sk_param_set(core, node, &rate, 1);
98+ sk_param_out(core, node, 2);
99+ return 0;
100+}
nodes/chaosnoise/chaosnoise.h+4−0
@@ -0,0 +1,4 @@
1+#ifndef SK_NODE_CHAOSNOISE_H
2+#define SK_NODE_CHAOSNOISE_H
3+int sk_node_chaosnoise(sk_core *core);
4+#endif
nodes/chaosnoise/config.mk+2−0
@@ -0,0 +1,2 @@
1+OBJ+=nodes/chaosnoise/chaosnoise.o
2+OBJ+=nodes/chaosnoise/l_chaosnoise.o
nodes/chaosnoise/l_chaosnoise.c+33−0
@@ -0,0 +1,33 @@
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 "chaosnoise.h"
9+
10+static lil_value_t chaosnoise(lil_t lil, size_t argc, lil_value_t *argv)
11+{
12+ sk_core *core;
13+ int rc;
14+ int i;
15+
16+ core = lil_get_data(lil);
17+
18+ SKLIL_ARITY_CHECK(lil, "chaosnoise", argc, 3);
19+
20+ for (i = 0; i < 3; i++) {
21+ rc = sklil_param(core, argv[i]);
22+ SKLIL_PARAM_CHECK(lil, rc, "chaosnoise");
23+ }
24+
25+ rc = sk_node_chaosnoise(core);
26+ SKLIL_ERROR_CHECK(lil, rc, "chaosnoise didn't work out.");
27+ return NULL;
28+}
29+
30+void sklil_load_chaosnoise(lil_t lil)
31+{
32+ lil_register(lil, "chaosnoise", chaosnoise);
33+}
nodes/chaosnoise/test.lil+3−0
@@ -0,0 +1,3 @@
1+chaosnoise 1.9 4000 0.141
2+wavout zz "test.wav"
3+computes 10
nodes/config.mk+1−0
@@ -26,3 +26,4 @@ include nodes/modalres/config.mk · 25 unmodified lines
2626 include nodes/chorus/config.mk
2727 include nodes/bezier/config.mk
2828 include nodes/bitnoise/config.mk
29+include nodes/chaosnoise/config.mk
nodes/loader.c+2−0
@@ -33,6 +33,7 @@ void sklil_load_modalres(lil_t lil); · 32 unmodified lines
3333 void sklil_load_chorus(lil_t lil);
3434 void sklil_load_bezier(lil_t lil);
3535 void sklil_load_bitnoise(lil_t lil);
36+void sklil_load_chaosnoise(lil_t lil);
3637
3738 void sklil_nodes(lil_t lil)
3839 {
@@ -64,6 +65,7 @@ void sklil_nodes(lil_t lil) · 25 unmodified lines
6465 sklil_load_chorus(lil);
6566 sklil_load_bezier(lil);
6667 sklil_load_bitnoise(lil);
68+ sklil_load_chaosnoise(lil);
6769 }
6870
6971 static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv)
nodes/sknodes.h+1−0
@@ -31,4 +31,5 @@ int sk_node_modalres(sk_core *core); · 30 unmodified lines
3131 int sk_node_chorus(sk_core *core);
3232 int sk_node_bezier(sk_core *core);
3333 int sk_node_bitnoise(sk_core *core);
34+int sk_node_chaosnoise(sk_core *core);
3435 #endif

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