-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpbrk.c
executable file
·73 lines (59 loc) · 1.54 KB
/
expbrk.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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/**
* expbrk.c
* generate exponential attack or decay breakpoint data
*/
int main(int argc, char** argv)
{
int i, npoints;
double startval, endval;
double dur, step, start, end, currentstep;
double fac, valrange, offset;
const double verysmall = 1.0e-4; // ~-80dB. NB: this affects slope
if (argc != 5) {
fprintf(stderr, "Usage: expbrk duration npoints startval endval\n");
return 1;
}
dur = atof(argv[1]);
if (dur <= 0.0) {
fprintf(stderr, "Error: duration must be positive.\n");
return 1;
}
npoints = atoi(argv[2]);
if (npoints <= 0) {
fprintf(stderr, "Error: npoints must be positive!\n");
return 1;
}
step = dur/npoints;
startval = atof(argv[3]);
endval = atof(argv[4]);
valrange = endval - startval;
if (valrange == 0.0) {
fprintf(stderr, "Warning: start and end values are the same!\n");
}
// initialize normalized exponential as attack or decay
if (startval > endval) {
start = 1.0;
end = verysmall;
valrange = -valrange;
offset = endval;
} else {
start = verysmall;
end = 1.0;
offset = startval;
}
currentstep = 0.0;
// make normalized curve, scale output to input values and range
fac = pow(end/start, 1.0/npoints);
for (i = 0; i < npoints; i++) {
fprintf(stdout, "%.4lf\t%.8lf\n", currentstep, offset + (start * valrange));
start *= fac;
currentstep += step;
}
// print final value
fprintf(stdout, "%.4lf\t%.8lf\n", currentstep,offset + (start * valrange));
fprintf(stderr, "done\n");
return 0;
}