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
;
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
;
30 double mPhase
; // float phase (goes between 0. and 1.)
31 double mPhaseIncr
; // freq * mPhaseStep
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
51 CWTOsc(const double* LUT
, unsigned long int LUTSize
)
58 void setLUT(const double* LUT
, unsigned long int LUTSize
)
61 mLUTSizeM
= LUTSize
-1;
62 mLUTSizeF
= (double) LUTSize
;
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
;
77 #endif // __IPLUGMOUSETESTDSP_H__