blob: c6b1a246105fefce4ce72537ffec6b90649fcc80 (
plain)
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
|
/*
* Scale input samples in configurable range to configurable output range
*/
public class Scale extends Chubgraph {
inlet => outlet;
Step __base => outlet; /* pseudo-private */
-1 => float __in_from; /* pseudo-private */
1 => float __in_to; /* pseudo-private */
-1 => float __out_from; /* pseudo-private */
1 => float __out_to; /* pseudo-private */
fun void
__update() /* pseudo-private */
{
/*
* Note that "__out_from" can be greater than "__out_to", resulting in the
* desired inversion of scaling
* (just like __out_from < __out_to and -SAMPLE was used).
*/
(__out_to-__out_from)/(__in_to-__in_from) => inlet.gain;
__out_from - __in_from*inlet.gain() => __base.next;
}
fun float
in(float from, float to)
{
from => __in_from;
to => __in_to;
__update();
return to;
}
fun float
in(float to)
{
return in(0, to);
}
fun float
out(float from, float to)
{
from => __out_from;
to => __out_to;
__update();
return to;
}
fun float
out(float to)
{
return out(0, to);
}
/* not strictly necessary with current default values */
__update();
}
|