SynthLab SDK
sinetablesource.h
Go to the documentation of this file.
1 #ifndef _SineSource_h
2 #define _SineSource_h
3 
4 #include "synthfunctions.h"
5 
6 // -----------------------------
7 // --- SynthLab SDK File --- //
8 // ----------------------------
16 // -----------------------------------------------------------------------------
17 namespace SynthLab
18 {
19 
40  {
41  public:
48  {
49  sineWavetable.dTable = &sinetable[0];
50  sineWavetable.tableLength = sineTableLength;
51  sineWavetable.wrapMask = sineTableLength - 1;
52  sineWavetable.waveformName = "sinewave";
53  }
54 
56 
60  virtual const char* getWaveformName() override
61  {
63  }
64 
69  inline virtual void selectTable(uint32_t midiNoteNumber) override { }
70 
79  inline virtual double readWaveTable(double normalizedPhaseInc) override
80  {
81  // --- two samples from table
82  double wtData[2] = { 0.0, 0.0 };
83 
84  // --- location = N(fo/fs)
85  double wtReadLocation = sineWavetable.tableLength * normalizedPhaseInc;
86 
87  // --- split the fractional index into int.frac parts
88  double dIntPart = 0.0;
89  double fracPart = modf(wtReadLocation, &dIntPart);
90  uint32_t readIndex = (uint32_t)dIntPart;
91  uint32_t nextReadIndex = (readIndex + 1) & sineWavetable.wrapMask;
92 
93  // --- two table reads
94  wtData[0] = sineWavetable.dTable[readIndex];
95  wtData[1] = sineWavetable.dTable[nextReadIndex];
96 
97  // --- interpolate the output
98  double output = doLinearInterpolation(wtData[0], wtData[1], fracPart);
99 
100  // --- scale as needed
101  return sineWavetable.outputComp * output;
102  }
103 
107  virtual uint32_t getWaveTableLength() override { return sineWavetable.tableLength; }
108 
109  protected:
110  // --- prefab table valid for all MIDI notes
112  };
113 
114 }
115 #endif // definer
116 
uint32_t tableLength
length
Definition: synthbase.h:1239
Interface for wavetable sources.
Definition: synthbase.h:609
double doLinearInterpolation(double x1, double x2, double y1, double y2, double x)
performs linear interpolation of x distance between two (x,y) points; returns interpolated value ...
Definition: synthfunctions.h:1387
uint32_t wrapMask
wrapping mask = length - 1
Definition: synthbase.h:1240
virtual const char * getWaveformName() override
Definition: sinetablesource.h:60
Storage for one static sinusoidal table source; stores a single sine table that is used for all notes...
Definition: sinetablesource.h:39
Definition: addosccore.cpp:4
Structure for holding information about a static wavetable, that is read from a static location...
Definition: synthbase.h:1208
virtual double readWaveTable(double normalizedPhaseInc) override
Read and interpolate the table; uses linear interpolation but could be changed to 4th order LaGrange ...
Definition: sinetablesource.h:79
virtual void selectTable(uint32_t midiNoteNumber) override
Nothing to do for this object since there is only one table.
Definition: sinetablesource.h:69
const char * waveformName
waveform name string
Definition: synthbase.h:1243
~SineTableSource()
emptu destructor
Definition: sinetablesource.h:55
double outputComp
output scaling factor (NOT volume or attenuation, waveform specific)
Definition: synthbase.h:1241
SineTableSource()
Stores the information about the static sinusoidal wavetable (see synthconstants.h) ...
Definition: sinetablesource.h:47
const double * dTable
table of 64-bit doubles
Definition: synthbase.h:1238
StaticWavetable sineWavetable
// — prefab table valid for all MIDI notes
Definition: sinetablesource.h:111
hard-coded arrays of FIR filter coefficients for the sample rate conversion objects (Interpolator and...
virtual uint32_t getWaveTableLength() override
Definition: sinetablesource.h:107