Simple ring modulator (silly_effect)
[aftubes.git] / effects.c
blob2ac9edf4ce72f3a655579b991e1f31a55b14eafc
1 #include "effects.h"
2 #include "effect.h"
3 #include "math.h"
4 #include "stdlib.h"
6 struct silly_effect {
7 struct effect e;
8 };
10 int silly_effect_process(struct effect *ef, void **buf, long n_samples)
12 short *bufp;
13 int i;
15 if (!*buf){
16 // we're not a source
17 return 1;
20 bufp = *buf;
21 for (i = 0; i < n_samples; ++i){
22 bufp[i * 2] *= cos((i * 2 * M_PI) / 441.0);
23 bufp[i * 2 + 1] *= cos((i * 2 * M_PI) / 441.0);
25 return 0;
28 static const struct effect_vtab silly_effect_vtab = {
29 process: silly_effect_process,
32 struct effect *silly_effect_create(void)
34 struct silly_effect *se;
35 se = malloc(sizeof *se);
36 if (!se){
37 return NULL;
39 se->e.vtab = &silly_effect_vtab;
40 return &se->e;
43 void silly_effect_free(struct effect *e)
45 free(e);