aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmain.cpp17
-rw-r--r--maximilian.cpp59
-rwxr-xr-xmaximilian.h3
3 files changed, 52 insertions, 27 deletions
diff --git a/main.cpp b/main.cpp
index 7529e56..7cece7b 100755
--- a/main.cpp
+++ b/main.cpp
@@ -1,7 +1,7 @@
#include "maximilian.h"
-maxiSample beats;//We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names.
-maxiDyn compress;
+maxiSample beats; //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names.
+maxiDyn compressor;
double out;
void setup() {//some inits
@@ -13,11 +13,16 @@ void setup() {//some inits
void play(double *output) {//this is where the magic happens. Very slow magic.
- out=compress.gate(beats.play(),0.3,5000,0.03,0.9999);//just play the file. Looping is default for all play functions.
+ out=compressor.compressor(beats.play(),1,0.02,0.0005,0.9995);//just play the file. Looping is default for all play functions.
+
+
+ output[0]=out;
+ output[1]=out;
+
+ // *output=beats.play(0.69);//play the file with a speed setting. 1. is normal speed.
+ // *output=beats.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing.
+ // *output=beats.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing.
- output[0]=out;
- output[1]=out;
-
}
diff --git a/maximilian.cpp b/maximilian.cpp
index f8e9b01..ccf4e5f 100644
--- a/maximilian.cpp
+++ b/maximilian.cpp
@@ -831,26 +831,8 @@ void maxiSample::getLength() {
length=myDataSize*0.5;
}
-/* This is a basic compressor. don't use it until the enveloping is finished */
-double maxiDyn::compress(double input, double ratio, double threshold) {
-
- if (fabs(input)>threshold) {
- if (input>0.) {
- output = 1-threshold+(((input-threshold)/ratio)+threshold);
- } else {
- output = 1-threshold+(((input+threshold)/ratio)-threshold);
- }
-
- }
-
- else {
- output=input+(1-threshold);
- }
- return output;
-}
-
-/* ok this isn't quite ready */
+/* working */
double maxiDyn::gate(double input, double threshold, long holdtime, double attack, double release) {
if (fabs(input)>threshold && attackphase!=1){
@@ -888,7 +870,44 @@ double maxiDyn::gate(double input, double threshold, long holdtime, double attac
return output;
}
-/* Lots of people struggle with the envelope generators so here's a new easy one. It takes mental numbers for attack and release tho */
+/* this is evil. leave it alone*/
+
+double maxiDyn::compressor(double input, double ratio, double threshold, double attack, double release) {
+
+ if (fabs(input)>threshold && attackphase!=1){
+ holdcount=0;
+ releasephase=0;
+ attackphase=1;
+ if(currentRatio==0) currentRatio=0.01;
+ }
+
+ if (attackphase==1 && currentRatio<ratio-1) {
+ currentRatio*=(1+attack);
+ }
+
+ if (currentRatio>=ratio-1) {
+ attackphase=0;
+ releasephase=1;
+ }
+
+ if (releasephase==1 && currentRatio>0.) {
+ currentRatio*=release;
+
+ }
+
+ if (input>0.) {
+ output = ((input-threshold)/1.+currentRatio)+threshold;
+ } else {
+ output = ((input+threshold)/1.+currentRatio)-threshold;
+ }
+
+ return output;
+}
+
+
+/* Lots of people struggle with the envelope generators so here's a new easy one.
+ It takes mental numbers for attack and release tho. Basically, they're exponentials.
+ I'll map them out later so that it's a bit more intuitive */
double maxiEnv::ar(double input, double attack, double release, long holdtime, int trigger) {
if (trigger==1 && attackphase!=1 && holdphase!=1){
diff --git a/maximilian.h b/maximilian.h
index cb1bebb..88b4843 100755
--- a/maximilian.h
+++ b/maximilian.h
@@ -320,9 +320,10 @@ class maxiDyn {
public:
double gate(double input, double threshold=0.9, long holdtime=1, double attack=1, double release=0.9995);
- double compress(double input, double ratio=2.0, double threshold=0.5);
+ double compressor(double input, double ratio, double threshold=0.9, double attack=1, double release=0.9995);
double input;
double ratio;
+ double currentRatio;
double threshold;
double output;
double attack;