SynthLab SDK
synthlabwtsource.h
1 #ifndef _SynthLabWTSource_h
2 #define _SynthLabWTSource_h
3 
4 #include "synthfunctions.h"
5 
6 // -----------------------------
7 // --- SynthLab SDK File --- //
8 // ----------------------------
16 // -----------------------------------------------------------------------------
17 namespace SynthLab
18 {
40  {
41  public:
44 
48  virtual const char* getWaveformName() override
49  {
51  }
52 
57  inline virtual void selectTable(uint32_t midiNoteNumber) override
58  {
59  selectedTable = wavetableSet[midiNoteNumber];
60  }
61 
70  inline virtual double readWaveTable(double normalizedPhaseInc) override
71  {
72  // --- two samples from table
73  double wtData[2] = { 0.0, 0.0 };
74 
75  // --- location = N(fo/fs)
76  double wtReadLocation = selectedTable.tableLength * normalizedPhaseInc;
77 
78  // --- split the fractional index into int.frac parts
79  //double dIntPart = 0.0;
80  //double fracPart = modf(wtReadLocation, &dIntPart);
81  uint32_t readIndex = (uint32_t)wtReadLocation;
82  uint32_t nextReadIndex = (readIndex + 1) & selectedTable.wrapMask;
83 
84  // --- two table reads
85  uint64_t u0 = selectedTable.uTable[readIndex];
86  uint64_t u1 = selectedTable.uTable[nextReadIndex];
87  wtData[0] = *(reinterpret_cast<double*>(&u0));
88  wtData[1] = *(reinterpret_cast<double*>(&u1));
89 
90  // --- interp
91  double fracPart = wtReadLocation - readIndex;
92  double output = doLinearInterpolation(wtData[0], wtData[1], fracPart);
93 
94  // --- scale as needed
95  return selectedTable.outputComp * output;
96  }
97 
101  virtual uint32_t getWaveTableLength() override { return selectedTable.tableLength; }
102 
113  inline void addSynthLabTableSet(SynthLabTableSet* synthLabTableSet)
114  {
115  for (uint32_t i = 0; i < NUM_MIDI_NOTES; i++)
116  {
117  StaticWavetable wt(synthLabTableSet->ppHexTableSet[i],
118  synthLabTableSet->tableLengths[i],
119  synthLabTableSet->waveformName,
120  synthLabTableSet->outputComp,
121  synthLabTableSet->tableFs);
122 
123  wavetableSet[i] = wt;
124  }
125  // --- set a default table
127  }
128 
129  protected:
130  // --- 128 wavetables
133  };
134 
152  {
153  public:
156 
160  virtual const char* getWaveformName() override
161  {
162  return drumTable.waveformName;
163  }
164 
169  inline virtual void selectTable(uint32_t midiNoteNumber) override { }
170 
179  inline virtual double readWaveTable(double normalizedPhaseInc) override
180  {
181  // --- core must calculate correct oscClocking (its easy)
182  double wtReadLocation = drumTable.tableLength * normalizedPhaseInc;
183  double output = 0.0;
184 
185  if (drumTable.dTable)
186  output = drumTable.dTable[(uint32_t)wtReadLocation];
187  else
188  {
189  // --- two table reads
190  uint64_t u0 = drumTable.uTable[(uint32_t)wtReadLocation];
191  output = *(reinterpret_cast<double*>(&u0));
192  }
193 
194  // --- scale as needed
195  return drumTable.outputComp * output;
196  }
197 
201  virtual uint32_t getWaveTableLength() override { return drumTable.tableLength; }
202 
213  inline void addWavetable(const double* _table, uint32_t length, const char* name, double outputComp = 1.0)
214  {
215  // --- create the static table
216  StaticWavetable wt(_table, length, name, outputComp);
217  drumTable = wt;
218  }
219 
230  inline void addWavetable(const uint64_t* _table, uint32_t length, const char* name, double outputComp = 1.0)
231  {
232  // --- create the static table
233  StaticWavetable wt(_table, length, name, outputComp);
234  drumTable = wt;
235  }
236 
237  protected:
238  // --- one table per source
240  };
241 
242 
255  {
256  std::string bankName = empty_string.c_str();
257  uint32_t numTables = 1;
258  std::string tableNames[MODULE_STRINGS];
259  int32_t tableIndexes[MODULE_STRINGS] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 };
260  StaticTableSource staticSources[MODULE_STRINGS];
261  };
262 }
263 #endif // definer
264 
uint32_t tableLength
length
Definition: synthbase.h:1239
const uint32_t MIDI_NOTE_A4
Definition: synthconstants.h:620
virtual const char * getWaveformName() override
Definition: synthlabwtsource.h:48
uint32_t numTables
number of wavetables in bank (up to 16)
Definition: synthlabwtsource.h:257
int32_t tableIndexes[MODULE_STRINGS]
unique indexes for faster lookup
Definition: synthlabwtsource.h:259
double outputComp
output scaling factor
Definition: synthbase.h:1146
StaticWavetable drumTable
one table per drum
Definition: synthlabwtsource.h:239
Interface for wavetable sources.
Definition: synthbase.h:609
std::string tableNames[MODULE_STRINGS]
names of wavetables
Definition: synthlabwtsource.h:258
Storage for one static table source, specifically for drums which are pitchless and one-shot...
Definition: synthlabwtsource.h:151
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
DrumWTSource()
empty constructor
Definition: synthlabwtsource.h:154
virtual uint32_t getWaveTableLength() override
Definition: synthlabwtsource.h:101
const char * waveformName
string for the GUI
Definition: synthbase.h:1149
uint32_t wrapMask
wrapping mask = length - 1
Definition: synthbase.h:1240
Information about a bank of wavetables that are used in the morphing wavetable core.
Definition: synthlabwtsource.h:254
Definition: addosccore.cpp:4
const uint32_t MODULE_STRINGS
Definition: synthconstants.h:130
uint32_t * tableLengths
pointers to lengths of each of the hex encoded tables
Definition: synthbase.h:1139
Structure for holding information about a static wavetable, that is read from a static location...
Definition: synthbase.h:1208
virtual uint32_t getWaveTableLength() override
Definition: synthlabwtsource.h:201
StaticWavetable wavetableSet[NUM_MIDI_NOTES]
— prefab table valid for all MIDI notes
Definition: synthlabwtsource.h:131
const char * waveformName
waveform name string
Definition: synthbase.h:1243
double outputComp
output scaling factor (NOT volume or attenuation, waveform specific)
Definition: synthbase.h:1241
virtual void selectTable(uint32_t midiNoteNumber) override
Select a table based on MIDI note number; nothing to do here.
Definition: synthlabwtsource.h:169
const double * dTable
table of 64-bit doubles
Definition: synthbase.h:1238
virtual const char * getWaveformName() override
Definition: synthlabwtsource.h:160
virtual double readWaveTable(double normalizedPhaseInc) override
Read and interpolate the table; uses linear interpolation but could be changed to 4th order LaGrange ...
Definition: synthlabwtsource.h:179
StaticTableSource()
empty constructor
Definition: synthlabwtsource.h:42
const uint32_t NUM_MIDI_NOTES
Definition: synthconstants.h:618
Storage for one static table source; a static table is pre-compiled into the synth, or (optionally) read from a file. The "source" stores a set of these tables to maximize frequency content while prohibiting aliasing.
Definition: synthlabwtsource.h:39
virtual double readWaveTable(double normalizedPhaseInc) override
Read and interpolate the table; uses linear interpolation but could be changed to 4th order LaGrange ...
Definition: synthlabwtsource.h:70
const std::string empty_string
Definition: synthconstants.h:184
StaticWavetable selectedTable
— selected table, stored here
Definition: synthlabwtsource.h:132
void addWavetable(const uint64_t *_table, uint32_t length, const char *name, double outputComp=1.0)
Adds a new wavetable to the array of 128 tables, one for each MIDI note.
Definition: synthlabwtsource.h:230
const uint64_t * uTable
table of 64-bit HEX values
Definition: synthbase.h:1237
~StaticTableSource()
empty destructor
Definition: synthlabwtsource.h:43
std::string bankName
one name for bank
Definition: synthlabwtsource.h:256
void addSynthLabTableSet(SynthLabTableSet *synthLabTableSet)
Adds a new SET of wavetables to the array of 128 tables, one for each MIDI note.
Definition: synthlabwtsource.h:113
This structure defines a set of wavetables that are usually found in .h files and compiled into the s...
Definition: synthbase.h:1126
hard-coded arrays of FIR filter coefficients for the sample rate conversion objects (Interpolator and...
uint64_t ** ppHexTableSet
pointers to sets of hex encoded tables
Definition: synthbase.h:1140
~DrumWTSource()
empty destructor
Definition: synthlabwtsource.h:155
void addWavetable(const double *_table, uint32_t length, const char *name, double outputComp=1.0)
Adds a new wavetable to the array of 128 tables, one for each MIDI note.
Definition: synthlabwtsource.h:213
virtual void selectTable(uint32_t midiNoteNumber) override
Select a table based on MIDI note number.
Definition: synthlabwtsource.h:57