diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-09 23:12:12 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-09-09 23:12:12 +0200 |
commit | 1ff3dbd45f6851bb0e7b39361a5c9a6ef2f4eff4 (patch) | |
tree | fd2e01b7b4959348fcffebe72843b3633c633a0c | |
parent | 143f701925167628150cbf4614ee5bd6803e539c (diff) | |
download | digitale-debutanten-1ff3dbd45f6851bb0e7b39361a5c9a6ef2f4eff4.tar.gz |
added Scale UGen allowing to a signal from source (in) to target (out) range
patch is very simple but the calculations are not; with scale the target range can be explicit in the code
-rw-r--r-- | lib.ck | 7 | ||||
-rw-r--r-- | lib/Scale.ck | 53 |
2 files changed, 58 insertions, 2 deletions
@@ -1,12 +1,15 @@ /* Includes */ Machine.add("lib/LiSaX.ck"); Machine.add("lib/SampOsc.ck"); -Machine.add("lib/ClipperGraph.ck"); -Machine.add("lib/ClipperGen.ck"); +Machine.add("lib/Scale.ck"); Machine.add("lib/Element.ck"); Machine.add("lib/List.ck"); Machine.add("lib/NanoEvent.ck"); +/* platform independant Clipper classes */ +//Machine.add("lib/ClipperGraph.ck"); +//Machine.add("lib/ClipperGen.ck"); + Machine.add("lib/Bus.ck"); Machine.add("lib/Oscope.ck"); diff --git a/lib/Scale.ck b/lib/Scale.ck new file mode 100644 index 0000000..9eeea0a --- /dev/null +++ b/lib/Scale.ck @@ -0,0 +1,53 @@ +/* + * 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 */ + { + (__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(); +} |