diff options
author | David Runge <dave@sleepmap.de> | 2017-05-04 21:35:40 +0200 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2017-05-04 21:35:40 +0200 |
commit | bce26739a1ad2bc2d242e8c8e3672f10d1a95085 (patch) | |
tree | 5f11940ca9bcb85dc98a28e1f8d5e0e34100c6f2 /classes | |
parent | 1adb6394c57d55290d76c1d6eb039a478059db99 (diff) | |
download | zzz-bce26739a1ad2bc2d242e8c8e3672f10d1a95085.tar.gz zzz-bce26739a1ad2bc2d242e8c8e3672f10d1a95085.tar.bz2 zzz-bce26739a1ad2bc2d242e8c8e3672f10d1a95085.tar.xz zzz-bce26739a1ad2bc2d242e8c8e3672f10d1a95085.zip |
classes/ZZZ.sc: Adding new SynthDef for clock and constant voltages. Rewriting all helper class functions to work properly with DC current. Removing unused init function. Removing unused stupid class constant.
Diffstat (limited to 'classes')
-rw-r--r-- | classes/ZZZ.sc | 133 |
1 files changed, 76 insertions, 57 deletions
diff --git a/classes/ZZZ.sc b/classes/ZZZ.sc index 65b18c1..662da36 100644 --- a/classes/ZZZ.sc +++ b/classes/ZZZ.sc @@ -6,111 +6,130 @@ ZZZ{ < cvMaxADSR = 8.0, < cvMinTriggerGateClock = 0.0, < cvMaxTriggerGateClock = 5.0, - < ampToVACConst = 6.8925; + < noteVoltageRangeMin = -5.0, + < noteVoltageRangeMax = 7.0, + < noteCpsRangeMin = 4.088, + < noteCpsRangeMax = 16744.036; var <channels; *new{ arg channels; - ^super.newCopyArgs(channels).init; - } - - init{ - ("Using the following channels:").postln; - channels.postln; + ^super.newCopyArgs(channels); } *initClass{ StartUp.add{ - //adding synth for percussive environments (trigger, gate, clock) + // adding SynthDef for clock + SynthDef(\ZZZClock, { |out = 0, freq = 2, iphase = 0, width = 0.1, mul= 1.0| + Out.ar(out, LFPulse.ar(freq, iphase, width, mul)); + }).add; + // adding SynthDef for constant notes + SynthDef(\ZZZConstant, { |out = 0, mul= 0.0| + Out.ar( + out, + Lag.ar( + LFPulse.ar( + 500, + 0, + 1), + 0.1, + mul + ) + ); + }).add; + //adding synth for percussive environments (trigger, gate) 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 + * Maximum: 10 + * Minimum: -10 * @return voltage that corresponds to the amplitude supplied. */ - *ampToVAC{ + *amplitudevoltage{ arg amplitude; - var voltage; - if((amplitude <= 1.0), { - voltage = amplitude * ampToVACConst; + var voltage = 0.0; + if((amplitude == 0.0), { + ^voltage; },{ - voltage = amplitude.lincurve(1.0, 2.5, ampToVACConst, 7.7, -4, nil); + voltage = amplitude*10.0; + if(voltage < -10.0, { + ^(-10.0); + }); + if(voltage > 10.0, { + ^(10.0); + }); + ^voltage; }); - ^voltage; } /** * Calculates amplitude for supplied voltage. - * Linear until ampToVACConst. - * Maximum amplitude output: 2.2 + * Maximum: 1.0 + * Minimum: -1.0 * @return amplitude needed to achieve the voltage supplied. */ - *vacToAmp{ + *voltageamplitude{ arg voltage; - var amplitude; - if((voltage <= ampToVACConst), { - amplitude = voltage/ampToVACConst; + var amplitude = 0.0; + if((voltage == 0.0), { + ^amplitude; },{ - amplitude = voltage.curvelin(ampToVACConst, 7.7, 1.0, 2.5, -4, \max); + amplitude = voltage/10.0; + if(amplitude < -1.0, { + ^(-1.0); + }); + if(amplitude > 1.0, { + ^(1.0); + }); + ^amplitude; }); - ^amplitude; } /** - * Calculates voltage for supplied frequency. - * Frequencies below 27.5Hz will return 0. - * @return voltage for corresponding frequency + * Calculates voltage for supplied cycles per second. + * @return voltage for corresponding cycles per second */ - *hzToVAC{ - arg frequency; - var voltage; - if(frequency < 27.5, { - voltage = 0; - },{ - voltage = frequency.explin(55, 880, 1.0, 5.0, nil); + *cpsvoltage{ + arg cps; + if(cps < noteCpsRangeMin, { + cps = noteCpsRangeMin; + }); + if(cps > noteCpsRangeMax, { + cps = noteCpsRangeMax; }); - ^voltage; + ^cps.explin(noteCpsRangeMin, noteCpsRangeMax, noteVoltageRangeMin, noteVoltageRangeMax); } /** - * Calculates frequency for supplied voltage. - * Voltages below 0 will return 27.5Hz - * @return frequency for corresponding voltage + * Calculates cycles per second for supplied voltage. + * @return cycles per second for corresponding voltage */ - *vacToHz{ + *voltagecps{ arg voltage; - var frequency; - if(voltage < 0, { - frequency = 27.5; - },{ - frequency = voltage.linexp(1.0, 5.0, 55, 880, nil); + if(voltage < noteVoltageRangeMin, { + voltage = noteVoltageRangeMin; + }); + if(voltage > noteVoltageRangeMax, { + voltage = noteVoltageRangeMax; }); - ^frequency; + ^voltage.linexp(noteVoltageRangeMin, noteVoltageRangeMax, noteCpsRangeMin, noteCpsRangeMax); } /** * Calculates amplitude for supplied frequency. - * Wraps call to hzToVAC -> vacToAmp * @return amplitude for corresponding frequency */ - *hzToAmp{ - arg frequency; - ^this.vacToAmp(this.hzToVAC(frequency)); + *cpsamp{ + arg cps; + ^this.voltageamplitude(this.cpsvoltage(cps)); } /** @@ -118,8 +137,8 @@ ZZZ{ * Wraps call to ampToVAC -> vacToHz * @return frequency for corresponding amplitude */ - *ampToHz{ + *ampcps{ arg amplitude; - ^this.vacToHz(this.ampToVAC(amplitude)); + ^this.voltagecps(this.amplitudevoltage(amplitude)); } } |