aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMick Grierson <mickgrierson@strangebook.lan>2011-10-16 23:00:42 +0100
committerMick Grierson <mickgrierson@strangebook.lan>2011-10-16 23:00:42 +0100
commit3a90e8344192e60f65cf9a1fe821bb080a323d34 (patch)
treed308cb6594bd52dbed03750c166d1aa9ebd61ccf
parent86eb05f4c39f7fde510cde682a529a2436a45955 (diff)
added maxiDyn compressor and gate
-rwxr-xr-xmain.cpp31
-rw-r--r--maximilian.cpp62
-rwxr-xr-xmaximilian.h18
3 files changed, 95 insertions, 16 deletions
diff --git a/main.cpp b/main.cpp
index ff2122d..70803aa 100755
--- a/main.cpp
+++ b/main.cpp
@@ -1,27 +1,26 @@
#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 compressor;
+double beat;
-maxiOsc timer;//this is the metronome
-int currentCount,lastCount,blob;//these values are used to check if we have a new beat this sample
void setup() {//some inits
- //nothing to go here this time
- blob=0;
+ beats.load("/Users/mickgrierson/Documents/audio/59210__suonho__abstract_electrofunkbreakbeats_124bpm_mono.wav");//load in your samples. Provide the full path to a wav file.
+ printf("Summary:\n%s", beats.getSummary());//get info on samples if you like.
+
}
-void play(double *output) {
+void play(double *output) {//this is where the magic happens. Very slow magic.
+ beat=beats.play();//just play the file. Looping is default for all play functions.
+ *output=compressor.compress(beat,100,0.01)*10;//OMG an evil compressor
+
+ // *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.
- currentCount=(int)timer.phasor(1000);//this sets up a metronome that ticks every 2 seconds
- if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
-
- cout << "tick\n";//the clock ticks
- blob++;
- cout << blob;
- cout << "\n";
- lastCount=0;//set lastCount to 0
- }
-
-} \ No newline at end of file
+}
+
diff --git a/maximilian.cpp b/maximilian.cpp
index 0c016b1..1b93489 100644
--- a/maximilian.cpp
+++ b/maximilian.cpp
@@ -820,4 +820,66 @@ void maxiSample::getLength() {
length=myDataSize*0.5;
}
+/* This is a basic compressor. Can also do expansion. It takes standard args for ratio and threshold
+ although threshold is in linear amplitude at the moment. It has some crotchety old excuse for gain compensation
+ which will do for now, but if you do choose to use it for expansion, watch out as it will bite you in the bum*/
+
+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;
+}
+
+/*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.
+ 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) {
+
+ if (fabs(input)>threshold && attackphase!=1){
+ holdcount=0;
+ releasephase=0;
+ attackphase=1;
+ amplitude=0;
+ }
+
+ if (attackphase==1 && amplitude<1) {
+ amplitude+=(1*attack);
+ output=input*amplitude;
+ }
+
+ if (amplitude>=1) {
+ attackphase=0;
+ holdphase=1;
+ }
+
+ if (holdcount<hold && holdphase==1) {
+ output=input;
+ holdcount++;
+ }
+
+ if (holdcount==hold) {
+ holdphase=0;
+ releasephase=1;
+ }
+
+ if (releasephase==1 && amplitude>0.) {
+ output=input*(amplitude*=release);
+
+ }
+
+ return output;
+}
diff --git a/maximilian.h b/maximilian.h
index 41df487..38ac3dc 100755
--- a/maximilian.h
+++ b/maximilian.h
@@ -314,4 +314,22 @@ public:
};
+class maxiDyn {
+
+
+public:
+ double gate(double input, double threshold=0.9, long hold=1, double attack=1, double release=0.9995);
+ double compress(double input, double ratio=2.0, double threshold=0.5);
+ double input;
+ double ratio;
+ double threshold;
+ double output;
+ long attack;
+ long release;
+ double amplitude;
+ long hold;
+ long holdcount;
+ int attackphase,holdphase,releasephase;
+};
+
#endif