From b2b6c92bd1dc0a1e1b5f4559378d05e3d4285d57 Mon Sep 17 00:00:00 2001 From: David Runge Date: Mon, 1 May 2017 00:10:18 +0200 Subject: classes/ZZZ.sc: Removing unused classvar zzzSynth. using lincurve and curvelin in ampToVAC and vacToAmp (respectively) for the exponential part. Adding functions to calculate voltage from frequency and frequency from voltage. --- classes/ZZZ.sc | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'classes/ZZZ.sc') diff --git a/classes/ZZZ.sc b/classes/ZZZ.sc index a71b1c1..3f39357 100644 --- a/classes/ZZZ.sc +++ b/classes/ZZZ.sc @@ -6,8 +6,7 @@ ZZZ{ < cvMaxADSR = 8.0, < cvMinTriggerGateClock = 0.0, < cvMaxTriggerGateClock = 5.0, - < ampToVACConst = 6.8925, - < zzzSynth; + < ampToVACConst = 6.8925; var 2.2), { - voltage = 2.2.log + ampToVACConst; - },{ - voltage = amplitude.log + ampToVACConst; - }); + voltage = amplitude.lincurve(1.0, 2.5, ampToVACConst, 7.7, -4, nil); }); voltage.postln; ^voltage; @@ -72,13 +67,44 @@ ZZZ{ if((voltage <= ampToVACConst), { amplitude = voltage/ampToVACConst; },{ - amplitude = (voltage-ampToVACConst).exp; - if(amplitude > 2.2, { - amplitude = 2.2; - }); + amplitude = voltage.curvelin(ampToVACConst, 7.7, 1.0, 2.5, -4, \max); }); amplitude.postln; ^amplitude; } + /** + * Calculates voltage for supplied frequency. + * Frequencies below 27.5Hz will return 0. + * @return voltage for corresponding frequency + */ + *hzToVAC{ + arg frequency; + var voltage; + if(frequency < 27.5, { + voltage = 0; + },{ + voltage = frequency.explin(55, 880, 1.0, 5.0, nil); + }); + voltage.postln; + ^voltage; + } + + /** + * Calculates frequency for supplied voltage. + * Voltages below 0 will return 27.5Hz + * @return frequency for corresponding voltage + */ + *vacToHz{ + arg voltage; + var frequency; + if(voltage < 0, { + frequency = 27.5; + },{ + frequency = voltage.linexp(1.0, 5.0, 55, 880, nil); + }); + frequency.postln; + ^frequency; + } + } -- cgit v1.2.3-70-g09d2