diff options
| -rw-r--r-- | maximilian.cpp | 21 | ||||
| -rwxr-xr-x | maximilian.h | 11 | ||||
| -rwxr-xr-x | ofxMaxim/ofMaximWindowsVS2008_emptyExample/src/maximilian.cpp | 8 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/fft.h | 1 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/maxiFFT.cpp | 2 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/maximilian.cpp | 22 | ||||
| -rwxr-xr-x | ofxMaxim/ofxMaxim/libs/maximilian.h | 94 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaximExamples007OSX/ofMaximExample007OSX/ofxMaxim/libs/maximilian.cpp | 16 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaximiPhone0062Example/ofxMaxim/libs/maximilian.cpp | 16 |
9 files changed, 125 insertions, 66 deletions
diff --git a/maximilian.cpp b/maximilian.cpp index d731311..eca57a6 100644 --- a/maximilian.cpp +++ b/maximilian.cpp @@ -227,7 +227,7 @@ double maxiDelayline::dl(double input, int size, double feedback) { if ( phase >=size ) { phase = 0; } - output=memory[phase]; + output=memory[phase]; memory[phase]=(memory[phase]*feedback)+(input*feedback)*0.5; phase+=1; return(output); @@ -237,8 +237,8 @@ double maxiDelayline::dl(double input, int size, double feedback) { double maxiDelayline::dl(double input, int size, double feedback, int position) { if ( phase >=size ) phase = 0; if ( position >=size ) position = 0; - output=memory[position]; - memory[phase]=(memory[phase]*feedback)+(input*feedback)*chandiv; + output=memory[position]; + memory[phase]=(memory[phase]*feedback)+(input*feedback)*chandiv; phase+=1; return(output); @@ -444,10 +444,9 @@ double maxiSample::play() { double maxiSample::playOnce() { // long length=myDataSize*(0.5/myChannels); - double remainder; short* buffer = (short *)myData; position=(position+1); - remainder = position - (long) position; + double remainder = position - (long) position; if ((long) position<length) output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation else @@ -457,11 +456,11 @@ double maxiSample::playOnce() { } double maxiSample::playOnce(double speed) { - double remainder; //long a,b; // long length=myDataSize*0.5; short* buffer = (short *)myData; position=position+((speed*chandiv*myChannels)/(maxiSettings::sampleRate/mySampleRate)); + double remainder = position - (long) position; if ((long) position<length) output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation else @@ -657,7 +656,7 @@ double maxiSample::play4(double frequency, double start, double end) { double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double remainder; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=(position+1); remainder = position - (long) position; if ((long) position>length) position=0; @@ -668,7 +667,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double maxiSample::bufferPlay(unsigned char &bufferin,double speed,long length) { double remainder; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=position+((speed*chandiv*myChannels)/(maxiSettings::sampleRate/mySampleRate)); if (speed >=0) { @@ -715,7 +714,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double remainder; length=end; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; if (frequency >0.) { if (position<start) { position=start; @@ -771,7 +770,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double maxiSample::bufferPlay4(unsigned char &bufferin,double frequency, double start, double end) { double remainder; double a,b,c,d,a1,a2,a3; - short* buffer = (short*)bufferin; + short* buffer = (short*)&bufferin; if (frequency >0.) { if (position<start) { position=start; @@ -1023,4 +1022,4 @@ double maxiEnv::adsr(double input, double attack, double decay, double sustain, double convert::mtof(int midinote) { return mtofarray[midinote]; -}
\ No newline at end of file +} diff --git a/maximilian.h b/maximilian.h index 4ec75d1..2629390 100755 --- a/maximilian.h +++ b/maximilian.h @@ -42,7 +42,7 @@ #include <iostream> #include <fstream> -#include <string> +#include <string.h> #include <cstdlib> #include "math.h" @@ -193,15 +193,6 @@ public: ~maxiSample() { if (myData) delete[] myData; - myChunkSize = NULL; - mySubChunk1Size = NULL; - myFormat = NULL; - myChannels = NULL; - mySampleRate = NULL; - myByteRate = NULL; - myBlockAlign = NULL; - myBitsPerSample = NULL; - myDataSize = NULL; } maxiSample():myData(NULL){}; diff --git a/ofxMaxim/ofMaximWindowsVS2008_emptyExample/src/maximilian.cpp b/ofxMaxim/ofMaximWindowsVS2008_emptyExample/src/maximilian.cpp index a0ee618..adb0068 100755 --- a/ofxMaxim/ofMaximWindowsVS2008_emptyExample/src/maximilian.cpp +++ b/ofxMaxim/ofMaximWindowsVS2008_emptyExample/src/maximilian.cpp @@ -515,7 +515,7 @@ double maxiSample::play4(double frequency, double start, double end) { double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double remainder; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=(position+1); remainder = position - (long) position; if ((long) position>length) position=0; @@ -526,7 +526,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double maxiSample::bufferPlay(unsigned char &bufferin,double speed,long length) { double remainder; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=position+((speed*chandiv*myChannels)/(samplerate/mySampleRate)); if (speed >=0) { @@ -573,7 +573,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double remainder; length=end; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; if (frequency >0.) { if (position<start) { position=start; @@ -629,7 +629,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double maxiSample::bufferPlay4(unsigned char &bufferin,double frequency, double start, double end) { double remainder; double a,b,c,d,a1,a2,a3; - short* buffer = (short*)bufferin; + short* buffer = (short*)&bufferin; if (frequency >0.) { if (position<start) { position=start; diff --git a/ofxMaxim/ofxMaxim/libs/fft.h b/ofxMaxim/ofxMaxim/libs/fft.h index f7e1947..84d7a91 100644 --- a/ofxMaxim/ofxMaxim/libs/fft.h +++ b/ofxMaxim/ofxMaxim/libs/fft.h @@ -39,7 +39,6 @@ #ifdef __APPLE_CC__ #include <Accelerate/Accelerate.h> - #warning Please link against the Accelerate framework #endif diff --git a/ofxMaxim/ofxMaxim/libs/maxiFFT.cpp b/ofxMaxim/ofxMaxim/libs/maxiFFT.cpp index 36034b2..866be40 100644 --- a/ofxMaxim/ofxMaxim/libs/maxiFFT.cpp +++ b/ofxMaxim/ofxMaxim/libs/maxiFFT.cpp @@ -121,7 +121,7 @@ float maxiFFT::spectralCentroid() { maxiFFT::~maxiFFT() { delete _fft; if (buffer) - delete[] buffer,magnitudes,phases,window, avgPower; + delete[] buffer,magnitudes,phases,window, avgPower, magnitudesDB; } diff --git a/ofxMaxim/ofxMaxim/libs/maximilian.cpp b/ofxMaxim/ofxMaxim/libs/maximilian.cpp index fe046f2..5326172 100644 --- a/ofxMaxim/ofxMaxim/libs/maximilian.cpp +++ b/ofxMaxim/ofxMaxim/libs/maximilian.cpp @@ -173,9 +173,9 @@ double maxiOsc::triangle(double frequency) { if ( phase >= 1.0 ) phase -= 1.0; phase += (1./(maxiSettings::sampleRate/(frequency))); if (phase <= 0.5 ) { - output =((phase)*4)-1; + output =(phase - 0.25) * 4; } else { - output =((0.5-phase)*4)-1; + output =((1.0-phase) - 0.25) * 4; } return(output); @@ -228,7 +228,7 @@ double maxiDelayline::dl(double input, int size, double feedback) { if ( phase >=size ) { phase = 0; } - output=memory[phase]; + output=memory[phase]; memory[phase]=(memory[phase]*feedback)+(input*feedback)*0.5; phase+=1; return(output); @@ -446,10 +446,9 @@ double maxiSample::play() { double maxiSample::playOnce() { // long length=myDataSize*(0.5/myChannels); - double remainder; short* buffer = (short *)myData; position=(position+1); - remainder = position - (long) position; + double remainder = position - (long) position; if ((long) position<length) output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation else @@ -459,11 +458,11 @@ double maxiSample::playOnce() { } double maxiSample::playOnce(double speed) { - double remainder; //long a,b; // long length=myDataSize*0.5; short* buffer = (short *)myData; position=position+((speed*chandiv*myChannels)/(maxiSettings::sampleRate/mySampleRate)); + double remainder = position - (long) position; if ((long) position<length) output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation else @@ -659,7 +658,7 @@ double maxiSample::play4(double frequency, double start, double end) { double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double remainder; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=(position+1); remainder = position - (long) position; if ((long) position>length) position=0; @@ -670,7 +669,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double maxiSample::bufferPlay(unsigned char &bufferin,double speed,long length) { double remainder; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=position+((speed*chandiv*myChannels)/(maxiSettings::sampleRate/mySampleRate)); if (speed >=0) { @@ -717,7 +716,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double remainder; length=end; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; if (frequency >0.) { if (position<start) { position=start; @@ -773,7 +772,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double maxiSample::bufferPlay4(unsigned char &bufferin,double frequency, double start, double end) { double remainder; double a,b,c,d,a1,a2,a3; - short* buffer = (short*)bufferin; + short* buffer = (short*)&bufferin; if (frequency >0.) { if (position<start) { position=start; @@ -1025,4 +1024,5 @@ double maxiEnv::adsr(double input, double attack, double decay, double sustain, double convert::mtof(int midinote) { return mtofarray[midinote]; -}
\ No newline at end of file +} + diff --git a/ofxMaxim/ofxMaxim/libs/maximilian.h b/ofxMaxim/ofxMaxim/libs/maximilian.h index d587fae..85c4c16 100755 --- a/ofxMaxim/ofxMaxim/libs/maximilian.h +++ b/ofxMaxim/ofxMaxim/libs/maximilian.h @@ -42,7 +42,7 @@ #include <iostream> #include <fstream> -#include <string> +#include <string.h> #include <cstdlib> #include "math.h" @@ -101,7 +101,7 @@ class maxiEnvelope { double currentval; double nextval; int isPlaying; - + public: double line(int numberofsegments,double segments[100]); void trigger(int index,double amp); @@ -139,6 +139,7 @@ class maxiFilter { double y;//pos double z;//pole double c;//filter coefficient + public: maxiFilter():x(0.0), y(0.0), z(0.0), c(0.0){}; double cutoff; @@ -196,18 +197,9 @@ public: ~maxiSample() { if (myData) delete[] myData; - myChunkSize = NULL; - mySubChunk1Size = NULL; - myFormat = NULL; - myChannels = NULL; - mySampleRate = NULL; - myByteRate = NULL; - myBlockAlign = NULL; - myBitsPerSample = NULL; - myDataSize = NULL; } - maxiSample():myData(NULL){}; + maxiSample():myData(NULL),position(0){}; bool load(string fileName, int channel=0); @@ -372,4 +364,82 @@ public: double mtof(int midinote); }; + + +class maxiDistortion { +public: + /*atan distortion, see http://www.musicdsp.org/showArchiveComment.php?ArchiveID=104*/ + /*shape from 1 (soft clipping) to infinity (hard clipping)*/ + double atanDist(const double in, const double shape); + double fastAtanDist(const double in, const double shape); + double fastatan( double x ); +}; + +inline double maxiDistortion::fastatan(double x) +{ + return (x / (1.0 + 0.28 * (x * x))); +} + +inline double maxiDistortion::atanDist(const double in, const double shape) { + double out; + out = (1.0 / atan(shape)) * atan(in * shape); + return out; +} + +inline double maxiDistortion::fastAtanDist(const double in, const double shape) { + double out; + out = (1.0 / fastatan(shape)) * fastatan(in * shape); + return out; +} + + +class maxiFlanger { +public: + //delay = delay time - ~800 sounds good + //feedback = 0 - 1 + //speed = lfo speed in Hz, 0.0001 - 10 sounds good + //depth = 0 - 1 + double flange(const double input, const unsigned int delay, const double feedback, const double speed, const double depth); + maxiDelayline dl; + maxiOsc lfo; + +}; + +inline double maxiFlanger::flange(const double input, const unsigned int delay, const double feedback, const double speed, const double depth) +{ + //todo: needs fixing + double output; + double lfoVal = lfo.triangle(speed); + output = dl.dl(input, delay + (lfoVal * depth * delay) + 1, feedback) ; + double normalise = (1 - fabs(output)); + output *= normalise; + return (output + input) / 2.0; +} + +class maxiChorus { +public: + //delay = delay time - ~800 sounds good + //feedback = 0 - 1 + //speed = lfo speed in Hz, 0.0001 - 10 sounds good + //depth = 0 - 1 + double chorus(const double input, const unsigned int delay, const double feedback, const double speed, const double depth); + maxiDelayline dl, dl2; + maxiOsc lfo; + maxiFilter lopass; + +}; + +inline double maxiChorus::chorus(const double input, const unsigned int delay, const double feedback, const double speed, const double depth) +{ + //this needs fixing + double output1, output2; + double lfoVal = lfo.noise(); + lfoVal = lopass.lores(lfoVal, speed, 1.0) * 2.0; + output1 = dl.dl(input, delay + (lfoVal * depth * delay) + 1, feedback) ; + output2 = dl2.dl(input, (delay + (lfoVal * depth * delay * 1.02) + 1) * 0.98, feedback * 0.99) ; + output1 *= (1.0 - fabs(output1)); + output2 *= (1.0 - fabs(output2)); + return (output1 + output2 + input) / 3.0; +} + #endif diff --git a/ofxMaxim/ofxMaximExamples007OSX/ofMaximExample007OSX/ofxMaxim/libs/maximilian.cpp b/ofxMaxim/ofxMaximExamples007OSX/ofMaximExample007OSX/ofxMaxim/libs/maximilian.cpp index 102ef15..63b9a34 100644 --- a/ofxMaxim/ofxMaximExamples007OSX/ofMaximExample007OSX/ofxMaxim/libs/maximilian.cpp +++ b/ofxMaxim/ofxMaximExamples007OSX/ofMaximExample007OSX/ofxMaxim/libs/maximilian.cpp @@ -219,7 +219,7 @@ void maxiEnvelope::trigger(int index, double amp) { //and this maxiDelayline::maxiDelayline() { - memory[88200]=NULL; + memset( memory, 0, 88200*sizeof (double) ); } @@ -228,7 +228,7 @@ double maxiDelayline::dl(double input, int size, double feedback) { if ( phase >=size ) { phase = 0; } - output=memory[phase]; + output=memory[phase]; memory[phase]=(memory[phase]*feedback)+(input*feedback)*0.5; phase+=1; return(output); @@ -238,8 +238,8 @@ double maxiDelayline::dl(double input, int size, double feedback) { double maxiDelayline::dl(double input, int size, double feedback, int position) { if ( phase >=size ) phase = 0; if ( position >=size ) position = 0; - output=memory[position]; - memory[phase]=(memory[phase]*feedback)+(input*feedback)*chandiv; + output=memory[position]; + memory[phase]=(memory[phase]*feedback)+(input*feedback)*chandiv; phase+=1; return(output); @@ -659,7 +659,7 @@ double maxiSample::play4(double frequency, double start, double end) { double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double remainder; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=(position+1); remainder = position - (long) position; if ((long) position>length) position=0; @@ -670,7 +670,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double maxiSample::bufferPlay(unsigned char &bufferin,double speed,long length) { double remainder; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=position+((speed*chandiv*myChannels)/(maxiSettings::sampleRate/mySampleRate)); if (speed >=0) { @@ -717,7 +717,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double remainder; length=end; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; if (frequency >0.) { if (position<start) { position=start; @@ -773,7 +773,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double maxiSample::bufferPlay4(unsigned char &bufferin,double frequency, double start, double end) { double remainder; double a,b,c,d,a1,a2,a3; - short* buffer = (short*)bufferin; + short* buffer = (short*)&bufferin; if (frequency >0.) { if (position<start) { position=start; diff --git a/ofxMaxim/ofxMaximiPhone0062Example/ofxMaxim/libs/maximilian.cpp b/ofxMaxim/ofxMaximiPhone0062Example/ofxMaxim/libs/maximilian.cpp index 102ef15..63b9a34 100644 --- a/ofxMaxim/ofxMaximiPhone0062Example/ofxMaxim/libs/maximilian.cpp +++ b/ofxMaxim/ofxMaximiPhone0062Example/ofxMaxim/libs/maximilian.cpp @@ -219,7 +219,7 @@ void maxiEnvelope::trigger(int index, double amp) { //and this maxiDelayline::maxiDelayline() { - memory[88200]=NULL; + memset( memory, 0, 88200*sizeof (double) ); } @@ -228,7 +228,7 @@ double maxiDelayline::dl(double input, int size, double feedback) { if ( phase >=size ) { phase = 0; } - output=memory[phase]; + output=memory[phase]; memory[phase]=(memory[phase]*feedback)+(input*feedback)*0.5; phase+=1; return(output); @@ -238,8 +238,8 @@ double maxiDelayline::dl(double input, int size, double feedback) { double maxiDelayline::dl(double input, int size, double feedback, int position) { if ( phase >=size ) phase = 0; if ( position >=size ) position = 0; - output=memory[position]; - memory[phase]=(memory[phase]*feedback)+(input*feedback)*chandiv; + output=memory[position]; + memory[phase]=(memory[phase]*feedback)+(input*feedback)*chandiv; phase+=1; return(output); @@ -659,7 +659,7 @@ double maxiSample::play4(double frequency, double start, double end) { double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double remainder; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=(position+1); remainder = position - (long) position; if ((long) position>length) position=0; @@ -670,7 +670,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,long length) { double maxiSample::bufferPlay(unsigned char &bufferin,double speed,long length) { double remainder; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; position=position+((speed*chandiv*myChannels)/(maxiSettings::sampleRate/mySampleRate)); if (speed >=0) { @@ -717,7 +717,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double remainder; length=end; long a,b; - short* buffer = (short *)bufferin; + short* buffer = (short *)&bufferin; if (frequency >0.) { if (position<start) { position=start; @@ -773,7 +773,7 @@ double maxiSample::bufferPlay(unsigned char &bufferin,double frequency, double s double maxiSample::bufferPlay4(unsigned char &bufferin,double frequency, double start, double end) { double remainder; double a,b,c,d,a1,a2,a3; - short* buffer = (short*)bufferin; + short* buffer = (short*)&bufferin; if (frequency >0.) { if (position<start) { position=start; |
