git ssb

0+

cel / foostudio



Commit 239935fea99de16fbc7d43693de7db919bedb955

Use just a function as the tune API

cel committed on 10/27/2016, 6:16:31 PM
Parent: 24f7eef53f32848b618ed1fba251c37db67ac3f8

Files changed

foostudio.cchanged
tune.cchanged
tune.hchanged
foostudio.cView
@@ -35,9 +35,9 @@
3535 if (argc > 1) src_fname = argv[1];
3636 if (argc > 2) device_out = argv[2];
3737 if (argc > 3) device_in = argv[3];
3838
39- ccdl_init(&ccdl, src_fname, "TUNE");
39 + ccdl_init(&ccdl, src_fname, "play");
4040
4141 if (ccdl_watch(&ccdl)) {
4242 errx(1, "ccdl_watch");
4343 }
@@ -118,14 +118,15 @@
118118 errx(1, "prepare after read failed: %s\n", snd_strerror(err));
119119 continue;
120120 }
121121
122- struct tune *tune = ccdl_get(&ccdl);
123- if (tune && tune->play) {
122 + play_fn *play;
123 + *(void **)(&play) = ccdl_get(&ccdl);
124 + if (play) {
124125 for (size_t i = 0; i < period_size; i++) {
125126 time += step;
126127 float frame_in = i < (unsigned)frames_in ? buffer[i] : 0;
127- buffer[i] = tune->play(&tune_obj, tune, time, frame_in);
128 + buffer[i] = play(tune_obj, time, frame_in);
128129 }
129130 } else {
130131 time += step * period_size;
131132 }
tune.cView
@@ -1,11 +1,7 @@
11 #include <math.h>
22 #include "tune.h"
33
4-static float tune_play(void **obj, struct tune *tune, double time, float in)
4 +float play(void *obj, double time, float in)
55 {
66 return 0.99 * (sin(2. * M_PI * time * 440.) * 0.25 + in * 0.75);
77 }
8-
9-const struct tune TUNE = {
10- .play = tune_play,
11-};
tune.hView
@@ -1,7 +1,5 @@
11 #pragma once
22
3-struct tune {
4- float (*play)(void **obj, struct tune *, double time, float in);
5-};
3 +typedef float play_fn(void *, double time, float in);
64
7-extern const struct tune TUNE;
5 +extern play_fn play;

Built with git-ssb-web