From bce26739a1ad2bc2d242e8c8e3672f10d1a95085 Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 4 May 2017 21:35:40 +0200 Subject: 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. --- classes/ZZZ.sc | 133 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 76 insertions(+), 57 deletions(-) (limited to 'classes') 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 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)); } } -- cgit v1.2.3-70-g09d2