History

added osc to LIL

Paul Batchelor committed 5 years ago

Commit f8edee71 parent ab390828 files · +206 −1Browse files

Unified · Split

8 files
  1. core.org +36 −1
  2. nodes/config.mk +1 −0
  3. nodes/gensine/gensine.c +7 −0
  4. nodes/loader.c +14 −0
  5. nodes/osc/config.mk +2 −0
  6. nodes/osc/l_osc.c +34 −0
  7. nodes/osc/osc.c +108 −0
  8. nodes/osc/osc.h +4 −0
core.org+36−1
@@ -395,6 +395,37 @@ int sk_param_get(sk_core *core, sk_param *p) · 394 unmodified lines
395 return 0;395 return 0;
396}396}
397#+END_SRC397#+END_SRC
398
399For situations where only constants are allowed, use
400=sk_param_get_constant=.
401
402#+NAME: funcdefs
403#+BEGIN_SRC c
404int sk_param_get_constant(sk_core *core, SKFLT *val);
405#+END_SRC
406
407#+NAME: funcs
408#+BEGIN_SRC c
409int sk_param_get_constant(sk_core *core, SKFLT *val)
410{
411 sk_stack *stk;
412 sk_stacklet *s;
413 int rc;
414
415 stk = &core->stack;
416
417 rc = sk_stack_pop(stk, &s);
418 SK_ERROR_CHECK(rc);
419
420 if (s->type != SK_TYPE_CONSTANT) {
421 /* Wrong type! */
422 return 1;
423 }
424
425 *val = s->f;
426 return 0;
427}
428#+END_SRC
398** Setting a Parameter429** Setting a Parameter
399Set a parameter with =sk_param_set=.430Set a parameter with =sk_param_set=.
400 431
@@ -922,7 +953,11 @@ int sk_core_table_pop(sk_core *core, sk_table **tab) · 521 unmodified lines
922 953
923 SK_ERROR_CHECK(rc);954 SK_ERROR_CHECK(rc);
924 955
925 if (s->type != SK_TYPE_TABLE) return 1;956 if (s->type != SK_TYPE_TABLE) {
957 printf("uh oh type is %d, %g\n", s->type, s->f);
958 printf("%d items on stack\n", core->stack.pos);
959 return 1;
960 }
926 961
927 *tab = (sk_table *)s->ptr;962 *tab = (sk_table *)s->ptr;
928 963
nodes/config.mk+1−0
@@ -6,3 +6,4 @@ include nodes/phasor/config.mk · 5 unmodified lines
6include nodes/rephasor/config.mk6include nodes/rephasor/config.mk
7include nodes/tabnew/config.mk7include nodes/tabnew/config.mk
8include nodes/gensine/config.mk8include nodes/gensine/config.mk
9include nodes/osc/config.mk
nodes/gensine/gensine.c+7−0
@@ -21,10 +21,17 @@ static lil_value_t gensine(lil_t lil, size_t argc, lil_value_t *argv) · 20 unmodified lines
21 21
22 if (rc) {22 if (rc) {
23 /* TODO: error handling */23 /* TODO: error handling */
24 printf("uh oh\n");
24 }25 }
25 26
26 sk_gen_sine(sk_table_data(tab), sk_table_size(tab));27 sk_gen_sine(sk_table_data(tab), sk_table_size(tab));
27 28
29 rc = sk_core_table_push(core, tab);
30
31 if (rc) {
32 /* TODO: error handling */
33 }
34
28 return NULL;35 return NULL;
29}36}
30 37
nodes/loader.c+14−0
@@ -13,6 +13,7 @@ void sklil_load_phasor(lil_t lil); · 12 unmodified lines
13void sklil_load_rephasor(lil_t lil);13void sklil_load_rephasor(lil_t lil);
14void sklil_load_tabnew(lil_t lil);14void sklil_load_tabnew(lil_t lil);
15void sklil_load_gensine(lil_t lil);15void sklil_load_gensine(lil_t lil);
16void sklil_load_osc(lil_t lil);
16 17
17void sklil_nodes(lil_t lil)18void sklil_nodes(lil_t lil)
18{19{
@@ -24,6 +25,7 @@ void sklil_nodes(lil_t lil) · 5 unmodified lines
24 sklil_load_rephasor(lil);25 sklil_load_rephasor(lil);
25 sklil_load_tabnew(lil);26 sklil_load_tabnew(lil);
26 sklil_load_gensine(lil);27 sklil_load_gensine(lil);
28 sklil_load_osc(lil);
27}29}
28 30
29static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv)31static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv)
@@ -37,6 +39,17 @@ static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv) · 7 unmodified lines
37 return NULL;39 return NULL;
38}40}
39 41
42static lil_value_t param(lil_t lil, size_t argc, lil_value_t *argv)
43{
44 sk_core *core;
45 core = lil_get_data(lil);
46
47 SKLIL_ARITY_CHECK(lil, "param", argc, 1);
48
49 sklil_param(core, argv[0]);
50 return NULL;
51}
52
40void sklil_loader(lil_t lil)53void sklil_loader(lil_t lil)
41{54{
42 sk_core *core;55 sk_core *core;
@@ -44,6 +57,7 @@ void sklil_loader(lil_t lil) · 1 unmodified line
44 lil_set_data(lil, core);57 lil_set_data(lil, core);
45 sklil_nodes(lil);58 sklil_nodes(lil);
46 lil_register(lil, "computes", computes);59 lil_register(lil, "computes", computes);
60 lil_register(lil, "param", param);
47}61}
48 62
49void sklil_clean(lil_t lil)63void sklil_clean(lil_t lil)
nodes/osc/config.mk+2−0
@@ -0,0 +1,2 @@
1OBJ+=nodes/osc/osc.o
2OBJ+=nodes/osc/l_osc.o
nodes/osc/l_osc.c+34−0
@@ -0,0 +1,34 @@
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 "osc.h"
9
10static lil_value_t osc(lil_t lil, size_t argc, lil_value_t *argv)
11{
12 sk_core *core;
13 int rc;
14 core = lil_get_data(lil);
15
16 SKLIL_ARITY_CHECK(lil, "osc", argc, 4);
17
18 /* skip param 0 */
19 sklil_param(core, argv[1]);
20 sklil_param(core, argv[2]);
21 sklil_param(core, argv[3]);
22
23 rc = sk_node_osc(core);
24
25 if (rc) {
26 /* TODO: error handling */
27 }
28 return NULL;
29}
30
31void sklil_load_osc(lil_t lil)
32{
33 lil_register(lil, "osc", osc);
34}
nodes/osc/osc.c+108−0
@@ -0,0 +1,108 @@
1#include <math.h>
2#include <stdlib.h>
3#include <stdint.h>
4#include "patchwerk.h"
5#include "core.h"
6#define SK_OSC_PRIV
7#include "dsp/osc.h"
8
9struct osc_n {
10 pw_cable *freq;
11 pw_cable *amp;
12 pw_cable *out;
13 sk_osc osc;
14};
15
16static void compute(pw_node *node)
17{
18 int blksize;
19 int n;
20 struct osc_n *osc;
21
22 blksize = pw_node_blksize(node);
23
24 osc = (struct osc_n *)pw_node_get_data(node);
25
26 for (n = 0; n < blksize; n++) {
27 PWFLT out, f, a;
28 f = pw_cable_get(osc->freq, n);
29 a = pw_cable_get(osc->amp, n);
30
31 sk_osc_freq(&osc->osc, f);
32 sk_osc_amp(&osc->osc, a);
33 out = sk_osc_tick(&osc->osc);
34
35 pw_cable_set(osc->out, n, out);
36 }
37}
38
39static 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
51int sk_node_osc(sk_core *core)
52{
53 pw_patch *patch;
54 pw_node *node;
55 int rc;
56 sk_param freq;
57 sk_param amp;
58 void *ud;
59 struct osc_n *osc;
60 int sr;
61 sk_table *tab;
62 SKFLT iphs;
63
64 rc = sk_param_get_constant(core, &iphs);
65 SK_ERROR_CHECK(rc);
66
67 rc = sk_param_get(core, &amp);
68 SK_ERROR_CHECK(rc);
69
70 rc = sk_param_get(core, &freq);
71 SK_ERROR_CHECK(rc);
72
73 rc = sk_core_table_pop(core, &tab);
74 SK_ERROR_CHECK(rc);
75
76 patch = sk_core_patch(core);
77
78 rc = pw_memory_alloc(patch, sizeof(struct osc_n), &ud);
79 SK_PW_ERROR_CHECK(rc);
80 osc = (struct osc_n *)ud;
81
82 sr = pw_patch_srate_get(patch);
83 sk_osc_init(&osc->osc, sr,
84 sk_table_data(tab),
85 sk_table_size(tab),
86 iphs);
87
88 rc = pw_patch_new_node(patch, &node);
89 SK_PW_ERROR_CHECK(rc);
90
91 rc = pw_node_cables_alloc(node, 3);
92 SK_PW_ERROR_CHECK(rc);
93
94 pw_node_set_block(node, 2);
95
96 pw_node_get_cable(node, 0, &osc->freq);
97 pw_node_get_cable(node, 1, &osc->amp);
98 pw_node_get_cable(node, 2, &osc->out);
99
100 pw_node_set_data(node, osc);
101 pw_node_set_compute(node, compute);
102 pw_node_set_destroy(node, destroy);
103
104 sk_param_set(core, node, &freq, 0);
105 sk_param_set(core, node, &amp, 1);
106 sk_param_out(core, node, 2);
107 return 0;
108}
nodes/osc/osc.h+4−0
@@ -0,0 +1,4 @@
1#ifndef SK_NODE_OSC_H
2#define SK_NODE_OSC_H
3int sk_node_osc(sk_core *core);
4#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