History

working lil interpreter

Paul Batchelor committed 5 years ago

Commit b895b2c1 parent 8b8b13613 files · +196 −1Browse files

Unified · Split

13 files
  1. Makefile +8 −1
  2. core.org +25 −0
  3. examples/ex4.lil +5 −0
  4. examples/hello.lil +3 −0
  5. nodes/arith/config.mk +1 −0
  6. nodes/arith/l_arith.c +27 −0
  7. nodes/loader.c +44 −0
  8. nodes/sine/config.mk +1 −0
  9. nodes/sine/l_sine.c +27 −0
  10. nodes/sklil.c +18 −0
  11. nodes/sklil.h +10 −0
  12. nodes/wavout/config.mk +1 −0
  13. nodes/wavout/l_wavout.c +26 −0
Makefile+8−1
@@ -8,7 +8,7 @@ WORGLE_FLAGS=-g -Werror · 7 unmodified lines
88 C89?=$(CC) -std=c89
99 C99?=$(CC) -std=c99
1010
11−CFLAGS += -Ipatchwerk -I.
11+CFLAGS += -Ipatchwerk -I. -Inodes
1212 CFLAGS += -Wall
1313 CFLAGS += -O3
1414 CFLAGS += -g
@@ -33,6 +33,7 @@ swell.c swell.h \ · 18 unmodified lines
3333 biramp.c biramp.h \
3434 core.c core.h \
3535 expmap.c expmap.h \
36+scale.c scale.h \
3637
3738 OBJ=\
3839 bigverb.o \
@@ -59,6 +60,9 @@ scale.o \ · 20 unmodified lines
5960 include nodes/config.mk
6061
6162 OBJ+=lil/lil.c99
63+OBJ+=lil/lil_main.c99
64+OBJ+=nodes/loader.o
65+OBJ+=nodes/sklil.o
6266
6367 .SUFFIX: .org .c
6468
@@ -133,6 +137,9 @@ libsndkit.a: tangle $(OBJ) · 68 unmodified lines
133137 @echo "Building $@"
134138 @$(AR) rcs $@ $(OBJ)
135139
140+sndkit: main.o $(OBJ)
141+ $(CC) $(CFLAGS) $^ -o $@
142+
136143 clean:
137144 $(RM) $(TANGLED)
138145 $(RM) worgle/worglite
core.org+25−0
@@ -118,6 +118,31 @@ void sk_core_compute(sk_core *core) · 117 unmodified lines
118118 }
119119 #+END_SRC
120120
121+=sk_core_computes= is like =sk_core_compute=, but computes
122+an approximuate number of seconds of audio. This value
123+gets rounded to the nearest block. The number of blocks
124+rendered gets rendered.
125+
126+#+NAME: funcdefs
127+#+BEGIN_SRC c
128+size_t sk_core_computes(sk_core *core, SKFLT secs);
129+#+END_SRC
130+
131+#+NAME: funcs
132+#+BEGIN_SRC c
133+size_t sk_core_computes(sk_core *core, SKFLT secs)
134+{
135+ size_t nblocks, n;
136+ nblocks = sk_core_seconds_to_blocks(core, secs);
137+
138+ for (n = 0; n < nblocks; n++) {
139+ sk_core_compute(core);
140+ }
141+
142+ return nblocks;
143+}
144+#+END_SRC
145+
121146 Building up nodes involves interacting with the patchwerk
122147 API. To get the top level struct of that opaquely, use
123148 =sk_core_patch=.
examples/ex4.lil+5−0
@@ -0,0 +1,5 @@
1+# basically ex3
2+sine 350 0.2
3+sine [add [sine 0.1 100] 440] 0.2
4+add zz zz
5+wavout zz test.wav
examples/hello.lil+3−0
@@ -0,0 +1,3 @@
1+sine 440 0.5
2+wavout zz "sine.wav"
3+computes 40
nodes/arith/config.mk+1−0
@@ -1 +1,2 @@
11 OBJ+=nodes/arith/arith.o
2+OBJ+=nodes/arith/l_arith.o
nodes/arith/l_arith.c+27−0
@@ -0,0 +1,27 @@
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 "arith.h"
9+
10+static lil_value_t add(lil_t lil, size_t argc, lil_value_t *argv)
11+{
12+ sk_core *core;
13+ core = lil_get_data(lil);
14+
15+ SKLIL_ARITY_CHECK(lil, "add", argc, 2);
16+
17+ sklil_param(core, argv[0]);
18+ sklil_param(core, argv[1]);
19+
20+ sk_node_add(core);
21+ return NULL;
22+}
23+
24+void sklil_load_arith(lil_t lil)
25+{
26+ lil_register(lil, "add", add);
27+}
nodes/loader.c+44−0
@@ -0,0 +1,44 @@
1+#include <stdlib.h>
2+#include <stdio.h>
3+#include "lil/lil.h"
4+#include "patchwerk/patchwerk.h"
5+#include "core.h"
6+#include "sklil.h"
7+
8+void sklil_load_sine(lil_t lil);
9+void sklil_load_wavout(lil_t lil);
10+void sklil_load_arith(lil_t lil);
11+
12+void sklil_nodes(lil_t lil)
13+{
14+ sklil_load_sine(lil);
15+ sklil_load_wavout(lil);
16+ sklil_load_arith(lil);
17+}
18+
19+static lil_value_t computes(lil_t lil, size_t argc, lil_value_t *argv)
20+{
21+ sk_core *core;
22+ core = lil_get_data(lil);
23+
24+ SKLIL_ARITY_CHECK(lil, "computes", argc, 1);
25+
26+ sk_core_computes(core, lil_to_double(argv[0]));
27+ return NULL;
28+}
29+
30+void sklil_loader(lil_t lil)
31+{
32+ sk_core *core;
33+ core = sk_core_new(44100);
34+ lil_set_data(lil, core);
35+ sklil_nodes(lil);
36+ lil_register(lil, "computes", computes);
37+}
38+
39+void sklil_clean(lil_t lil)
40+{
41+ sk_core *core;
42+ core = lil_get_data(lil);
43+ sk_core_del(core);
44+}
nodes/sine/config.mk+1−0
@@ -1 +1,2 @@
11 OBJ+=nodes/sine/sine.o
2+OBJ+=nodes/sine/l_sine.o
nodes/sine/l_sine.c+27−0
@@ -0,0 +1,27 @@
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 "sine.h"
9+
10+static lil_value_t sine(lil_t lil, size_t argc, lil_value_t *argv)
11+{
12+ sk_core *core;
13+ core = lil_get_data(lil);
14+
15+ SKLIL_ARITY_CHECK(lil, "sine", argc, 2);
16+
17+ sklil_param(core, argv[0]);
18+ sklil_param(core, argv[1]);
19+
20+ sk_node_sine(core);
21+ return NULL;
22+}
23+
24+void sklil_load_sine(lil_t lil)
25+{
26+ lil_register(lil, "sine", sine);
27+}
nodes/sklil.c+18−0
@@ -0,0 +1,18 @@
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+
8+void sklil_param(sk_core *core, lil_value_t arg)
9+{
10+ const char *sarg;
11+ sarg = lil_to_string(arg);
12+
13+ if (!strcmp(sarg, "zz") || strlen(sarg) == 0) {
14+ return;
15+ }
16+
17+ sk_core_constant(core, lil_to_double(arg));
18+}
nodes/sklil.h+10−0
@@ -0,0 +1,10 @@
1+#ifndef SKLIL_H
2+#define SKLIL_H
3+#define SKLIL_ARITY_CHECK(LIL, NODE, ARGC, NARGS) \
4+if (ARGC < NARGS) { \
5+ lil_set_error(LIL, NODE ": not enough args."); \
6+ return NULL; \
7+}
8+
9+void sklil_param(sk_core *core, lil_value_t arg);
10+#endif
nodes/wavout/config.mk+1−0
@@ -1 +1,2 @@
11 OBJ+=nodes/wavout/wavout.c99
2+OBJ+=nodes/wavout/l_wavout.o
nodes/wavout/l_wavout.c+26−0
@@ -0,0 +1,26 @@
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 "wavout.h"
9+
10+static lil_value_t wavout(lil_t lil, size_t argc, lil_value_t *argv)
11+{
12+ sk_core *core;
13+ core = lil_get_data(lil);
14+
15+ SKLIL_ARITY_CHECK(lil, "wavout", argc, 2);
16+
17+ sklil_param(core, argv[0]);
18+
19+ sk_node_wavout(core, lil_to_string(argv[1]));
20+ return NULL;
21+}
22+
23+void sklil_load_wavout(lil_t lil)
24+{
25+ lil_register(lil, "wavout", wavout);
26+}

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