-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tables.pde
39 lines (30 loc) · 834 Bytes
/
Tables.pde
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
float [] _tableLinearTodB;
float [] _tableExp8;
float [] _tableExp8MapTo255;
int TABLE_SIZE = 256;
void initTables() {
initLinearTodB();
}
void initLinearTodB() {
_tableLinearTodB = new float[TABLE_SIZE];
_tableExp8 = new float[TABLE_SIZE];
_tableExp8MapTo255 = new float[TABLE_SIZE];
_tableLinearTodB[0] = -144.0;
for(int i=1; i<TABLE_SIZE; i++) {
float vi = i/float(TABLE_SIZE);
_tableLinearTodB[i] = (float)(20 * Math.log10(vi));
_tableExp8[i] = mapCurve(vi,8);
}
}
float cvLinearTodB(float v) {
v = constrain(v,0,1);
return _tableLinearTodB[int(v * (TABLE_SIZE-1))];
}
float cvLinearToExp8(float v) {
v = constrain(v,0,1);
return _tableExp8[int(v*(TABLE_SIZE-1))];
}
float cvLinearToExp8255(float v) {
v = constrain(v,0,1);
return _tableExp8MapTo255[int(v*(TABLE_SIZE-1))];
}