-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslice.c
46 lines (40 loc) · 885 Bytes
/
slice.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
#include <stdlib.h>
#include "soundpipe.h"
int sp_slice_create(sp_slice **p)
{
*p = malloc(sizeof(sp_slice));
return SP_OK;
}
int sp_slice_destroy(sp_slice **p)
{
free(*p);
return SP_OK;
}
int sp_slice_init(sp_data *sp, sp_slice *p, sp_ftbl *vals, sp_ftbl *buf)
{
p->vals = vals;
p->buf = buf;
p->pos = 0;
p->nextpos = 0;
p->id = 0;
return SP_OK;
}
int sp_slice_compute(sp_data *sp, sp_slice *p, SPFLOAT *in, SPFLOAT *out)
{
*out = 0;
if(*in != 0) {
if(p->id < p->vals->size) {
p->pos = p->vals->tbl[p->id];
if(p->id == p->vals->size - 1) {
p->nextpos = p->buf->size;
} else {
p->nextpos = p->vals->tbl[p->id + 1];
}
}
}
if(p->pos < p->nextpos) {
*out = p->buf->tbl[p->pos];
p->pos++;
}
return SP_OK;
}