diff options
| author | mick grierson <mickgrierson@gmail.com> | 2016-12-14 02:30:34 +0000 |
|---|---|---|
| committer | mick grierson <mickgrierson@gmail.com> | 2016-12-14 02:30:34 +0000 |
| commit | d60b86693af086e820f2488a4f8db6fe96ed7ece (patch) | |
| tree | 6b9b50a70744706271fc5c417a431137196bc199 | |
| parent | df18758a04f36e74f0fa74a65ee11572015a9aff (diff) | |
refined old envelopes
| -rwxr-xr-x | main.cpp | 18 | ||||
| -rw-r--r-- | maximilian.cpp | 144 | ||||
| -rwxr-xr-x | maximilian.h | 17 | ||||
| -rwxr-xr-x | maximilianTest.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | openFrameworks/ofxMaxim/libs/fft.cpp | 9 | ||||
| -rw-r--r-- | openFrameworks/ofxMaxim/libs/maxiFFT.h | 4 | ||||
| -rw-r--r-- | openFrameworks/openFrameworksExamples/OSX/OF_0.9.0_OSX_XCode7_mySketch_maxim/src/ofApp.cpp | 3 |
7 files changed, 170 insertions, 29 deletions
@@ -1,21 +1,21 @@ #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. +maxiOsc myOsc; +maxiEnvelope myEnv; +int counter; +double tv[8] = {1,1,0,1,1,2,0,4}; void setup() {//some inits - beats.load("/Users/michaelgrierson/Documents/workspace/Maximilian/beat2.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. - cout << beats.getLength(); - } void play(double *output) {//this is where the magic happens. Very slow magic. - //output[0]=beats.play();//just play the file. Looping is default for all play functions. - output[0]=beats.play(0.68);//play the file with a speed setting. 1. is normal speed. - //output[0]=beats.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing. - //output[0]=beats.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing. + + + double out = myEnv.ramps(tv); + + output[0]=myOsc.sinewave(440)*out; output[1]=output[0]; } diff --git a/maximilian.cpp b/maximilian.cpp index 350a258..5bd94bb 100644 --- a/maximilian.cpp +++ b/maximilian.cpp @@ -372,14 +372,14 @@ double maxiEnvelope::line(int numberofsegments,double segments[1000]) { nextval=segments[valindex+2]; currentval=segments[valindex]; if (currentval-amplitude > 0.0000001 && valindex < numberofsegments) { - amplitude += ((currentval-startval)/(maxiSettings::sampleRate/period)); + amplitude += ((currentval-startVal)/(maxiSettings::sampleRate/period)); } else if (currentval-amplitude < -0.0000001 && valindex < numberofsegments) { - amplitude -= (((currentval-startval)*(-1))/(maxiSettings::sampleRate/period)); + amplitude -= (((currentval-startVal)*(-1))/(maxiSettings::sampleRate/period)); } else if (valindex >numberofsegments-1) { valindex=numberofsegments-2; } else { valindex=valindex+2; - startval=currentval; + startVal=currentval; } output=amplitude; @@ -392,13 +392,141 @@ double maxiEnvelope::line(int numberofsegments,double segments[1000]) { } //and this -void maxiEnvelope::trigger(int index, double amp) { - isPlaying=1;//ok the envelope is being used now. - valindex=index; - amplitude=amp; - +//void maxiEnvelope::trigger(int index, double amp) { +// isPlaying=1;//ok the envelope is being used now. +// valindex=index; +// amplitude=amp; +// +//} + +double maxiEnvelope::ramp(double startVal, double endVal, double duration, int trigger1){ + + if (trigger!=0) { + phase=startVal; + trigger=0; + } + + if (startVal<endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./duration))); + if ( phase >= endVal ) phase = endVal; + } + + if (startVal > endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./duration))); + if ( phase <= endVal ) phase = endVal; + } + return(phase); + +} + + +double maxiEnvelope::ramps(double rampsArray[1000], int trigger1){ + + if (trigger!=0) { + valindex=0; + endVal=rampsArray[valindex]; + trigger=0; + + } + + if (phase<endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./rampsArray[valindex+1]))); + if ( phase >= endVal ) { + startVal=phase; + valindex+=2; + endVal=rampsArray[valindex]; + } + } + + if (phase > endVal) { + phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./rampsArray[valindex+1]))); + if ( phase <= endVal ) { + startVal=phase; + valindex+=2; + endVal=rampsArray[valindex]; + } + } + return(phase); + } +double maxiEnvelope::ar(double attack, double release,int trigger1) { + + if (trigger!=0) { + phase=0; + releaseMode=false; + trigger=0; + } + + if (phase<1 && releaseMode==false) { + phase += ((1)/(maxiSettings::sampleRate/(1./attack))); + if ( phase >= 1 ) { + phase=1; + releaseMode=true; + }; + } + + if (releaseMode==true) { + phase += ((-1)/(maxiSettings::sampleRate/(1./release))); + if ( phase <= 0 ) phase = 0; + } + + return phase; +} + + +double maxiEnvelope::adsr(double attack, double decay, double sustain, double release, int trigger1) { + + if (trigger!=0 && !releaseMode && !decayMode && !sustainMode) { + phase=0; + releaseMode=false; + decayMode=false; + sustainMode=false; + attackMode=true; + } + + if (phase<1 && attackMode) { + phase += ((1)/(maxiSettings::sampleRate/(1./attack))); + if ( phase >= 1 ) { + phase=1; + attackMode=false; + decayMode=true; + }; + } + + if (decayMode) { + phase += ((-1)/(maxiSettings::sampleRate/(1./decay))); + if ( phase <= sustain ) { + phase=sustain; + decayMode=false; + sustainMode=true; + }; + } + + if (sustainMode) { + + if (trigger!=0) { + phase=sustain; + } + + if (trigger==0) { + sustainMode=false; + releaseMode=true; + } + } + + if (releaseMode) { + phase += ((-sustain)/(maxiSettings::sampleRate/(1./release))); + if ( phase <= 0 ) { + phase = 0; + releaseMode=false; + } + } + + return phase; +} + + //Delay with feedback maxiDelayline::maxiDelayline() { memset( memory, 0, 88200*sizeof (double) ); diff --git a/maximilian.h b/maximilian.h index 6cb7628..658ead6 100755 --- a/maximilian.h +++ b/maximilian.h @@ -99,14 +99,25 @@ class maxiEnvelope { double period; double output; - double startval; + double phase; + double startVal; + double endVal; double currentval; double nextval; + bool releaseMode; + bool decayMode; + bool sustainMode; + bool attackMode=true; int isPlaying; -public: +public: + int trigger=1; double line(int numberofsegments,double segments[100]); - void trigger(int index,double amp); + double ramp(double startVal=0, double endVal=1, double duration=1, int trigger=1); + double ramps(double rampsArray[1000], int trigger=1); + double ar(double attack=0.1, double release=0.1,int trigger=1); + double adsr(double attack=0.1, double decay=0.1, double sustain=0.1, double release=0.1,int trigger=1); +// void trigger(int index,double amp); int valindex; double amplitude; diff --git a/maximilianTest.xcodeproj/project.pbxproj b/maximilianTest.xcodeproj/project.pbxproj index a63e823..b398724 100755 --- a/maximilianTest.xcodeproj/project.pbxproj +++ b/maximilianTest.xcodeproj/project.pbxproj @@ -284,7 +284,7 @@ buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; GCC_AUTO_VECTORIZATION = YES; - GCC_C_LANGUAGE_STANDARD = c11; + GCC_C_LANGUAGE_STANDARD = gnu99; GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_MODEL_PPC64 = NO; @@ -307,7 +307,7 @@ buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; GCC_AUTO_VECTORIZATION = YES; - GCC_C_LANGUAGE_STANDARD = c11; + GCC_C_LANGUAGE_STANDARD = gnu99; GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_MODEL_PPC64 = NO; diff --git a/openFrameworks/ofxMaxim/libs/fft.cpp b/openFrameworks/ofxMaxim/libs/fft.cpp index 85a7aa9..6e5e0de 100644 --- a/openFrameworks/ofxMaxim/libs/fft.cpp +++ b/openFrameworks/ofxMaxim/libs/fft.cpp @@ -544,9 +544,12 @@ void fft::inversePowerSpectrum(int start, float *finalOut, float *window, float } /* zero negative frequencies */ - memset(in_real+half, half, 0.0); - memset(in_img+half, half, 0.0); - +// memset(in_real+half, half, 0.0); +// memset(in_img+half, half, 0.0); + + memset(in_real+half, 0.0, sizeof(float) * half); + memset(in_img+half, 0.0, sizeof(float) * half); + FFT(n, 1, in_real, in_img, out_real, out_img); // second parameter indicates inverse transform for (i = 0; i < n; i++) { diff --git a/openFrameworks/ofxMaxim/libs/maxiFFT.h b/openFrameworks/ofxMaxim/libs/maxiFFT.h index d2694f4..53a75c5 100644 --- a/openFrameworks/ofxMaxim/libs/maxiFFT.h +++ b/openFrameworks/ofxMaxim/libs/maxiFFT.h @@ -33,7 +33,7 @@ #ifndef _MAXI_FFT #define _MAXI_FFT -//#define _NO_VDSP //set this if you don't want to use apple's vDSP fft functions +#define _NO_VDSP //set this if you don't want to use apple's vDSP fft functions #include "fft.h" @@ -125,4 +125,4 @@ public: }; -#endif
\ No newline at end of file +#endif diff --git a/openFrameworks/openFrameworksExamples/OSX/OF_0.9.0_OSX_XCode7_mySketch_maxim/src/ofApp.cpp b/openFrameworks/openFrameworksExamples/OSX/OF_0.9.0_OSX_XCode7_mySketch_maxim/src/ofApp.cpp index b3607f3..ef25823 100644 --- a/openFrameworks/openFrameworksExamples/OSX/OF_0.9.0_OSX_XCode7_mySketch_maxim/src/ofApp.cpp +++ b/openFrameworks/openFrameworksExamples/OSX/OF_0.9.0_OSX_XCode7_mySketch_maxim/src/ofApp.cpp @@ -57,7 +57,7 @@ void ofApp::draw(){ //-------------------------------------------------------------- void ofApp::audioOut(float * output, int bufferSize, int nChannels) { - + for (int i = 0; i < bufferSize; i++){ @@ -73,7 +73,6 @@ void ofApp::audioOut(float * output, int bufferSize, int nChannels) { //make 'wave' equal something noisy - double wave = mySample.play(0.5); output[i*nChannels ] = wave; /* You may end up with lots of outputs. add them here */ |
