Files: fdc9644582b3e2b875598b772c5bdda6c74ef9e5 / studio.c
1399 bytesRaw
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | struct tune_dl { |
12 | void *handle; |
13 | ino_t inode; |
14 | struct tune *tune; |
15 | }; |
16 | |
17 | static int tune_dl_load(struct tune_dl *dl, const char *libfname) |
18 | { |
19 | struct stat st; |
20 | if (stat(libfname, &st) < 0) { |
21 | warn("stat"); |
22 | return -1; |
23 | } |
24 | if (dl->inode == st.st_ino) { |
25 | // file unchanged |
26 | return 0; |
27 | } |
28 | // reload the library |
29 | if (dl->handle) { |
30 | dlclose(dl->handle); |
31 | dl->inode = 0; |
32 | } |
33 | dl->handle = dlopen(libfname, RTLD_NOW); |
34 | if (dl->handle == NULL) { |
35 | // warnx("dlopen: %s", dlerror()); |
36 | return 0; |
37 | } |
38 | dl->tune = dlsym(dl->handle, "TUNE"); |
39 | if (dl->tune == NULL) { |
40 | warn("dlsym"); |
41 | dlclose(dl->handle); |
42 | return 0; |
43 | } |
44 | dl->inode = st.st_ino; |
45 | if (dl->tune->reload) { |
46 | dl->tune->reload(dl->tune); |
47 | } |
48 | return 0; |
49 | } |
50 | |
51 | int main(int argc, char *argv[]) |
52 | { |
53 | struct tune_dl dl = {0}; |
54 | const char *fname = "./tune.so"; |
55 | if (tune_dl_load(&dl, fname) < 0) { |
56 | return 1; |
57 | } |
58 | if (dl.tune->init) { |
59 | dl.tune->init(dl.tune); |
60 | } |
61 | int t = 0; |
62 | while (1) { |
63 | (void) tune_dl_load(&dl, fname); |
64 | if (dl.handle && dl.tune->play) { |
65 | double sample = dl.tune->play(dl.tune, t); |
66 | printf("%d %f\n", t, sample); |
67 | } |
68 | (void) tune_dl_load(&dl, fname); |
69 | usleep(100000); |
70 | t++; |
71 | } |
72 | if (dl.tune->deinit) { |
73 | dl.tune->deinit(dl.tune); |
74 | } |
75 | } |
76 |
Built with git-ssb-web