-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdtrig.c
52 lines (48 loc) · 1.03 KB
/
dtrig.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdlib.h>
#include "soundpipe.h"
int sp_dtrig_create(sp_dtrig **p)
{
*p = malloc(sizeof(sp_dtrig));
return SP_OK;
}
int sp_dtrig_destroy(sp_dtrig **p)
{
free(*p);
return SP_OK;
}
int sp_dtrig_init(sp_data *sp, sp_dtrig *p, sp_ftbl *ft)
{
p->ft = ft;
p->counter = 0;
p->pos = 0;
p->running = 0;
p->loop = 0;
p->delay = 0;
p->scale = 1;
return SP_OK;
}
int sp_dtrig_compute(sp_data *sp, sp_dtrig *p, SPFLOAT *in, SPFLOAT *out)
{
if(*in == 1.0){
p->running = 1.0;
p->pos = 0;
p->counter = p->delay * sp->sr;
}
if((p->pos < p->ft->size) && p->running){
if(p->counter == 0){
p->counter = (uint32_t)(p->scale * p->ft->tbl[p->pos] * sp->sr - 1);
*out = 1.0;
p->pos++;
if(p->loop){
p->pos %= p->ft->size;
}
return SP_OK;
}else{
*out = 0;
p->counter--;
return SP_OK;
}
}
*out = 0;
return SP_NOT_OK;
}