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
8C89?=$(CC) -std=c898C89?=$(CC) -std=c89
9C99?=$(CC) -std=c999C99?=$(CC) -std=c99
10 10
11CFLAGS += -Ipatchwerk -I.11CFLAGS += -Ipatchwerk -I. -Inodes
12CFLAGS += -Wall12CFLAGS += -Wall
13CFLAGS += -O313CFLAGS += -O3
14CFLAGS += -g14CFLAGS += -g
@@ -33,6 +33,7 @@ swell.c swell.h \ · 18 unmodified lines
33biramp.c biramp.h \33biramp.c biramp.h \
34core.c core.h \34core.c core.h \
35expmap.c expmap.h \35expmap.c expmap.h \
36scale.c scale.h \
36 37
37OBJ=\38OBJ=\
38bigverb.o \39bigverb.o \
@@ -59,6 +60,9 @@ scale.o \ · 20 unmodified lines
59include nodes/config.mk60include nodes/config.mk
60 61
61OBJ+=lil/lil.c9962OBJ+=lil/lil.c99
63OBJ+=lil/lil_main.c99
64OBJ+=nodes/loader.o
65OBJ+=nodes/sklil.o
62 66
63.SUFFIX: .org .c67.SUFFIX: .org .c
64 68
@@ -133,6 +137,9 @@ libsndkit.a: tangle $(OBJ) · 68 unmodified lines
133 @echo "Building $@"137 @echo "Building $@"
134 @$(AR) rcs $@ $(OBJ)138 @$(AR) rcs $@ $(OBJ)
135 139
140sndkit: main.o $(OBJ)
141 $(CC) $(CFLAGS) $^ -o $@
142
136clean:143clean:
137 $(RM) $(TANGLED)144 $(RM) $(TANGLED)
138 $(RM) worgle/worglite145 $(RM) worgle/worglite
core.org+25−0
@@ -118,6 +118,31 @@ void sk_core_compute(sk_core *core) · 117 unmodified lines
118}118}
119#+END_SRC119#+END_SRC
120 120
121=sk_core_computes= is like =sk_core_compute=, but computes
122an approximuate number of seconds of audio. This value
123gets rounded to the nearest block. The number of blocks
124rendered gets rendered.
125
126#+NAME: funcdefs
127#+BEGIN_SRC c
128size_t sk_core_computes(sk_core *core, SKFLT secs);
129#+END_SRC
130
131#+NAME: funcs
132#+BEGIN_SRC c
133size_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
121Building up nodes involves interacting with the patchwerk146Building up nodes involves interacting with the patchwerk
122API. To get the top level struct of that opaquely, use147API. To get the top level struct of that opaquely, use
123=sk_core_patch=.148=sk_core_patch=.
examples/ex4.lil+5−0
@@ -0,0 +1,5 @@
1# basically ex3
2sine 350 0.2
3sine [add [sine 0.1 100] 440] 0.2
4add zz zz
5wavout zz test.wav
examples/hello.lil+3−0
@@ -0,0 +1,3 @@
1sine 440 0.5
2wavout zz "sine.wav"
3computes 40
nodes/arith/config.mk+1−0
@@ -1 +1,2 @@
1OBJ+=nodes/arith/arith.o1OBJ+=nodes/arith/arith.o
2OBJ+=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
10static 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
24void 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
8void sklil_load_sine(lil_t lil);
9void sklil_load_wavout(lil_t lil);
10void sklil_load_arith(lil_t lil);
11
12void sklil_nodes(lil_t lil)
13{
14 sklil_load_sine(lil);
15 sklil_load_wavout(lil);
16 sklil_load_arith(lil);
17}
18
19static 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
30void 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
39void 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 @@
1OBJ+=nodes/sine/sine.o1OBJ+=nodes/sine/sine.o
2OBJ+=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
10static 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
24void 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
8void 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) \
4if (ARGC < NARGS) { \
5 lil_set_error(LIL, NODE ": not enough args."); \
6 return NULL; \
7}
8
9void sklil_param(sk_core *core, lil_value_t arg);
10#endif
nodes/wavout/config.mk+1−0
@@ -1 +1,2 @@
1OBJ+=nodes/wavout/wavout.c991OBJ+=nodes/wavout/wavout.c99
2OBJ+=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
10static 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
23void 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