21 IOscillator(
double startPhase = 0.,
double startFreq = 1.)
23 , mStartPhase(startPhase)
25 SetFreqCPS(startFreq);
28 virtual inline T Process(
double freqHz) = 0;
30 inline void SetFreqCPS(
double freqHz)
32 mPhaseIncr = (1./mSampleRate) * freqHz;
35 void SetSampleRate(
double sampleRate)
37 mSampleRate = sampleRate;
45 void SetPhase(
double phase)
52 double mPhaseIncr = 0.;
53 double mSampleRate = 44100.;
72 inline T Process(
double freqHz)
override
114#define UNITBIT32 1572864.
119#define ALIGN16 __declspec(align(16))
122#define ALIGN16 alignas(16)
123#define ALIGNED(x) __attribute__ ((aligned (x)))
144 ProcessBlock(&output, 1);
149 inline T Process(
double freqCPS)
override
154 ProcessBlock(&output, 1);
159 static inline T Lookup(
double phaseRadians)
161 double tPhase = phaseRadians / (PI * 2.) * tableSize;
163 tPhase += (double) UNITBIT32;
167 const int normhipart = tf.i[HIOFFSET];
170 const T* addr = mLUT + (tf.i[HIOFFSET] & tableSizeM1);
171 tf.i[HIOFFSET] = normhipart;
172 const double frac = tf.d - UNITBIT32;
173 const T f1 = addr[0];
174 const T f2 = addr[1];
175 return f1 + frac * (f2 - f1);
178 void ProcessBlock(T* pOutput,
int nFrames)
185 const int normhipart = tf.i[HIOFFSET];
187 for (
auto s = 0; s < nFrames; s++)
190 const int index = tf.i[HIOFFSET] & tableSizeM1;
191 const T* addr = mLUT + index;
192 tf.i[HIOFFSET] = normhipart;
193 const double frac = tf.d - UNITBIT32;
194 phase = tf.d + index + phaseIncr;
195 const T f1 = addr[0];
196 const T f2 = addr[1];
197 mLastOutput = pOutput[s] = T(f1 + frac * (f2 - f1));
201 tf.d = UNITBIT32 * tableSize;
202 const int normhipart2 = tf.i[HIOFFSET];
203 tf.d = phase + (UNITBIT32 * tableSize - UNITBIT32);
204 tf.i[HIOFFSET] = normhipart2;
210 static const int tableSize = 512;
211 static const int tableSizeM1 = 511;
212 static const T mLUT[513];
215#include "Oscillator_table.h"