-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathincr.c
45 lines (38 loc) · 783 Bytes
/
incr.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
#include <stdlib.h>
#include "soundpipe.h"
#ifndef max
#define max(a, b) ((a > b) ? a : b)
#endif
#ifndef min
#define min(a, b) ((a < b) ? a : b)
#endif
int sp_incr_create(sp_incr **p)
{
*p = malloc(sizeof(sp_incr));
return SP_OK;
}
int sp_incr_destroy(sp_incr **p)
{
free(*p);
return SP_OK;
}
int sp_incr_init(sp_data *sp, sp_incr *p, SPFLOAT val)
{
p->min = 0;
p->max = 1;
p->step = 0.1;
p->val = val;
return SP_OK;
}
int sp_incr_compute(sp_data *sp, sp_incr *p, SPFLOAT *in, SPFLOAT *out)
{
if(*in > 0 ) {
p->val += p->step;
p->val = max(min(p->val, p->max), p->min);
} else if (*in < 0) {
p->val -= p->step;
p->val = max(min(p->val, p->max), p->min);
}
*out = p->val;
return SP_OK;
}