diff options
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/fft.cpp | 2 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/maxiFFT.cpp | 2 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/maximilian.cpp | 19 | ||||
| -rwxr-xr-x | ofxMaxim/ofxMaxim/libs/maximilian.h | 14 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/src/ofxMaxim.h | 63 |
5 files changed, 88 insertions, 12 deletions
diff --git a/ofxMaxim/ofxMaxim/libs/fft.cpp b/ofxMaxim/ofxMaxim/libs/fft.cpp index 9fe812f..dddcd2a 100644 --- a/ofxMaxim/ofxMaxim/libs/fft.cpp +++ b/ofxMaxim/ofxMaxim/libs/fft.cpp @@ -597,7 +597,7 @@ void fft::inversePowerSpectrum_vdsp(int start, float *finalOut, float *window, f vDSP_fft_zrip(setupReal, &A, 1, log2n, FFT_INVERSE); vDSP_ztoc(&A, 1, (COMPLEX*) out_real, 2, half); - static float scale = 1./n; + float scale = 1./n; vDSP_vsmul(out_real, 1, &scale, out_real, 1, n); //multiply by window diff --git a/ofxMaxim/ofxMaxim/libs/maxiFFT.cpp b/ofxMaxim/ofxMaxim/libs/maxiFFT.cpp index 866be40..2ddefb4 100644 --- a/ofxMaxim/ofxMaxim/libs/maxiFFT.cpp +++ b/ofxMaxim/ofxMaxim/libs/maxiFFT.cpp @@ -203,7 +203,7 @@ void maxiFFTOctaveAnalyzer::setup(float samplingRate, int nBandsInTheFFT, int nA // fe: 2f for octave bands, sqrt(2) for half-octave bands, cuberoot(2) for third-octave bands, etc if (nAveragesPerOctave==0) // um, wtf? nAveragesPerOctave = 1; - nAveragesPerOctave = nAveragesPerOctave; +// nAveragesPerOctave = nAveragesPerOctave; averageFrequencyIncrement = pow(2.0f, 1.0f/(float)(nAveragesPerOctave)); // this isn't currently configurable (used once here then no effect), but here's some reasoning: // 43 is a good value if you want to approximate "computer" octaves: 44100/2/2/2/2/2/2/2/2/2/2 diff --git a/ofxMaxim/ofxMaxim/libs/maximilian.cpp b/ofxMaxim/ofxMaxim/libs/maximilian.cpp index 2700d33..64728e4 100644 --- a/ofxMaxim/ofxMaxim/libs/maximilian.cpp +++ b/ofxMaxim/ofxMaxim/libs/maximilian.cpp @@ -457,6 +457,7 @@ bool maxiSample::read() length=myDataSize*(0.5/myChannels); inFile.close(); // close the input file + cout << "Ch: " << myChannels << ", len: " << length << endl; if (myChannels>1) { int position=0; int channel=readChannel*2; @@ -488,14 +489,15 @@ double maxiSample::play() { } double maxiSample::playOnce() { - position=(position+1); - double remainder = position - (long) position; + short* buffer = (short *)myData; + position++; if ((long) position<length) - output = (double) ((1-remainder) * temp[1+ (long) position] + remainder * temp[2+(long) position])/32767;//linear interpolation - else - output=0; + output = (double) buffer[(long)position]/32767.0; + else { + output=0; + } + return output; - return(output); } double maxiSample::playOnce(double speed) { @@ -900,6 +902,11 @@ void maxiSample::clear() { memset(myData, 0, myDataSize); } +void maxiSample::reset() { + position=0; +} + + diff --git a/ofxMaxim/ofxMaxim/libs/maximilian.h b/ofxMaxim/ofxMaxim/libs/maximilian.h index 32fdb1a..6eeb8d1 100755 --- a/ofxMaxim/ofxMaxim/libs/maximilian.h +++ b/ofxMaxim/ofxMaxim/libs/maximilian.h @@ -234,7 +234,7 @@ public: } - maxiSample():myData(NULL),position(0), recordPosition(0), myChannels(1), mySampleRate(maxiSettings::sampleRate) {}; + maxiSample():myData(NULL),temp(NULL),position(0), recordPosition(0), myChannels(1), mySampleRate(maxiSettings::sampleRate) {}; bool load(string fileName, int channel=0); @@ -262,6 +262,8 @@ public: } void clear(); + + void reset(); double play(); @@ -284,10 +286,13 @@ public: double bufferPlay(unsigned char &bufferin,double frequency, double start, double end); double bufferPlay4(unsigned char &bufferin,double frequency, double start, double end); - - bool save() + bool save() { + save(myPath); + } + + bool save(string filename) { - fstream myFile (myPath.c_str(), ios::out | ios::binary); + fstream myFile (filename.c_str(), ios::out | ios::binary); // write the wav file per the wav file format myFile.seekp (0, ios::beg); @@ -485,6 +490,7 @@ public: env = release * (env - input) + input; return env; } + void reset() {env=0;} private: double attack, release, env; }; diff --git a/ofxMaxim/ofxMaxim/src/ofxMaxim.h b/ofxMaxim/ofxMaxim/src/ofxMaxim.h index ec8c539..b197723 100644 --- a/ofxMaxim/ofxMaxim/src/ofxMaxim.h +++ b/ofxMaxim/ofxMaxim/src/ofxMaxim.h @@ -52,4 +52,67 @@ typedef maxiSettings ofxMaxiSettings; typedef maxiMFCC ofxMaxiMFCC; +//typedef maxiSignal vector<double>; +// +//class maxiBase { +// virtual maxiSignal play() = {}; +//}; +// +//class ofMaxiSine : public maxiBase { +// maxiOsc osc; +// double freq; +// +// void update(double freq) { +// freq = freq; +// } +// void play() { +// osc.sine(freq); +// } +//} +// +// +//class maxiNoise : public maxiBase { +// maxiBase* update() { +// //do something? +// }; +// +// double play() { +// return rand() / (float)RAND_MAX; +// } +//}; +// +//class maxiAnotherUGen : public maxiBase { +// maxiBase* update(double param1, bool param2); +//}; +// +//class maxiYetAnotherUGen : public maxiBase { +// maxiBase* update(int something, float somethingElse); +//}; +// +//void maxiProcess(maxiSignal &signal, maxiBase *ugen) { +// double val = ugen->play(); +// for(int i=0; i < signal.size(); i++) { +// signal[i] = val; +// } +//} +// +//void maxiBlock(maxiSignal &signal, maxiBase *ugen) { +// for (int i=0; i < 64; i++) { +// maxiProcess(signal, ugen); +// } +//} +// +//typedef maxiUGens vector<maxiBase> +// +//maxiNoise ugen1; +//maxiAnotherUGen ugen2; +//maxiUGens ugen1 = createUGens(maxiNoise, 2); +// +//maxiSignal sig(2); +//maxiProcess(sig, ugen1.update()); +//maxiProcess(sig, ugen2.update(8.2, false)); +// +//ugen.update(2,3)->play(); + + #endif |
