diff options
| author | mick grierson <mickgrierson@gmail.com> | 2016-12-19 22:56:37 +0000 |
|---|---|---|
| committer | mick grierson <mickgrierson@gmail.com> | 2016-12-19 22:56:37 +0000 |
| commit | 85d3fe3233cee889a9c2593d48ba1dea12d4a7a8 (patch) | |
| tree | 73376d3e055d95b26e0b87afcce83f9b0894f789 | |
| parent | cfb9046eec768c76baa4c0711870bb255c86ef4a (diff) | |
refactored, tested, bugfixed the new javascript samplerate-based envelopes. Should be good now...
| -rwxr-xr-x | main.cpp | 100 | ||||
| -rw-r--r-- | maximilian.cpp | 43 | ||||
| -rwxr-xr-x | maximilian.h | 6 |
3 files changed, 74 insertions, 75 deletions
@@ -1,90 +1,88 @@ -#include "maximilian.h" - -maxiOsc myOsc; -maxiEnvelope myEnv; -int counter; -double vals[12]={1,0.1,0.5,0.0,1.5,0.0,0.1,1,1.0,0.15,1.0,0.1}; -std::vector<double> rampsA(vals, vals+12); - - -void setup() {//some inits - - myEnv.note(true); - -} - -void play(double *output) {//this is where the magic happens. Very slow magic. - - counter++; - - if (counter ==0 || counter % 330400==0) { - myEnv.note(true); - } - - - double out = myEnv.ramps(rampsA); - - output[0]=myOsc.sinewave(440)*out; - - output[1]=output[0]; -} - - //#include "maximilian.h" // //maxiOsc myOsc; //maxiEnvelope myEnv; //int counter; +//double vals[12]={1,0.1,0.5,0.0,1.5,0.0,0.1,1,1.0,0.15,1.0,0.1}; +//std::vector<double> rampsA(vals, vals+12); +// +// +//void setup() {//some inits +// +// myEnv.trigger(true); // -//void setup() { -// cout << myEnv.trigger << endl; //} // -//void play(double *output) { +//void play(double *output) {//this is where the magic happens. Very slow magic. // +// counter++; // -// if (counter ==0 || counter % 88201==0) { -// myEnv.note(true); +// if (counter ==0 || counter % 330400==0) { +// myEnv.trigger(true); // } // -// if (counter % 44100==0) { -// myEnv.note(false); -// } // -// counter++; +// double out = myEnv.ramps(rampsA); // -// double out = myEnv.adsr(); -// // output[0]=myOsc.sinewave(440)*out; -// +// // output[1]=output[0]; -// //} + //#include "maximilian.h" // //maxiOsc myOsc; //maxiEnvelope myEnv; -//int counter; +//int counter=0; // //void setup() { -// cout << myEnv.trigger << endl; //} // //void play(double *output) { // // -// if (counter ==0 || counter % 88200==0) { -// myEnv.note(true); +// if (counter ==0 || counter % 17640==0) { +// myEnv.trigger(true); // } // +// if (counter % 8821==0) { +// myEnv.trigger(false); +// } // // counter++; // -// double out = myEnv.ar(1,1); -// +// double out = myEnv.adsr(0.1,0.2,0.1,3); +// // output[0]=myOsc.sinewave(440)*out; // // output[1]=output[0]; // //} + +#include "maximilian.h" + +maxiOsc myOsc; +maxiEnvelope myEnv; +int counter; + +void setup() { +} + +void play(double *output) { + + + if (counter ==0 || counter % 8820==0) { + myEnv.trigger(true); + } + + + counter++; + + double out = myEnv.ar(0.01,1); + + output[0]=myOsc.sinewave(440)*out; + + output[1]=output[0]; + +} diff --git a/maximilian.cpp b/maximilian.cpp index 5609aad..0d9bcfd 100644 --- a/maximilian.cpp +++ b/maximilian.cpp @@ -393,27 +393,27 @@ double maxiEnvelope::line(int numberofsegments,double segments[1000]) { return(output); } -//and this -//void maxiEnvelope::trigger(int index, double amp) { -// isPlaying=1;//ok the envelope is being used now. -// valindex=index; -// amplitude=amp; -// -//} +//and this is also deprecated +void maxiEnvelope::trigger(int index, double amp) { + isPlaying=1;//ok the envelope is being used now. + valindex=index; + amplitude=amp; + +} -void maxiEnvelope::note(bool noteOn) { +void maxiEnvelope::trigger(bool noteOn) { - if (noteOn) trigger=1; - if (noteOn==false) trigger=0; + if (noteOn) trig=1; + if (noteOn==false) trig=0; } double maxiEnvelope::ramp(double startVal, double endVal, double duration){ - if (trigger!=0) { + if (trig!=0) { phase=startVal; isPlaying=true; - trigger=0; + trig=0; } if (isPlaying) { @@ -440,11 +440,11 @@ double maxiEnvelope::ramp(double startVal, double endVal, double duration){ double maxiEnvelope::ramps(std::vector<double> rampsArray){ - if (trigger!=0) { + if (trig!=0) { valindex=0; endVal=rampsArray[valindex+1]; isPlaying=true; - trigger=0; + trig=0; } @@ -513,10 +513,10 @@ double maxiEnvelope::ramps(std::vector<double> rampsArray){ double maxiEnvelope::ar(double attack, double release) { - if (trigger!=0) { - phase=0; + if (trig!=0) { + //phase=0; releaseMode=false; - trigger=0; + trig=0; } if (phase<1 && releaseMode==false) { @@ -538,12 +538,13 @@ double maxiEnvelope::ar(double attack, double release) { double maxiEnvelope::adsr(double attack, double decay, double sustain, double release) { - if (trigger!=0 && !attackMode && !decayMode && !sustainMode && !releaseMode) { - phase=0.; + if (trig!=0 && !attackMode) { +// phase=0.; releaseMode=false; decayMode=false; sustainMode=false; attackMode=true; + trig=0; } if (attackMode) { @@ -567,11 +568,11 @@ double maxiEnvelope::adsr(double attack, double decay, double sustain, double re if (sustainMode) { - if (trigger!=0) { + if (noteOn) { phase=sustain; } - if (trigger==0) { + if (!noteOn) { sustainMode=false; releaseMode=true; } diff --git a/maximilian.h b/maximilian.h index 54dec4b..2e8593d 100755 --- a/maximilian.h +++ b/maximilian.h @@ -124,14 +124,14 @@ class maxiEnvelope { int isPlaying; public: - int trigger; + int trig; double line(int numberofsegments,double segments[100]); double ramp(double startVal=0, double endVal=1, double duration=1); double ramps(std::vector<double> rampsArray); double ar(double attack=0.1, double release=0.1); double adsr(double attack=0.1, double decay=0.1, double sustain=0.1, double release=0.1); -// void trigger(int index,double amp); - void note(bool noteOn=false); + void trigger(int index,double amp); + void trigger(bool noteOn=false); int valindex; double amplitude; |
