21 IOscillator(
double startPhase = 0.,
double startFreq = 1.)
22 : mStartPhase(startPhase)
24 SetFreqCPS(startFreq);
27 virtual inline T Process(
double freqHz) = 0;
29 inline void SetFreqCPS(
double freqHz)
31 mPhaseIncr = (1./mSampleRate) * freqHz;
34 void SetSampleRate(
double sampleRate)
36 mSampleRate = sampleRate;
44 void SetPhase(
double phase)
51 double mPhaseIncr = 0.;
52 double mSampleRate = 44100.;
71 inline T Process(
double freqHz)
override
113#define UNITBIT32 1572864.
118#define ALIGN16 __declspec(align(16))
121#define ALIGN16 alignas(16)
122#define ALIGNED(x) __attribute__ ((aligned (x)))
143 ProcessBlock(&output, 1);
148 inline T Process(
double freqCPS)
override
153 ProcessBlock(&output, 1);
158 static inline T Lookup(
double phaseRadians)
160 double tPhase = phaseRadians / (PI * 2.) * tableSizeM1;
162 tPhase += (double) UNITBIT32;
166 const int normhipart = tf.i[HIOFFSET];
169 const T* addr = mLUT + (tf.i[HIOFFSET] & tableSizeM1);
170 tf.i[HIOFFSET] = normhipart;
171 const double frac = tf.d - UNITBIT32;
172 const T f1 = addr[0];
173 const T f2 = addr[1];
174 return f1 + frac * (f2 - f1);
177 void ProcessBlock(T* pOutput,
int nFrames)
184 const int normhipart = tf.i[HIOFFSET];
186 for (
auto s = 0; s < nFrames; s++)
190 const T* addr = mLUT + (tf.i[HIOFFSET] & tableSizeM1);
191 tf.i[HIOFFSET] = normhipart;
192 const double frac = tf.d - UNITBIT32;
193 const T f1 = addr[0];
194 const T f2 = addr[1];
195 mLastOutput = pOutput[s] = T(f1 + frac * (f2 - f1));
199 tf.d = UNITBIT32 * tableSize;
200 const int normhipart2 = tf.i[HIOFFSET];
201 tf.d = phase + (UNITBIT32 * tableSize - UNITBIT32);
202 tf.i[HIOFFSET] = normhipart2;
208 static const int tableSize = 512;
209 static const int tableSizeM1 = 511;
210 static const T mLUT[513];
213#include "Oscillator_table.h"