-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpon.c
76 lines (67 loc) · 1.36 KB
/
expon.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Expon
*
* This code has been extracted from the Csound opcode "expon".
* It has been modified to work as a Soundpipe module.
*
* Original Author(s): Barry Vercoe
* Year: 1991
* Location: OOps/ugens1.c
*
*/
#include <math.h>
#include <stdlib.h>
#include "soundpipe.h"
int sp_expon_create(sp_expon **p)
{
*p = malloc(sizeof(sp_expon));
return SP_OK;
}
int sp_expon_destroy(sp_expon **p)
{
free(*p);
return SP_OK;
}
static void expon_reinit(sp_data *sp, sp_expon *p)
{
p->stime = 0;
p->sdur = p->dur * sp->sr;
SPFLOAT onedsr = 1.0 / sp->sr;
if((p->a * p->b) > 0.0) {
p->incr = pow((SPFLOAT)(p->b / p->a), onedsr / p->dur);
} else {
fprintf(stderr, "Warning: p values must be non-zero\n");
p->incr = 1;
p->val = p->a;
}
p->val = p->a;
}
int sp_expon_init(sp_data *sp, sp_expon *p)
{
p->a = 0.000001;
p->b = 1;
p->dur = 1;
expon_reinit(sp, p);
p->init = 1;
return SP_OK;
}
int sp_expon_compute(sp_data *sp, sp_expon *p, SPFLOAT *in, SPFLOAT *out)
{
if(*in) {
expon_reinit(sp, p);
p->init = 0;
}
if(p->init) {
*out = 0;
return SP_OK;
}
if(p->stime < p->sdur) {
SPFLOAT val = p->val;
p->val *= p->incr;
p->stime++;
*out = val;
} else {
*out = p->b;
}
return SP_OK;
}