From 9b352d42f4631a515345ed7c4992a736aab1fea2 Mon Sep 17 00:00:00 2001 From: Mick Grierson Date: Mon, 17 Oct 2011 02:01:12 +0100 Subject: added maxiEnv - easier to use ADSR and AR envelopes for those who find ramps a bit weird --- maximilian.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 4 deletions(-) (limited to 'maximilian.cpp') diff --git a/maximilian.cpp b/maximilian.cpp index 1b93489..f2ef3db 100644 --- a/maximilian.cpp +++ b/maximilian.cpp @@ -842,11 +842,11 @@ double maxiDyn::compress(double input, double ratio, double threshold) { } /*reasonably happy with this. input is the input signal to gate, threshold is the threshold of the gate (default 0.9), - hold is how long you want to hold after the attack finishes (default 1 sample). The envelopes are old school digital. + holdtime is how long you want to hold after the attack finishes (default 1 sample). The envelopes are old school digital. An attack of 1 is instant (default). An attack of 0.0015 is a few hundred ms. Likewise, a release of 0. is instant and a release of 0.9995 (default) is a few hundred ms. When I can be arsed I'll work out what this ends up as in seconds and do the conversion. I may never be arsed. It seems a waste. */ -double maxiDyn::gate(double input, double threshold, long hold, double attack, double release) { +double maxiDyn::gate(double input, double threshold, long holdtime, double attack, double release) { if (fabs(input)>threshold && attackphase!=1){ holdcount=0; @@ -865,12 +865,12 @@ double maxiDyn::gate(double input, double threshold, long hold, double attack, d holdphase=1; } - if (holdcount=1) { + amplitude=1; + attackphase=0; + holdphase=1; + } + + if (holdcount0.) { + output=input*(amplitude*=release); + + } + + return output; +} + +double maxiEnv::adsr(double input, double attack, double decay, double sustain, double release, long holdtime, int trigger) { + + if (trigger==1 && attackphase!=1 && holdphase!=1 && decayphase!=1){ + holdcount=0; + decayphase=0; + sustainphase=0; + releasephase=0; + attackphase=1; + } + + if (attackphase==1) { + amplitude+=(1*attack); + output=input*amplitude; + } + + if (amplitude>=1) { + amplitude=1; + attackphase=0; + decayphase=1; + } + + if (decayphase==1) { + output=input*(amplitude*=decay); + if (amplitude<=sustain) { + decayphase=0; + holdphase=1; + } + } + + if (holdcount0.) { + output=input*(amplitude*=release); + + } + + return output; +} \ No newline at end of file -- cgit v1.3