[IPlug/EXAMPLES] upgrade all vs projects to vs2013
[wdl/wdl-ol.git] / IPlugExamples / IPlugMouseTest / IPlugMouseTestDSP.h
blobc9c21b1298f6b3f0ab24f04b5feaf17b41a70610
1 #ifndef __IPLUGMOUSETESTDSP_H__
2 #define __IPLUGMOUSETESTDSP_H__
4 inline double midi2CPS(double pitch)
6 return 440. * pow(2., (pitch - 69.) / 12.);
9 inline double wrap(double x, double low = 0., double high = 1.)
11 while (x >= high) x -= high;
12 while (x < low) x += high - low;
14 return x;
17 inline double lerp(double phase, const double* buffer, unsigned long int mask)
19 const int intPart = (int) phase;
20 const double fracPart = phase-intPart;
22 const double a = buffer[intPart & mask];
23 const double b = buffer[(intPart+1) & mask];
25 return a + (b - a) * fracPart;
28 struct CWTOscState
30 double mPhase; // float phase (goes between 0. and 1.)
31 double mPhaseIncr; // freq * mPhaseStep
33 CWTOscState()
35 mPhase = 0.;
36 mPhaseIncr = 0.;
39 } WDL_FIXALIGN;
41 class CWTOsc
43 protected:
44 const double* mLUT; // pointer to waveform lookup table, const because the oscilator doesn't change the table data
45 unsigned long int mLUTSize; // wavetable size
46 unsigned long int mLUTSizeM; // wavetable Mask (size -1)
47 double mLUTSizeF; // float version
49 public:
51 CWTOsc(const double* LUT, unsigned long int LUTSize)
53 setLUT(LUT, LUTSize);
56 ~CWTOsc() {}
58 void setLUT(const double* LUT, unsigned long int LUTSize)
60 mLUTSize = LUTSize;
61 mLUTSizeM = LUTSize-1;
62 mLUTSizeF = (double) LUTSize;
63 mLUT = LUT;
66 inline double process(CWTOscState* pState)
68 pState->mPhase = wrap(pState->mPhase, 0., 1.);
69 const double output = lerp(pState->mPhase * mLUTSizeF, mLUT, mLUTSizeM);
70 pState->mPhase += pState->mPhaseIncr;
72 return output;
75 } WDL_FIXALIGN;
77 #endif // __IPLUGMOUSETESTDSP_H__