aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README2
-rwxr-xr-xmain.cpp92
-rw-r--r--maximilian.cpp199
-rwxr-xr-xmaximilian.h19
-rwxr-xr-xmaximilianTest.xcodeproj/project.pbxproj4
-rw-r--r--openFrameworks/ofxMaxim/libs/fft.cpp9
-rw-r--r--openFrameworks/ofxMaxim/libs/maxiFFT.h4
-rw-r--r--openFrameworks/openFrameworksExamples/OSX/OF_0.9.0_OSX_XCode7_mySketch_maxim/src/ofApp.cpp3
8 files changed, 302 insertions, 30 deletions
diff --git a/README b/README
index 009126a..51d6e00 100644
--- a/README
+++ b/README
@@ -41,7 +41,7 @@ This is in the maximilianTestWindowsVS2010 folder. You will need to install the
:::COMMAND LINE COMPILATION IN MACOSX
-> g++ -Wall -D__MACOSX_CORE__ -o maximilian main.cpp RtAudio.cpp player.cpp maximilian.cpp -framework CoreAudio -lpthread
+> g++ -Wall -D__MACOSX_CORE__ -o maximilian main.cpp RtAudio.cpp player.cpp maximilian.cpp -framework CoreAudio -framework CoreFoundation -lpthread
> ./maximilian
diff --git a/main.cpp b/main.cpp
index d7ca862..9bd1025 100755
--- a/main.cpp
+++ b/main.cpp
@@ -1,22 +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.trigger(true);
+//
+//}
+//
+//void play(double *output) {//this is where the magic happens. Very slow magic.
+//
+// counter++;
+//
+// if (counter ==0 || counter % 330400==0) {
+// myEnv.trigger(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=0;
+//
+//void setup() {
+//}
+//
+//void play(double *output) {
+//
+//
+// if (counter ==0 || counter % 17640==0) {
+// myEnv.trigger(true);
+// }
+//
+// if (counter % 8821==0) {
+// myEnv.trigger(false);
+// }
+//
+// counter++;
+//
+// double out = myEnv.adsr(0.1,0.2,0.1,3);
+//
+// output[0]=myOsc.sinewave(440)*out;
+//
+// output[1]=output[0];
+//
+//}
+
#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;
-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 setup() {
}
-void play(double *output) {//this is where the magic happens. Very slow magic.
+void play(double *output) {
+
- //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.
+ 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 3391da1..0d9bcfd 100644
--- a/maximilian.cpp
+++ b/maximilian.cpp
@@ -364,6 +364,8 @@ double maxiOsc::triangle(double frequency) {
}
+// don't use this nonsense. Use ramps instead.
+// ..er... I mean "This method is deprecated"
double maxiEnvelope::line(int numberofsegments,double segments[1000]) {
//This is a basic multi-segment ramp generator that you can use for more or less anything.
//However, it's not that intuitive.
@@ -372,14 +374,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;
@@ -391,7 +393,7 @@ double maxiEnvelope::line(int numberofsegments,double segments[1000]) {
return(output);
}
-//and this
+//and this is also deprecated
void maxiEnvelope::trigger(int index, double amp) {
isPlaying=1;//ok the envelope is being used now.
valindex=index;
@@ -399,6 +401,195 @@ void maxiEnvelope::trigger(int index, double amp) {
}
+void maxiEnvelope::trigger(bool noteOn) {
+
+ if (noteOn) trig=1;
+ if (noteOn==false) trig=0;
+
+}
+
+double maxiEnvelope::ramp(double startVal, double endVal, double duration){
+
+ if (trig!=0) {
+ phase=startVal;
+ isPlaying=true;
+ trig=0;
+ }
+
+ if (isPlaying) {
+
+ 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);
+ } else {
+
+ return(0);
+
+ }
+
+
+}
+
+
+double maxiEnvelope::ramps(std::vector<double> rampsArray){
+
+ if (trig!=0) {
+ valindex=0;
+ endVal=rampsArray[valindex+1];
+ isPlaying=true;
+ trig=0;
+
+ }
+
+ if (isPlaying) {
+
+ if (valindex>0 && rampsArray[valindex-1]==rampsArray[valindex+1]) {
+ period += (1/(maxiSettings::sampleRate/(1./rampsArray[valindex])));
+ if (period>=1) {
+ phase=endVal;
+ startVal=phase;
+ if (valindex+2<rampsArray.size()){
+ valindex+=2;
+ endVal=rampsArray[valindex+1];
+ period=0;
+ }
+ } output=phase;
+ }
+
+ if (valindex==0 && output==endVal) {
+ period += (1/(maxiSettings::sampleRate/(1./rampsArray[valindex])));
+ if (period>=1) {
+ phase=endVal;
+ startVal=phase;
+ if (valindex+2<rampsArray.size()){
+ valindex+=2;
+ endVal=rampsArray[valindex+1];
+ period=0;
+ }
+ } output=phase;
+ }
+
+ if (phase<endVal) {
+ phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./rampsArray[valindex])));
+ if ( phase >= endVal ) {
+ phase=endVal;
+ startVal=phase;
+ if (valindex+2<rampsArray.size()){
+ valindex+=2;
+ endVal=rampsArray[valindex+1];
+
+ }
+ }
+ output=phase;
+ }
+
+ if (phase > endVal) {
+ phase += ((endVal-startVal)/(maxiSettings::sampleRate/(1./rampsArray[valindex])));
+ if ( phase <= endVal ) {
+ phase=endVal;
+ startVal=phase;
+ if (valindex+2<rampsArray.size()){
+ valindex+=2;
+ endVal=rampsArray[valindex+1];
+
+ }
+ } output=phase;
+ }
+
+ return(output);
+
+ } else {
+
+ return(0);
+ }
+}
+
+double maxiEnvelope::ar(double attack, double release) {
+
+ if (trig!=0) {
+ //phase=0;
+ releaseMode=false;
+ trig=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) {
+
+ if (trig!=0 && !attackMode) {
+// phase=0.;
+ releaseMode=false;
+ decayMode=false;
+ sustainMode=false;
+ attackMode=true;
+ trig=0;
+ }
+
+ if (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 (noteOn) {
+ phase=sustain;
+ }
+
+ if (!noteOn) {
+ 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 d2db173..2e8593d 100755
--- a/maximilian.h
+++ b/maximilian.h
@@ -109,16 +109,29 @@ public:
class maxiEnvelope {
- double period;
+ double period=0;
double output;
- double startval;
+ double phase;
+ double startVal;
+ double endVal;
double currentval;
double nextval;
+ bool noteOn;
+ bool releaseMode;
+ bool decayMode;
+ bool sustainMode;
+ bool attackMode;
int isPlaying;
-public:
+public:
+ 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 trigger(bool noteOn=false);
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 */