diff options
| author | Chris Kiefer <chrisk13fer@gmail.com> | 2012-02-22 11:54:30 +0000 |
|---|---|---|
| committer | Chris Kiefer <chrisk13fer@gmail.com> | 2012-02-22 11:54:30 +0000 |
| commit | bb60cd352f53f4600913d2152032dd4aff228520 (patch) | |
| tree | c9a663b0f0d7ec52f4a3e2011f8762d976402ae0 | |
| parent | f50936e993e14adcccbe9be68031676ad0f07085 (diff) | |
optimsed gabor creation
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/fft.cpp | 36 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/maxiAtoms.cpp | 37 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/maxiAtoms.h | 4 | ||||
| -rw-r--r-- | ofxMaxim/ofxMaxim/libs/maxiGrains.h | 18 |
4 files changed, 63 insertions, 32 deletions
diff --git a/ofxMaxim/ofxMaxim/libs/fft.cpp b/ofxMaxim/ofxMaxim/libs/fft.cpp index 3f13bd2..e65b5cc 100644 --- a/ofxMaxim/ofxMaxim/libs/fft.cpp +++ b/ofxMaxim/ofxMaxim/libs/fft.cpp @@ -361,25 +361,25 @@ void PowerSpectrum(int NumSamples, float *In, float *Out) * Windowing Functions */ -int NumWindowFuncs() -{ - return 4; -} +//int NumWindowFuncs() +//{ +// return 4; +//} -char *WindowFuncName(int whichFunction) -{ - switch (whichFunction) { - default: - case 0: - return "Rectangular"; - case 1: - return "Bartlett"; - case 2: - return "Hamming"; - case 3: - return "Hanning"; - } -} +//char *WindowFuncName(int whichFunction) +//{ +// switch (whichFunction) { +// default: +// case 0: +// return "Rectangular"; +// case 1: +// return "Bartlett"; +// case 2: +// return "Hamming"; +// case 3: +// return "Hanning"; +// } +//} void WindowFunc(int whichFunction, int NumSamples, float *in) { diff --git a/ofxMaxim/ofxMaxim/libs/maxiAtoms.cpp b/ofxMaxim/ofxMaxim/libs/maxiAtoms.cpp index afff2cb..f834288 100644 --- a/ofxMaxim/ofxMaxim/libs/maxiAtoms.cpp +++ b/ofxMaxim/ofxMaxim/libs/maxiAtoms.cpp @@ -16,43 +16,52 @@ #include <Accelerate/Accelerate.h> #endif - float sineBuffer2[514]={0,0.012268,0.024536,0.036804,0.049042,0.06131,0.073547,0.085785,0.097992,0.1102,0.12241,0.13455,0.1467,0.15884,0.17093,0.18301,0.19507,0.20709,0.21909,0.23105,0.24295,0.25485,0.26669,0.2785,0.29025,0.30197,0.31366,0.32529,0.33685,0.34839,0.35986,0.37128,0.38266,0.39395,0.40521,0.41641,0.42752,0.4386,0.44958,0.46051,0.47137,0.48215,0.49286,0.50351,0.51407,0.52457,0.53497,0.54529,0.55554,0.5657,0.57578,0.58575,0.59567,0.60547,0.6152,0.62482,0.63437,0.6438,0.65314,0.66238,0.67151,0.68057,0.68951,0.69833,0.70706,0.7157,0.72421,0.7326,0.74091,0.74908,0.75717,0.76514,0.77298,0.7807,0.7883,0.79581,0.80316,0.81042,0.81754,0.82455,0.83142,0.8382,0.84482,0.85132,0.8577,0.86392,0.87006,0.87604,0.88187,0.8876,0.89319,0.89862,0.90396,0.90912,0.91415,0.91907,0.92383,0.92847,0.93295,0.93729,0.9415,0.94556,0.94949,0.95325,0.95691,0.96039,0.96375,0.96692,0.97,0.9729,0.97565,0.97827,0.98074,0.98306,0.98523,0.98724,0.98914,0.99084,0.99243,0.99387,0.99515,0.99628,0.99725,0.99808,0.99875,0.99927,0.99966,0.99988,0.99997,0.99988,0.99966,0.99927,0.99875,0.99808,0.99725,0.99628,0.99515,0.99387,0.99243,0.99084,0.98914,0.98724,0.98523,0.98306,0.98074,0.97827,0.97565,0.9729,0.97,0.96692,0.96375,0.96039,0.95691,0.95325,0.94949,0.94556,0.9415,0.93729,0.93295,0.92847,0.92383,0.91907,0.91415,0.90912,0.90396,0.89862,0.89319,0.8876,0.88187,0.87604,0.87006,0.86392,0.8577,0.85132,0.84482,0.8382,0.83142,0.82455,0.81754,0.81042,0.80316,0.79581,0.7883,0.7807,0.77298,0.76514,0.75717,0.74908,0.74091,0.7326,0.72421,0.7157,0.70706,0.69833,0.68951,0.68057,0.67151,0.66238,0.65314,0.6438,0.63437,0.62482,0.6152,0.60547,0.59567,0.58575,0.57578,0.5657,0.55554,0.54529,0.53497,0.52457,0.51407,0.50351,0.49286,0.48215,0.47137,0.46051,0.44958,0.4386,0.42752,0.41641,0.40521,0.39395,0.38266,0.37128,0.35986,0.34839,0.33685,0.32529,0.31366,0.30197,0.29025,0.2785,0.26669,0.25485,0.24295,0.23105,0.21909,0.20709,0.19507,0.18301,0.17093,0.15884,0.1467,0.13455,0.12241,0.1102,0.097992,0.085785,0.073547,0.06131,0.049042,0.036804,0.024536,0.012268,0,-0.012268,-0.024536,-0.036804,-0.049042,-0.06131,-0.073547,-0.085785,-0.097992,-0.1102,-0.12241,-0.13455,-0.1467,-0.15884,-0.17093,-0.18301,-0.19507,-0.20709,-0.21909,-0.23105,-0.24295,-0.25485,-0.26669,-0.2785,-0.29025,-0.30197,-0.31366,-0.32529,-0.33685,-0.34839,-0.35986,-0.37128,-0.38266,-0.39395,-0.40521,-0.41641,-0.42752,-0.4386,-0.44958,-0.46051,-0.47137,-0.48215,-0.49286,-0.50351,-0.51407,-0.52457,-0.53497,-0.54529,-0.55554,-0.5657,-0.57578,-0.58575,-0.59567,-0.60547,-0.6152,-0.62482,-0.63437,-0.6438,-0.65314,-0.66238,-0.67151,-0.68057,-0.68951,-0.69833,-0.70706,-0.7157,-0.72421,-0.7326,-0.74091,-0.74908,-0.75717,-0.76514,-0.77298,-0.7807,-0.7883,-0.79581,-0.80316,-0.81042,-0.81754,-0.82455,-0.83142,-0.8382,-0.84482,-0.85132,-0.8577,-0.86392,-0.87006,-0.87604,-0.88187,-0.8876,-0.89319,-0.89862,-0.90396,-0.90912,-0.91415,-0.91907,-0.92383,-0.92847,-0.93295,-0.93729,-0.9415,-0.94556,-0.94949,-0.95325,-0.95691,-0.96039,-0.96375,-0.96692,-0.97,-0.9729,-0.97565,-0.97827,-0.98074,-0.98306,-0.98523,-0.98724,-0.98914,-0.99084,-0.99243,-0.99387,-0.99515,-0.99628,-0.99725,-0.99808,-0.99875,-0.99927,-0.99966,-0.99988,-0.99997,-0.99988,-0.99966,-0.99927,-0.99875,-0.99808,-0.99725,-0.99628,-0.99515,-0.99387,-0.99243,-0.99084,-0.98914,-0.98724,-0.98523,-0.98306,-0.98074,-0.97827,-0.97565,-0.9729,-0.97,-0.96692,-0.96375,-0.96039,-0.95691,-0.95325,-0.94949,-0.94556,-0.9415,-0.93729,-0.93295,-0.92847,-0.92383,-0.91907,-0.91415,-0.90912,-0.90396,-0.89862,-0.89319,-0.8876,-0.88187,-0.87604,-0.87006,-0.86392,-0.8577,-0.85132,-0.84482,-0.8382,-0.83142,-0.82455,-0.81754,-0.81042,-0.80316,-0.79581,-0.7883,-0.7807,-0.77298,-0.76514,-0.75717,-0.74908,-0.74091,-0.7326,-0.72421,-0.7157,-0.70706,-0.69833,-0.68951,-0.68057,-0.67151,-0.66238,-0.65314,-0.6438,-0.63437,-0.62482,-0.6152,-0.60547,-0.59567,-0.58575,-0.57578,-0.5657,-0.55554,-0.54529,-0.53497,-0.52457,-0.51407,-0.50351,-0.49286,-0.48215,-0.47137,-0.46051,-0.44958,-0.4386,-0.42752,-0.41641,-0.40521,-0.39395,-0.38266,-0.37128,-0.35986,-0.34839,-0.33685,-0.32529,-0.31366,-0.30197,-0.29025,-0.2785,-0.26669,-0.25485,-0.24295,-0.23105,-0.21909,-0.20709,-0.19507,-0.18301,-0.17093,-0.15884,-0.1467,-0.13455,-0.12241,-0.1102,-0.097992,-0.085785,-0.073547,-0.06131,-0.049042,-0.036804,-0.024536,-0.012268,0,0.012268 }; +maxiGrainWindowCache<gaussianWinFunctor> maxiCollider::envCache = maxiGrainWindowCache<gaussianWinFunctor>(); + inline void maxiCollider::createGabor(flArr &atom, const float freq, const float sampleRate, const uint length, float startPhase, const float kurtotis, const float amp) { atom.resize(length); flArr sine; sine.resize(length); - float inc = 1.0 / length * 2.0; - float gausDivisor = (-2.0 * kurtotis * kurtotis); - float phase =-1.0; +// float gausDivisor = (-2.0 * kurtotis * kurtotis); +// float phase =-1.0; + double *env = maxiCollider::envCache.getWindow(length); #ifdef __APPLE_CC__ - vDSP_vramp(&phase, &inc, &atom[0], 1, length); - vDSP_vsq(&atom[0], 1, &atom[0], 1, length); - vDSP_vsdiv(&atom[0], 1, &gausDivisor, &atom[0], 1, length); - for(uint i=0; i < length; i++) atom[i] = exp(atom[i]); -#else + vDSP_vdpsp(env, 1, &atom[0], 1, length); +#else for(uint i=0; i < length; i++) { - //gaussian envelope - atom[i] = exp((phase* phase) / gausDivisor); - phase += inc; + atom[i] = env[i]; } #endif +//#ifdef __APPLE_CC__ +// vDSP_vramp(&phase, &inc, &atom[0], 1, length); +// vDSP_vsq(&atom[0], 1, &atom[0], 1, length); +// vDSP_vsdiv(&atom[0], 1, &gausDivisor, &atom[0], 1, length); +// for(uint i=0; i < length; i++) atom[i] = exp(atom[i]); +//#else +// for(uint i=0; i < length; i++) { +// //gaussian envelope +// atom[i] = exp((phase* phase) / gausDivisor); +// phase += inc; +// } +//#endif + float cycleLen = sampleRate / freq; float maxPhase = length / cycleLen; - inc /= 2.0; + float inc = 1.0 / length; #ifdef __APPLE_CC__ flArr interpConstants; interpConstants.resize(length); - phase = 0.0; + float phase = 0.0; vDSP_vramp(&phase, &inc, &interpConstants[0], 1, length); vDSP_vsmsa(&interpConstants[0], 1, &maxPhase, &startPhase, &interpConstants[0], 1, length); float waveTableLength = 512; diff --git a/ofxMaxim/ofxMaxim/libs/maxiAtoms.h b/ofxMaxim/ofxMaxim/libs/maxiAtoms.h index b7ba354..dd6a41e 100644 --- a/ofxMaxim/ofxMaxim/libs/maxiAtoms.h +++ b/ofxMaxim/ofxMaxim/libs/maxiAtoms.h @@ -12,6 +12,8 @@ #include "maximilian.h" #include <list> #include <vector> +#include "maxiGrains.h" + using namespace std; @@ -37,8 +39,10 @@ class maxiCollider { public: static inline void createGabor(flArr &atom, const float freq, const float sampleRate, const uint length, float phase, const float kurtotis, const float amp); + static maxiGrainWindowCache<gaussianWinFunctor> envCache; }; + //queue atoms into an audio stream class maxiAccelerator { public: diff --git a/ofxMaxim/ofxMaxim/libs/maxiGrains.h b/ofxMaxim/ofxMaxim/libs/maxiGrains.h index dab90b9..f2f63b9 100644 --- a/ofxMaxim/ofxMaxim/libs/maxiGrains.h +++ b/ofxMaxim/ofxMaxim/libs/maxiGrains.h @@ -73,6 +73,24 @@ struct blackmanNutallWinFunctor { } }; +struct gaussianWinFunctor { + double gausDivisor; + gaussianWinFunctor() { + init(0.3); + } + gaussianWinFunctor(double kurtosis) { + init(kurtosis); + } + void init(double kurtosis) { + gausDivisor = (-2.0 * kurtosis * kurtosis); + } + inline double operator()(ulong windowLength, ulong windowPos) { + double phase = ((windowPos / (double) windowLength) - 0.5) * 2.0; + return exp((phase * phase) / gausDivisor); + } +}; + + template<typename F> class maxiGrainWindowCache { public: |
