aboutsummaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2017-04-30 19:36:14 +0200
committerDavid Runge <dave@sleepmap.de>2017-04-30 19:36:14 +0200
commitdf13df2257f98d98fa200a32fac94c043254e19f (patch)
tree1739af7b24777e1fa9534dc802196ec0accba785 /classes
downloadzzz-df13df2257f98d98fa200a32fac94c043254e19f.tar.gz
zzz-df13df2257f98d98fa200a32fac94c043254e19f.tar.bz2
zzz-df13df2257f98d98fa200a32fac94c043254e19f.tar.xz
zzz-df13df2257f98d98fa200a32fac94c043254e19f.zip
classes/ZZZ.sc: Adding first version of base class for Expert Sleepers devices. The class functions ampToVAC and vacToAmp have been tested using a RME Babyface and the implemented ZZZHold SynthDef. Above an amplitude of 1.0 the output turns out to be logarithmic (ln), instead of linear, so anywhere above that should be used with caution, as the implemented calculation functions are only an approximation in that region.
Diffstat (limited to 'classes')
-rw-r--r--classes/ZZZ.sc84
1 files changed, 84 insertions, 0 deletions
diff --git a/classes/ZZZ.sc b/classes/ZZZ.sc
new file mode 100644
index 0000000..a71b1c1
--- /dev/null
+++ b/classes/ZZZ.sc
@@ -0,0 +1,84 @@
+ZZZ{
+
+ classvar <cvMinLFO = -2.5,
+ < cvMaxLFO = 2.5,
+ < cvMinADSR = 0.0,
+ < cvMaxADSR = 8.0,
+ < cvMinTriggerGateClock = 0.0,
+ < cvMaxTriggerGateClock = 5.0,
+ < ampToVACConst = 6.8925,
+ < zzzSynth;
+ var <channels;
+
+ *new{
+ arg channels;
+ ^super.newCopyArgs(channels).init;
+ }
+
+ init{
+ ("Using the following channels:").postln;
+ channels.postln;
+ }
+
+ *initClass{
+ StartUp.add{
+ //adding synth for percussive environments (trigger, gate, clock)
+ SynthDef(\ZZZPerc, { |out = 0, freq = 20000, amp = 0.0, attack = 0.001, release = 1, time = 1, curve = -4|
+ var signal, envelope;
+ envelope = EnvGen.kr(Env.perc(attack, release, amp, curve), doneAction: 2);
+ signal = SinOsc.ar(freq, 0, envelope);
+ Out.ar(out, signal);
+ }).add;
+ // adding synth for note environments (adsr, v/o)
+ SynthDef(\ZZZHold, { |out = 0, freq = 20000, amp = 0.0|
+ var signal;
+ signal = SinOsc.ar(freq, 0, amp);
+ Out.ar(out, signal);
+ }).add;
+ }
+ }
+
+ /**
+ * Calculates voltage for supplied amplitude.
+ * Linear until ampToVACConst, exponential above.
+ * Maximum voltage: 7.68096 VAC
+ * @return voltage that corresponds to the amplitude supplied.
+ */
+ *ampToVAC{
+ arg amplitude;
+ var voltage;
+ if((amplitude <= 1.0), {
+ voltage = amplitude * ampToVACConst;
+ },{
+ if((amplitude > 2.2), {
+ voltage = 2.2.log + ampToVACConst;
+ },{
+ voltage = amplitude.log + ampToVACConst;
+ });
+ });
+ voltage.postln;
+ ^voltage;
+ }
+
+ /**
+ * Calculates amplitude for supplied voltage.
+ * Linear until ampToVACConst.
+ * Maximum amplitude output: 2.2
+ * @return amplitude needed to achieve the voltage supplied.
+ */
+ *vacToAmp{
+ arg voltage;
+ var amplitude;
+ if((voltage <= ampToVACConst), {
+ amplitude = voltage/ampToVACConst;
+ },{
+ amplitude = (voltage-ampToVACConst).exp;
+ if(amplitude > 2.2, {
+ amplitude = 2.2;
+ });
+ });
+ amplitude.postln;
+ ^amplitude;
+ }
+
+}