SynthLab SDK
synthbase.h
Go to the documentation of this file.
1 #ifndef __synthBase_h__
2 #define __synthBase_h__
3 
4 #include <cmath>
5 #include <random>
6 #include <string>
7 #include <sstream>
8 #include <vector>
9 #include <stdint.h>
10 #include <memory>
11 #include <algorithm>
12 #include <map>
13 
14 #include "synthstructures.h"
15 #include "synthlabparams.h"
16 
17 #define _MATH_DEFINES_DEFINED
18 
19 // -----------------------------
20 // --- SynthLab SDK File --- //
21 // ----------------------------
29 // -----------------------------------------------------------------------------
30 namespace SynthLab
31 {
37  struct DMConfig
38  {
39  bool dm_build = false;
40  bool dual_mono_filters = false;
41  bool half_sample_set = false;
42  bool reduced_unison_count = false;
43  bool analog_fgn_filters = false;
44  bool parameterSmoothing = true;
45  };
46 
47  // ---------------------- SYNTH OBJECTS WITHOUT BASE CLASES --------------------------------------------- //
48  //
49  /*
50  These are simple, stand-alone objects or primary synth objects that perform intrinsically
51  basic/fundamental synth operations.
52 
53  Many of these are used as base classes for extended objects.
54 
55  These are NOT interfaces, which are defined in a separate section of this file.
56  */
57  //
58  // ------------------------------------------------------------------------------------------------------- //
59 
81  {
82  public:
83  AudioBuffer() {}
84  AudioBuffer(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
85  ~AudioBuffer();
86 
88  void init(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
89  void flushBuffers();
90 
92  float* getInputBuffer(uint32_t channel);
93  float* getOutputBuffer(uint32_t channel);
94 
96  float** getInputBuffers() { return inputBuffer; }
97  float** getOutputBuffers() { return outputBuffer; }
98 
100  uint32_t getInputChannelCount() { return numInputChannels; }
101  uint32_t getOutputChannelCount() { return numOutputChannels; }
102 
104  uint32_t getBlockSize() { return blockSize; }
105  uint32_t getSamplesInBlock() { return samplesInBlock; }
106  void setSamplesInBlock(uint32_t _samplesInBlock);
107 
108  protected:
109  void destroyInputBuffers();
110  void destroyOutputBuffers();
111  float** inputBuffer = nullptr;
112  float** outputBuffer = nullptr;
113  uint32_t numInputChannels = 1;
114  uint32_t numOutputChannels = 1;
115  uint32_t blockSize = 64;
116  uint32_t samplesInBlock = 64;
117  };
118 
119 
138  {
139  public:
140  SynthClock() {}
141  ~SynthClock() {}
142  SynthClock& operator=(const SynthClock& params);
143 
145  void reset(double startValue = 0.0);
146  void initWithClock(SynthClock& clock);
147 
149  void advanceClock(uint32_t renderInterval = 1);
150  bool advanceWrapClock(uint32_t renderInterval = 1);
151  bool wrapClock();
152 
154  void setFrequency(double _frequency_Hz, double _sampleRate);
155  double getFrequency() { return frequency_Hz; }
156 
158  void addPhaseOffset(double _phaseOffset, bool wrap = true);
159  void removePhaseOffset();
160 
162  void addFrequencyOffset(double _freqOffset);
163  void removeFrequencyOffset();
164 
166  void saveState();
167  void restoreState();
168 
169  public: // for fastest access
170  double mcounter = 0.0;
171  double phaseInc = 0.0;
172  double phaseOffset = 0.0;
173  double freqOffset = 0.0;
174  double frequency_Hz = 0.0;
175  double sampleRate = 0.0;
176  enum { MOD_COUNTER, PHASE_INC, PHASE_OFFSET, FREQUENCY_HZ, NUM_VARS };
177  double state[NUM_VARS] = { 0.0, 0.0, 0.0, 0.0 };
178  };
179 
195  class Timer
196  {
197  public:
198  Timer() {}
199  ~Timer() {}
200 
202  void resetTimer() { counter = 0; }
203 
205  void setExpireSamples(uint32_t _targetValueInSamples) { targetValueInSamples = _targetValueInSamples; }
206  void setExpireMilliSec(double timeMSec, double sampleRate) { setExpireSamples( ((uint32_t)(sampleRate*(timeMSec / 1000.0))) ); }
207 
209  uint32_t getExpireSamples() { return targetValueInSamples; }
210 
212  bool timerExpired() { return (counter >= targetValueInSamples); }
213 
215  void advanceTimer(uint32_t ticks = 1) { counter += ticks; }
216  uint32_t getTick() { return counter; }
217 
218  protected:
219  uint32_t counter = 0;
220  uint32_t targetValueInSamples = 0;
221  };
222 
239  class XFader
240  {
241  public:
242  XFader() {}
243  XFader(uint32_t _xfadeTime_Samples);
244 
246  void reset();
247 
249  void setXFadeTime(uint32_t _xfadeTime_Samples);
250  void startCrossfade() { running = true; }
251  void stopCrossfade() { running = false; }
252  bool isCrossfading() { return running; }
253 
254  // --- crossfade FROM A to B
255  // returns TRUE if the crossfade is still going (needs more samples)
256  // FALSE if the crossfade is finished (done)
257  bool crossfade(XFadeType xfadeType, double inputA, double inputB, double& output);
258 
259  protected:
260  uint32_t xfadeTime_Samples = 4410;
261  uint32_t xfadeTime_Counter = 0;
262  bool running = false;
263  };
264 
265 
284  {
285  public:
286  XHoldFader() {}
287  ~XHoldFader() {}
288 
289  // --- fader functions
290  void reset();
291 
293  inline void setXFadeTimeSamples(uint32_t _xfadeTimeSamples){ xfadeTime_Samples = _xfadeTimeSamples; }
294  inline uint32_t getXFadeTimeSamples(){ return xfadeTime_Samples; }
295 
297  void setHoldTimeSamples(double _holdTimeSamples);
298  inline double getHoldTimeSamples() { return holdTime_Samples; }
299 
301  XFadeData getCrossfadeData();
302 
303  protected:
304  uint32_t xfadeTime_Samples = 4410;
305  uint32_t xfadeTime_Counter = 0;
306  uint32_t holdTime_Samples = 4410;
307  uint32_t holdTime_Counter = 0;
308  bool holding = false;
309  };
310 
311 
326  {
327  public:
328  SlewLimiter() {}
329  ~SlewLimiter() {}
330 
331  // --- slewing functions
332  void reset() { z1 = 0; }
333 
334  // --- slew value is: 0 <= slewvalue <= 0.9999
335  void setSlewValue(double _g) { g = _g; }
336  inline double doSlewLimiter(double input)
337  {
338  double output = input*(1.0 - g) + g*z1;
339  z1 = output;
340  return output;
341  }
342 
343  protected:
344  double g = 0;
345  double z1 = 0.0;
346  };
347 
348 
366  {
367  public:
368  Synchronizer() {}
369  ~Synchronizer() {}
370 
372  bool reset(double _sampleRate, double startPhase, int32_t xfadeSamples = 16);
373 
376  SynthClock& getHardSyncClock() { return hardSyncClock; }
377  SynthClock& getCrossFadeClock() { return crossFadeClock; }
378  void startHardSync(SynthClock oscClock);
379  double doHardSyncXFade(double inA, double inB);
380  bool isProcessing() { return hardSyncFader.isCrossfading(); }
381 
383  void addPhaseOffset(double offset);
384  void removePhaseOffset();
385 
386  protected:
390  double hardSyncFrequency = 440.0;
391  double sampleRate = 44100.0;
392  };
393 
394 
413  {
414  public:
415  RampModulator() {}
416  ~RampModulator() {}
417 
419  bool startModulator(double startValue, double endValue, double modTime_mSec, double sampleRate);
420 
422  bool setModTime(double modTime_mSec, double sampleRate);
423 
425  double getNextModulationValue(uint32_t advanceClock = 1);
426 
428  void advanceClock(uint32_t ticks = 1);
429  inline bool isActive() { return timerActive; }
430 
431  protected:
432  bool timerActive = false;
433  double timerInc = 0.0;
434  double countUpTimer = 0.0;
435  double modRange = 1.0;
436  double modStart = 0.0;
437  double modEnd = 1.0;
438  };
439 
458  {
459  public:
460  GlideModulator() {}
461  ~GlideModulator() {}
462 
464  bool startModulator(double startNote, double endNote, double glideTime_mSec, double sampleRate);
465 
467  bool setGlideTime(double glideTime_mSec, double sampleRate);
468 
470  double getNextModulationValue(uint32_t advanceClock = 1);
471 
473  void advanceClock(uint32_t ticks = 1);
474  inline bool isActive() { return timerActive; }
475 
476  protected:
477  bool timerActive = false;
478  double timerInc = 0.0;
479  double countDownTimer = 1.0;
480  double glideRange = 1.0;
481  };
482 
496  {
497  public:
498  NoiseGenerator() {}
499  ~NoiseGenerator() {}
500 
502  std::default_random_engine defaultGeneratorEngine;
503 
505  double doGaussianWhiteNoise(double mean = 0.0, double variance = 1.0);
506  double doWhiteNoise();
507  double doPinkNoise();
508  double doPinkingFilter(double white);
509 
510  protected:
512  double bN[3] = { 0.0, 0.0, 0.0 };
513 
514  // --- another method of white noise, faster
515  float g_fScale = 2.0f / 0xffffffff;
516  int g_x1 = 0x67452301;
517  int g_x2 = 0xefcdab89;
518  };
519 
520  // ---------------------- SYNTH INTERFACE OBJECTS-------------------------------------------------------- //
521  //
522  /*
523  These are pure abstrace interfaces to be used as base classes for the synth objects. These allow
524  container objects to hold (shared) simple interface pointers, or the actual object pointers; all
525  object interfacing is done through the common objec model interfaces here.
526  */
527  //
528  // ------------------------------------------------------------------------------------------------------- //
529 
552  {
553  public:
562  virtual double* getModArrayPtr(uint32_t index) = 0;
563 
572  virtual double getModValue(uint32_t index) = 0;
573 
583  virtual void setModValue(uint32_t index, double value) = 0;
584  };
585 
586  // ---------------------- WAVETABLES --------------------------------------------------------- //
610  {
611  public:
620  virtual void selectTable(uint32_t midiNoteNumber) = 0;
621 
631  virtual double readWaveTable(double normalizedPhaseInc) = 0;
632 
636  virtual uint32_t getWaveTableLength() = 0;
637 
638 
642  virtual const char* getWaveformName() = 0;
643 
645  //\return the table index (unique) for faster iteration (OPTIONAL), or -1 if not found
646  //*/
647  //virtual int32_t getWaveformIndex() { return -1; }
648  };
649 
670  {
671  public:
680  virtual IWavetableSource* getTableSource(const char* uniqueTableName) = 0;
681  virtual IWavetableSource* getTableSource(uint32_t uniqueTableIndex) { return nullptr; }
682 
692  virtual bool addTableSource(const char* uniqueTableName, IWavetableSource* tableSource, uint32_t& uniqueIndex) = 0;
693 
701  virtual bool removeTableSource(const char* uniqueTableName) = 0;
702 
709  virtual bool clearTableSources() = 0;
710 
714  virtual int32_t getWaveformIndex(const char* uniqueTableName) { return -1; }
715  };
716 
717 
718  // ---------------------- PCM SAMPLES --------------------------------------------------------- //
734  {
735  double audioOutput[STEREO_CHANNELS] = { 0.0, 0.0 };
736  uint32_t numActiveChannels = 0;
737  };
738 
741  enum class SampleLoopMode { loop, sustain, oneShot };
742 
767  {
768  public:
775  virtual double selectSample(double oscFrequency) = 0;
776 
787  virtual PCMSampleOutput readSample(double& readIndex, double inc) = 0;
788 
798  virtual void setSampleLoopMode(SampleLoopMode _loopMode) = 0;
799 
804  virtual void deleteSamples() = 0;
805 
810  virtual uint32_t getValidSampleCount() = 0;
811 
816  virtual bool haveValidSamples() = 0;
817  };
818 
839  {
840  public:
850  virtual IPCMSampleSource* getSampleSource(const char* uniqueSampleSetName) = 0;
851 
861  virtual bool addSampleSource(const char* uniqueSampleSetName, IPCMSampleSource* sampleSource) = 0;
862 
863 
872  virtual bool removeSampleSource(const char* uniqueSampleSetName) = 0;
873 
880  virtual bool clearSampleSources() = 0;
881  };
882 
905  {
906  public:
918  virtual uint32_t getGlobalMIDIData(uint32_t index) = 0;
919 
931  virtual uint32_t getCCMIDIData(uint32_t index) = 0;
932 
941  virtual uint32_t getAuxDAWDataUINT(uint32_t index) = 0;
942 
951  virtual float getAuxDAWDataFloat(uint32_t index) = 0;
952  };
953 
957  enum { LPF1, LPF2, LPF3, LPF4, HPF1, HPF2, HPF3, HPF4, BPF2, BPF4, BSF2, BSF4,
958  APF1, APF2, ANM_LPF1, ANM_LPF2, ANM_LPF3, ANM_LPF4, NUM_FILTER_OUTPUTS };
959 
961 
966  const double GUI_Q_MIN = 1.0;
967  const double GUI_Q_MAX = 10.0;
968  const double SVF_Q_SLOPE = (25.0 - 0.707) / (GUI_Q_MAX - GUI_Q_MIN);
969  const double KORG35_Q_SLOPE = (2.0 - 0.707) / (GUI_Q_MAX - GUI_Q_MIN);
970  const double MOOG_Q_SLOPE = (4.0 - 0.0) / (GUI_Q_MAX - GUI_Q_MIN);
971  const double DIODE_Q_SLOPE = (17.0 - 0.0) / (GUI_Q_MAX - GUI_Q_MIN);
972  const double HSYNC_MOD_SLOPE = 3.0;
974 
989  {
990  FilterOutput() { clearData(); }
991  double filter[NUM_FILTER_OUTPUTS];
992  void clearData()
993  {
994  memset(&filter[0], 0, sizeof(double) * NUM_FILTER_OUTPUTS);
995  }
996  };
997 
998 
1018  {
1026  virtual bool reset(double _sampleRate) = 0;
1027 
1034  virtual bool update() = 0;
1035 
1043  virtual FilterOutput* process(double xn) = 0;
1044 
1052  virtual void setFilterParams(double _fc, double _Q) = 0;
1053  };
1054 
1055 
1072  {
1076 
1078  float** inputBuffers = nullptr;
1079  float** outputBuffers = nullptr;
1080  float** fmBuffers = nullptr;
1081 
1086  void* moduleParameters = nullptr;
1087  const char* dllPath = nullptr;
1088 
1089  double sampleRate = 0.0;
1090  uint32_t samplesToProcess = 64;
1091  double unisonDetuneCents = 0.0;
1092  double unisonStartPhase = 0.0;
1093 
1094  double BPM = 120.0;
1096  };
1097 
1098  // ----------------------------------- SYNTH OBJECTS ----------------------------------------------------- //
1099  //
1100  /*
1101  Fundamental objects that are used throughout SynthLab
1102  */
1103  //
1104  // ------------------------------------------------------------------------------------------------------- //
1105 
1127  {
1128  // --- multi initializer construction
1129  SynthLabTableSet(const char* _waveformName, double _tableFs,
1130  uint32_t* _tableLengths, uint64_t** _ppHexTableSet, double _outputComp)
1131  : waveformName(_waveformName)
1132  , tableFs(_tableFs)
1133  , tableLengths(_tableLengths)
1134  , ppHexTableSet(_ppHexTableSet)
1135  , outputComp(_outputComp)
1136  { }
1137 
1138  // --- ptr to array of table lengths
1139  uint32_t* tableLengths = nullptr;
1140  uint64_t** ppHexTableSet = nullptr;
1141 
1142  // --- fs for this table set
1143  double tableFs = 44100.0;
1144 
1145  // --- output scaling factor (NOT volume or attenuation, waveform specific)
1146  double outputComp = 1.0;
1147 
1148  // --- GUI string for this waveform
1149  const char* waveformName;
1150  };
1151 
1152  // --- fwd decl
1153  class StaticTableSource;
1174  {
1175  SynthLabBankSet(unsigned int _tablePtrsCount, SynthLabTableSet** _tablePtrs, std::string* _tableNames, StaticTableSource* _staticSources = nullptr)
1176  : tablePtrsCount(_tablePtrsCount)
1177  , tablePtrs(_tablePtrs)
1178  , tableNames(_tableNames)
1179  , staticSources(_staticSources) {}
1180 
1181  unsigned int tablePtrsCount = 32;
1183  std::string* tableNames = nullptr;
1184  StaticTableSource* staticSources = nullptr;
1185  };
1186 
1190  const uint32_t kDefaultWaveTableLength = 256;
1191 
1209  {
1210  StaticWavetable() {}
1211 
1212  StaticWavetable(const uint64_t* _table, uint32_t _tableLength, const char* _waveformName,
1213  double _outputComp = 1.0, double _tableFs = 44100)
1214  : uTable(_table)
1215  , tableLength(_tableLength)
1216  , waveformName(_waveformName)
1217  , outputComp(_outputComp)
1218  , tableFs(_tableFs)
1219  {
1220  wrapMask = tableLength - 1;
1221  dTable = nullptr;
1222  }
1223 
1224  StaticWavetable(const double* _table, uint32_t _tableLength, const char* _waveformName,
1225  double _outputComp = 1.0, double _tableFs = 44100)
1226  : dTable(_table)
1227  , tableLength(_tableLength)
1228  , waveformName(_waveformName)
1229  , outputComp(_outputComp)
1230  , tableFs(_tableFs)
1231  {
1232  wrapMask = tableLength - 1;
1233  uTable = nullptr;
1234  }
1235 
1236  // --- either/or static tables
1237  const uint64_t* uTable;
1238  const double* dTable;
1241  double outputComp = 1.0;
1242  double tableFs = 44100.0;
1243  const char* waveformName;
1244  };
1245 
1265  {
1266  DynamicWavetable() {}
1267 
1268  DynamicWavetable(std::shared_ptr<double> _table, uint32_t _tableLength, const char* _waveformName,
1269  double _outputComp = 1.0, double _tableFs = 44100)
1270  : table(_table)
1271  , tableLength(_tableLength)
1272  , waveformName(_waveformName)
1273  , outputComp(_outputComp)
1274  , tableFs(_tableFs)
1275  {
1276  wrapMask = tableLength - 1;
1277  }
1278 
1279  std::shared_ptr<double> table = nullptr;
1282  double outputComp = 1.0;
1283  double tableFs = 44100.0;
1284  const char* waveformName;
1285  };
1286 
1287 
1306  {
1307  public:
1308  WavetableDatabase() {}
1310 
1312  virtual IWavetableSource* getTableSource(const char* uniqueTableName) override;
1313  virtual IWavetableSource* getTableSource(uint32_t uniqueTableIndex) override;
1314  virtual bool addTableSource(const char* uniqueTableName, IWavetableSource* tableSource, uint32_t& uniqueIndex) override;
1315  virtual bool removeTableSource(const char* uniqueTableName) override;
1316  virtual bool clearTableSources() override;
1317  virtual int32_t getWaveformIndex(const char* uniqueTableName) override;
1318 
1321 
1322  protected:
1323  typedef std::map < std::string, IWavetableSource* > wavetableSourceMap;
1324  wavetableSourceMap wavetableDatabase;
1325  std::vector<IWavetableSource*> wavetableVector;
1326  };
1327 
1328 
1347  {
1348  public:
1349  PCMSampleDatabase() {}
1351 
1353  virtual IPCMSampleSource* getSampleSource(const char* uniqueSampleSetName) override;
1354  virtual bool addSampleSource(const char* uniqueSampleSetName, IPCMSampleSource* sampleSource) override;
1355  virtual bool removeSampleSource(const char* uniqueSampleSetName) override;
1356  virtual bool clearSampleSources() override;
1357 
1360 
1361  protected:
1362  typedef std::map < std::string, IPCMSampleSource* >sampleSourceMap;
1363  sampleSourceMap sampleDatabase;
1364  std::vector<IPCMSampleSource*> sources;
1365  };
1366 
1385  {
1386  public:
1387  SynthProcessInfo(){}
1388  SynthProcessInfo(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
1389  ~SynthProcessInfo() {}
1390 
1392  void pushMidiEvent(midiEvent event);
1393  void clearMidiEvents();
1394  uint64_t getMidiEventCount();
1395  midiEvent* getMidiEvent(uint32_t index);
1396 
1398  double absoluteBufferTime_Sec = 0.0;
1399  double BPM = 0.0;
1400  double timeSigNumerator = 0.0;
1401  uint32_t timeSigDenomintor = 0;
1402 
1403  protected:
1405  std::vector<midiEvent> midiEventQueue;
1406  };
1407 
1424  {
1425  public:
1426  MidiInputData();
1427  ~MidiInputData() {}
1428 
1430  virtual uint32_t getGlobalMIDIData(uint32_t index);
1431  virtual uint32_t getCCMIDIData(uint32_t index);
1432  virtual uint32_t getAuxDAWDataUINT(uint32_t index);
1433  virtual float getAuxDAWDataFloat(uint32_t index);
1434 
1436  void setGlobalMIDIData(uint32_t index, uint32_t value);
1437  void setCCMIDIData(uint32_t index, uint32_t value);
1438  void setAuxDAWDataUINT(uint32_t index, uint32_t value);
1439  void setAuxDAWDataFloat(uint32_t index, float value);
1440 
1442  IMidiInputData* getIMIDIInputData() { return this; }
1443 
1444  protected:
1445  // --- shared MIDI tables, via IMIDIData
1446  uint32_t globalMIDIData[kNumMIDIGlobals];
1448  double auxData[kNumMIDIAuxes];
1449  };
1450 
1467  class Modulators : public IModulator
1468  {
1469  public:
1470  Modulators();
1471 
1473  virtual double* getModArrayPtr(uint32_t index);
1474  virtual double getModValue(uint32_t index);
1475  virtual void setModValue(uint32_t index, double value);
1476 
1477  // --- fast clearing of array
1478  void clear();
1479 
1481  void initInputValues();
1482 
1484  IModulator* getModulatorPtr() { return this; }
1485 
1486  protected:
1487  // --- array of modulation inputs or outputs
1488  double modArray[MAX_MODULATION_CHANNELS];
1489  };
1490 
1517  {
1518  public:
1525  virtual ~ModuleCore() { }
1526 
1528  virtual bool reset(CoreProcData& processInfo) = 0;
1529  virtual bool update(CoreProcData& processInfo) = 0;
1530  virtual bool render(CoreProcData& processInfo) = 0;
1531  virtual bool doNoteOn(CoreProcData& processInfo) = 0;
1532  virtual bool doNoteOff(CoreProcData& processInfo) = 0;
1533 
1535  virtual int32_t getState() { return -1; }
1536  virtual bool shutdown() { return false; }
1537  virtual void setSustainOverride(bool sustain) { return; }
1538  virtual void setStandAloneMode(bool b) { standAloneMode = b; }
1539 
1541  bool startGlideModulation(GlideInfo& glideInfo) {
1542  return glideModulator->startModulator(glideInfo.startMIDINote, glideInfo.endMIDINote, glideInfo.glideTime_mSec, glideInfo.sampleRate);
1543  }
1544 
1546  uint32_t getModuleType() { return moduleType; }
1547  const char* getModuleName() { return moduleName; }
1548  void* getModuleHandle() { return moduleHandle; }
1549  void setModuleHandle(void* handle) { moduleHandle = handle; }
1550  uint32_t getModuleIndex() { return moduleIndex; }
1551  void setModuleIndex(uint32_t index) { moduleIndex = index; }
1552  int32_t getPreferredModuleIndex() { return preferredIndex; }
1553  void setPreferredModuleIndex(uint32_t index) { preferredIndex = index; }
1554 
1565 
1566  protected:
1567  // --- module
1569  const char* moduleName = nullptr;
1570  void* moduleHandle = nullptr;
1571  uint32_t moduleIndex = 0;
1572  int32_t preferredIndex = -1;
1574  bool standAloneMode = false;
1575  std::unique_ptr<GlideModulator> glideModulator;
1576  };
1577 
1601  {
1602  public:
1603  SynthModule(std::shared_ptr<MidiInputData> _midiInputData);
1604  virtual ~SynthModule();
1605 
1607  virtual bool reset(double _sampleRate) = 0;
1608  virtual bool update() = 0;
1609  virtual bool render(uint32_t samplesToProcess = 1) = 0;
1610  virtual bool doNoteOn(MIDINoteEvent& noteEvent) = 0;
1611  virtual bool doNoteOff(MIDINoteEvent& noteEvent) = 0;
1612 
1614  virtual bool initialize(const char* _dllDirectory) { dllDirectory = _dllDirectory; return true; }
1615 
1617  virtual int32_t getState() { return -1; }
1618  virtual bool shutdown() { return false; }
1619 
1621  virtual bool startGlideModulation(GlideInfo& glideInfo);
1622 
1624  std::shared_ptr<Modulators> getModulationInput() { return modulationInput; }
1625  std::shared_ptr<Modulators> getModulationOutput() { return modulationOutput; }
1626 
1628  std::shared_ptr<AudioBuffer> getAudioBuffers() { return audioBuffers; }
1629 
1631  void setUnisonMode(double _unisonDetuneCents, double _unisonStarPhase) {
1632  unisonDetuneCents = _unisonDetuneCents; unisonStartPhase = _unisonStarPhase;
1633  }
1634 
1636  void setFMBuffer(std::shared_ptr<AudioBuffer> pmBuffer) { fmBuffer = pmBuffer; }
1637  void clearFMBuffer() { fmBuffer = nullptr; }
1638 
1641  virtual bool getModuleStrings(std::vector<std::string>& moduleStrings, std::string ignoreStr = "");
1642  virtual bool getModuleStrings(uint32_t coreIndex, std::vector<std::string>& moduleStrings, std::string ignoreStr);
1643  virtual bool getAllModuleStrings(std::vector<std::string>& moduleStrings, std::string ignoreStr);
1644  virtual bool getModKnobStrings(std::vector<std::string>& modKnobStrings);
1645  virtual bool getModKnobStrings(uint32_t coreIndex, std::vector<std::string>& modKnobStrings);
1646  virtual bool getModuleCoreStrings(std::vector<std::string>& moduleCoreStrings);
1647  virtual bool addModuleCore(std::shared_ptr<ModuleCore> core);
1648  virtual uint32_t getSelectedCoreIndex();
1649  virtual bool selectModuleCore(uint32_t index);
1650  virtual bool selectDefaultModuleCore();
1651  virtual void packCores();
1652  virtual bool clearModuleCores();
1653  virtual void setStandAloneMode(bool b);
1654 
1655  protected:
1657  std::shared_ptr<Modulators> modulationInput = std::make_shared<Modulators>();
1658 
1660  std::shared_ptr<Modulators> modulationOutput = std::make_shared<Modulators>();
1661 
1663  std::shared_ptr<MidiInputData> midiInputData = nullptr;
1664 
1666  std::shared_ptr<AudioBuffer> audioBuffers = nullptr;
1667 
1669  std::unique_ptr<GlideModulator> glideModulator;
1670 
1672  std::shared_ptr<AudioBuffer> fmBuffer = nullptr;
1673 
1675  std::shared_ptr<ModuleCore> moduleCores[NUM_MODULE_CORES];
1676  std::shared_ptr<ModuleCore> selectedCore = nullptr;
1677 
1680 
1681  double unisonDetuneCents = 0.0;
1682  double unisonStartPhase = 0.0;
1683  bool standAloneMode = false;
1684 
1687  std::string dllDirectory;
1688  };
1689 
1690 
1691  // ----------------------------------- FX-FILTERING OBJECTS ---------------------------------------------- //
1692  //
1693  /*
1694  Objects taken primarily from Will Pirkle's FX book (2nd edition)
1695  Most objects are heavily detailed in the book Designing Audio Effects Plugins in C++ 2nd Ed and
1696  at http://aspikplugins.com/sdkdocs/html/index.html
1697  */
1698  //
1699  // ------------------------------------------------------------------------------------------------------- //
1700 
1713  inline double doLinearInterp(double y1, double y2, double fractional_X)
1714  {
1715  // --- check invalid condition
1716  if (fractional_X >= 1.0) return y2;
1717 
1718  // --- use weighted sum method of interpolating
1719  return fractional_X*y2 + (1.0 - fractional_X)*y1;
1720  }
1721 
1736  template <typename T>
1738  {
1739  public:
1740  CircularBuffer() {} /* C-TOR */
1741  ~CircularBuffer() {} /* D-TOR */
1742 
1744  void flushBuffer() { memset(&buffer[0], 0, bufferLength * sizeof(T)); }
1745 
1748  void createCircularBuffer(uint32_t _bufferLength)
1749  {
1750  // --- find nearest power of 2 for buffer, and create
1751  createCircularBufferPowerOfTwo((uint32_t)(pow(2, ceil(log(_bufferLength) / log(2)))));
1752  }
1753 
1756  void createCircularBufferPowerOfTwo(uint32_t _bufferLengthPowerOfTwo)
1757  {
1758  // --- reset to top
1759  writeIndex = 0;
1760 
1761  // --- find nearest power of 2 for buffer, save it as bufferLength
1762  bufferLength = _bufferLengthPowerOfTwo;
1763 
1764  // --- save (bufferLength - 1) for use as wrapping mask
1765  wrapMask = bufferLength - 1;
1766 
1767  // --- create new buffer
1768  buffer.reset(new T[bufferLength]);
1769 
1770  // --- flush buffer
1771  flushBuffer();
1772  }
1773 
1775  void writeBuffer(T input)
1776  {
1777  // --- write and increment index counter
1778  buffer[writeIndex++] = input;
1779 
1780  // --- wrap if index > bufferlength - 1
1781  writeIndex &= wrapMask;
1782  }
1783 
1785  T readBuffer(int32_t delayInSamples)//, bool readBeforeWrite = true)
1786  {
1787  // --- subtract to make read index
1788  // note: -1 here is because we read-before-write,
1789  // so the *last* write location is what we use for the calculation
1790  int32_t readIndex = (writeIndex - 1) - delayInSamples;
1791 
1792  // --- autowrap index
1793  readIndex &= wrapMask;
1794 
1795  // --- read it
1796  return buffer[readIndex];
1797  }
1798 
1800  T readBuffer(double delayInFractionalSamples)
1801  {
1802  // --- truncate delayInFractionalSamples and read the int part
1803  int32_t intPart = (int32_t)delayInFractionalSamples;
1804 
1805  T y1 = readBuffer(intPart);
1806 
1807  // --- if no interpolation, just return value
1808  if (!interpolate) return y1;
1809 
1810  // --- else do interpolation
1811  //
1812  int readIndexNext = intPart + 1;
1813 
1814  // --- autowrap index
1815  readIndexNext &= wrapMask;
1816 
1817  // --- read the sample at n+1 (one sample OLDER)
1818  T y2 = readBuffer(readIndexNext);
1819 
1820  // --- get fractional part
1821  double fraction = delayInFractionalSamples - intPart;
1822 
1823  // --- do the interpolation (you could try different types here)
1824  return doLinearInterp(y1, y2, fraction);
1825  }
1826 
1828  void setInterpolate(bool b) { interpolate = b; }
1829 
1830  private:
1831  std::unique_ptr<T[]> buffer = nullptr;
1832  uint32_t writeIndex = 0;
1833  uint32_t bufferLength = 1024;
1834  uint32_t wrapMask = 1023;
1835  bool interpolate = true;
1836  };
1837 
1856  {
1857  public:
1858  DelayLine(void) {} /* C-TOR */
1859  ~DelayLine(void) {} /* D-TOR */
1860 
1861  public:
1863  void clear(){ delayBuffer.flushBuffer();}
1864 
1872  void reset(double _sampleRate, double minimumPitch = MIDI_NOTE_0_FREQ) // 8.176 = MIDI note 0
1873  {
1874  // ---
1875  delayBuffer.createCircularBuffer( ((uint32_t)(_sampleRate / minimumPitch)) );
1876  clear();
1877  }
1878 
1885  void setDelayInSamples(double _delaySamples)
1886  {
1887  delaySamples = _delaySamples;
1888  }
1889 
1896  void writeDelay(double xn)
1897  {
1898  // --- write to delay buffer
1899  delayBuffer.writeBuffer(xn);
1900  }
1901 
1908  double readDelay()
1909  {
1910  double yn = delayBuffer.readBuffer(delaySamples);
1911  return yn;
1912  }
1913 
1914  private:
1915  // --- our only variable
1916  double delaySamples = 0;
1917 
1918  // --- delay buffer of doubles
1919  CircularBuffer<double> delayBuffer;
1920  };
1921 
1922 
1935  struct BQCoeffs
1936  {
1937  // --- filter coefficients
1938  double coeff[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
1939  };
1940 
1955  {
1956  public:
1957  BQAudioFilter(void) {} /* C-TOR */
1958  ~BQAudioFilter(void) {} /* D-TOR */
1959 
1960  public:
1962  void reset(){ flushDelays(); }
1963 
1966  {
1967  for (uint32_t i = 0; i<numStates; i++)
1968  state[i] = 0.0;
1969  }
1970 
1972  void setCoeffs(BQCoeffs& _coeffs) {
1973  bq = _coeffs;
1974  }
1975 
1977  void copyCoeffs(BQAudioFilter& destination) {
1978  destination.setCoeffs(bq);
1979  }
1980 
1987  double processAudioSample(double xn)
1988  {
1989  // --- transposed canonical
1990  double yn = bq.coeff[a0] * xn + state[xz1];
1991 
1992  // --- shuffle/update
1993  state[xz1] = bq.coeff[a1] * xn - bq.coeff[b1] * yn + state[xz2];
1994  state[xz2] = bq.coeff[a2] * xn - bq.coeff[b2] * yn;
1995  return xn*bq.coeff[d0] + yn*bq.coeff[c0];
1996  }
1997 
1998  protected:
1999  enum { a0, a1, a2, b1, b2, c0, d0 };
2000  enum { xz1, xz2, yz1, yz2, numStates };
2001  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2003  };
2004 
2005 
2020  {
2021  public:
2022  FracDelayAPF(void) {} /* C-TOR */
2023  ~FracDelayAPF(void) {} /* D-TOR */
2024 
2025  public:
2027  void reset()
2028  {
2029  state[0] = 0.0;
2030  state[1] = 0.0;
2031  }
2032 
2034  void setAlpha(double _alpha)
2035  {
2036  alpha = _alpha;
2037  }
2038 
2045  double processAudioSample(double xn)
2046  {
2047  double yn = xn*alpha + state[0] - alpha*state[1];
2048  state[0] = xn;
2049  state[1] = yn;
2050  return yn;
2051  }
2052 
2053  private:
2054  // --- our only coefficient
2055  double alpha = 0.0;
2056  double state[2] = { 0.0, 0.0 };
2057  };
2058 
2059 
2075  {
2076  public:
2077  ResLoopFilter(void) {} /* C-TOR */
2078  ~ResLoopFilter(void) {} /* D-TOR */
2079 
2080  public:
2082  void reset()
2083  {
2084  state[0] = 0.0;
2085  state[1] = 0.0;
2086  }
2087 
2094  double processAudioSample(double xn)
2095  {
2096  double yn = 0.5*xn + 0.5*state[0];
2097  state[0] = xn;
2098  return yn;
2099  }
2100 
2101  private:
2102  double state[2] = { 0.0, 0.0 };
2103  };
2104 
2105 
2121  {
2122  public:
2123  DCRemovalFilter(void) {} /* C-TOR */
2124  ~DCRemovalFilter(void) {} /* D-TOR */
2125 
2126  public:
2128  void reset(double _sampleRate)
2129  {
2130  for (uint32_t i = 0; i<numStates; i++)
2131  state[i] = 0.0;
2132 
2133  sampleRate = _sampleRate;
2134 
2135  // --- see book for formulae
2136  double theta_c = kTwoPi*fc / sampleRate;
2137  double gamma = cos(theta_c) / (1.0 + sin(theta_c));
2138 
2139  // --- update coeffs
2140  coeffs[a0] = (1.0 + gamma) / 2.0;
2141  coeffs[a1] = -(1.0 + gamma) / 2.0;
2142  coeffs[a2] = 0.0;
2143  coeffs[b1] = -gamma;
2144  coeffs[b2] = 0.0;
2145  }
2146 
2153  double processAudioSample(double xn)
2154  {
2155  // --- transposed canonical
2156  double yn = coeffs[a0] * xn + state[xz1];
2157 
2158  // --- shuffle/update
2159  state[xz1] = coeffs[a1] * xn - coeffs[b1] * yn + state[xz2];
2160  state[xz2] = coeffs[a2] * xn - coeffs[b2] * yn;
2161  return yn;
2162  }
2163 
2164  protected:
2165  enum { xz1, xz2, yz1, yz2, numStates };
2166  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2167  enum { a0, a1, a2, b1, b2 };
2168  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2169  double fc = 1.0;
2170  double sampleRate = 1.0;
2171  };
2172 
2173 
2188  class TinyBPF
2189  {
2190  public:
2191  TinyBPF(void) {} /* C-TOR */
2192  ~TinyBPF(void) {} /* D-TOR */
2193 
2194  public:
2196  void reset(double _sampleRate)
2197  {
2198  for (uint32_t i = 0; i<numStates; i++)
2199  state[i] = 0.0;
2200 
2201  sampleRate = _sampleRate;
2202  }
2203 
2205  void setParameters(double _fc, double _Q)
2206  {
2207  if (fc == _fc && Q == _Q)
2208  return;
2209 
2210  fc = _fc;
2211  Q = _Q;
2212 
2213  // --- see book for formulae
2214  double K = tan(kPi*fc / sampleRate);
2215  double delta = K*K*Q + K + Q;
2216 
2217  // --- update coeffs
2218  coeffs[a0] = K / delta;;
2219  coeffs[a1] = 0.0;
2220  coeffs[a2] = -K / delta;
2221  coeffs[b1] = 2.0*Q*(K*K - 1) / delta;
2222  coeffs[b2] = (K*K*Q - K + Q) / delta;
2223  }
2224 
2231  double processAudioSample(double xn)
2232  {
2233  // --- transposed canonical
2234  double yn = coeffs[a0] * xn + state[xz1];
2235 
2236  // --- shuffle/update
2237  state[xz1] = coeffs[a1] * xn - coeffs[b1] * yn + state[xz2];
2238  state[xz2] = coeffs[a2] * xn - coeffs[b2] * yn;
2239  return yn;
2240  }
2241 
2242  protected:
2243  enum { xz1, xz2, yz1, yz2, numStates };
2244  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2245  enum { a0, a1, a2, b1, b2 };
2246  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2247  double fc = 5.0;
2248  double Q = 0.5;
2249  double sampleRate = 1.0;
2250  };
2251 
2267  {
2268  public:
2269  LP2Filter(void) {} /* C-TOR */
2270  ~LP2Filter(void) {} /* D-TOR */
2271 
2272  public:
2274  void reset(double _sampleRate)
2275  {
2276  sampleRate = _sampleRate;
2277  clear();
2278  }
2279 
2281  void clear()
2282  {
2283  for (uint32_t i = 0; i<numStates; i++)
2284  state[i] = 0.0;
2285  }
2286 
2288  void setParameters(double _fc, double _Q)
2289  {
2290  if (fc == _fc && Q == _Q)
2291  return;
2292 
2293  fc = _fc;
2294  Q = _Q;
2295 
2296  // --- see book for formulae
2297  double theta_c = 2.0*kPi*fc / sampleRate;
2298  double d = 1.0 / Q;
2299  double betaNumerator = 1.0 - ((d / 2.0)*(sin(theta_c)));
2300  double betaDenominator = 1.0 + ((d / 2.0)*(sin(theta_c)));
2301 
2302  double beta = 0.5*(betaNumerator / betaDenominator);
2303  double gamma = (0.5 + beta)*(cos(theta_c));
2304  double alpha = (0.5 + beta - gamma) / 2.0;
2305 
2306  // --- update coeffs
2307  coeffs[a0] = alpha;
2308  coeffs[a1] = 2.0*alpha;
2309  coeffs[a2] = alpha;
2310  coeffs[b1] = -2.0*gamma;
2311  coeffs[b2] = 2.0*beta;
2312  }
2313 
2320  double processAudioSample(double xn)
2321  {
2322  // --- transposed canonical
2323  double yn = coeffs[a0] * xn + state[xz1];
2324 
2325  // --- shuffle/update
2326  state[xz1] = coeffs[a1] * xn - coeffs[b1] * yn + state[xz2];
2327  state[xz2] = coeffs[a2] * xn - coeffs[b2] * yn;
2328  return yn;
2329  }
2330 
2331  protected:
2332  enum { xz1, xz2, yz1, yz2, numStates };
2333  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2334  enum { a0, a1, a2, b1, b2 };
2335  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2336  double fc = 5.0;
2337  double Q = 0.5;
2338  double sampleRate = 1.0;
2339  };
2340 
2341 
2357  {
2358  public:
2359  HP2Filter(void) {} /* C-TOR */
2360  ~HP2Filter(void) {} /* D-TOR */
2361 
2362  public:
2364  void reset(double _sampleRate)
2365  {
2366  for (uint32_t i = 0; i<numStates; i++)
2367  state[i] = 0.0;
2368 
2369  sampleRate = _sampleRate;
2370  }
2371 
2373  void setParameters(double _fc, double _Q)
2374  {
2375  if (fc == _fc && Q == _Q)
2376  return;
2377 
2378  fc = _fc;
2379  Q = _Q;
2380 
2381  double theta_c = kTwoPi*fc / sampleRate;
2382  double d = 1.0 / Q;
2383 
2384  // --- see book for formulae
2385  double betaNumerator = 1.0 - ((d / 2.0)*(sin(theta_c)));
2386  double betaDenominator = 1.0 + ((d / 2.0)*(sin(theta_c)));
2387 
2388  double beta = 0.5*(betaNumerator / betaDenominator);
2389  double gamma = (0.5 + beta)*(cos(theta_c));
2390  double alpha = (0.5 + beta + gamma) / 2.0;
2391 
2392  // --- update coeffs
2393  coeffs[a0] = alpha;
2394  coeffs[a1] = -2.0*alpha;
2395  coeffs[a2] = alpha;
2396  coeffs[b1] = -2.0*gamma;
2397  coeffs[b2] = 2.0*beta;
2398  }
2399 
2406  double processAudioSample(double xn)
2407  {
2408  // --- transposed canonical
2409  double yn = coeffs[a0] * xn + state[xz1];
2410 
2411  // --- shuffle/update
2412  state[xz1] = coeffs[a1] * xn - coeffs[b1] * yn + state[xz2];
2413  state[xz2] = coeffs[a2] * xn - coeffs[b2] * yn;
2414  return yn;
2415  }
2416 
2417  protected:
2418  enum { xz1, xz2, yz1, yz2, numStates };
2419  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2420  enum { a0, a1, a2, b1, b2 };
2421  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2422  double fc = 5.0;
2423  double Q = 0.5;
2424  double sampleRate = 1.0;
2425  };
2426 
2442  {
2443  public:
2444  TinyReson(void) {} /* C-TOR */
2445  ~TinyReson(void) {} /* D-TOR */
2446 
2447  public:
2449  void reset(double _sampleRate)
2450  {
2451  for(uint32_t i=0; i<numStates; i++)
2452  state[i] = 0.0;
2453 
2454  sampleRate = _sampleRate;
2455  }
2456 
2458  void setParameters(double _fc, double _Q)
2459  {
2460  if (fc == _fc && Q == _Q)
2461  return;
2462 
2463  fc = _fc;
2464  Q = _Q;
2465 
2466  double theta_c = kTwoPi*fc / sampleRate;
2467  double BW = fc / Q;
2468  coeffs[b2] = exp(-2.0*kPi*(BW / sampleRate));
2469  coeffs[b1] = ((-4.0*coeffs[b2]) / (1.0 + coeffs[b2]))*cos(theta_c);
2470  coeffs[a0] = 1.0 - pow(coeffs[b2], 0.5);
2471  coeffs[a2] = -coeffs[a0];
2472  }
2473 
2480  double processAudioSample(double xn, double loss = 1.0)
2481  {
2482  // --- direct
2483  double yn = coeffs[a0]*xn + coeffs[a2]*state[xz2] - coeffs[b1]*state[yz1] -coeffs[b2]*state[yz2];
2484  state[xz2] = state[xz1];
2485  state[xz1] = xn;
2486  state[yz2] = state[yz1];
2487  state[yz1] = yn * loss;
2488  return yn;
2489  }
2490 
2491  protected:
2492  enum { xz1, xz2, yz1, yz2, numStates };
2493  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2494  enum { a0, a2, b1, b2 };
2495  double coeffs[4] = { 0.0, 0.0, 0.0, 0.0 };
2496  double fc = 440.0;
2497  double Q = 0.5;
2498  double sampleRate = 1.0;
2499  };
2500 
2516  {
2517  public:
2518  LowShelfFilter(void) {} /* C-TOR */
2519  ~LowShelfFilter(void) {} /* D-TOR */
2520 
2521  public:
2523  void reset(double _sampleRate)
2524  {
2525  for (uint32_t i = 0; i<numStates; i++)
2526  state[i] = 0.0;
2527 
2528  sampleRate = _sampleRate;
2529  }
2530 
2532  void setParameters(double shelfFreq, double boostCut_dB)
2533  {
2534  double theta_c = kTwoPi*shelfFreq / sampleRate;
2535  double mu = pow(10.0, boostCut_dB / 20.0);
2536 
2537  double beta = 4.0 / (1.0 + mu);
2538  double delta = beta*tan(theta_c / 2.0);
2539  double gamma = (1.0 - delta) / (1.0 + delta);
2540 
2541  // --- update coeffs
2542  coeffs[a0] = (1.0 - gamma) / 2.0;
2543  coeffs[a1] = (1.0 - gamma) / 2.0;
2544  coeffs[a2] = 0.0;
2545  coeffs[b1] = -gamma;
2546  coeffs[b2] = 0.0;
2547 
2548  coeffs[c0] = mu - 1.0;
2549  coeffs[d0] = 1.0;
2550  }
2551 
2558  double processAudioSample(double xn)
2559  {
2560  // --- transposed canonical
2561  double yn = coeffs[a0] * xn + state[xz1];
2562 
2563  // --- shuffle/update
2564  state[xz1] = coeffs[a1] * xn - coeffs[b1] * yn + state[xz2];
2565  state[xz2] = coeffs[a2] * xn - coeffs[b2] * yn;
2566  return xn*coeffs[d0] + yn*coeffs[c0];
2567  }
2568 
2569  protected:
2570  enum { xz1, xz2, yz1, yz2, numStates };
2571  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2572  enum { a0, a1, a2, b1, b2, c0, d0 };
2573  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2574  double fc = 440.0;
2575  double boostCut_dB = 0.0;
2576  double sampleRate = 1.0;
2577  };
2578 
2579 
2595  {
2596  public:
2597  HighShelfFilter(void) {} /* C-TOR */
2598  ~HighShelfFilter(void) {} /* D-TOR */
2599 
2600  public:
2602  void reset(double _sampleRate)
2603  {
2604  for (uint32_t i = 0; i<numStates; i++)
2605  state[i] = 0.0;
2606 
2607  sampleRate = _sampleRate;
2608  }
2609 
2611  void setParameters(double shelfFreq, double boostCut_dB)
2612  {
2613  double theta_c = kTwoPi*shelfFreq / sampleRate;
2614  double mu = pow(10.0, boostCut_dB / 20.0);
2615 
2616  double beta = (1.0 + mu) / 4.0;
2617  double delta = beta*tan(theta_c / 2.0);
2618  double gamma = (1.0 - delta) / (1.0 + delta);
2619 
2620  coeffs[a0] = (1.0 + gamma) / 2.0;
2621  coeffs[a1] = -coeffs[a0];
2622  coeffs[a2] = 0.0;
2623  coeffs[b1] = -gamma;
2624  coeffs[b2] = 0.0;
2625 
2626  coeffs[c0] = mu - 1.0;
2627  coeffs[d0] = 1.0;
2628  }
2629 
2636  double processAudioSample(double xn)
2637  {
2638  // --- transposed canonical
2639  double yn = coeffs[a0] * xn + state[xz1];
2640 
2641  // --- shuffle/update
2642  state[xz1] = coeffs[a1] * xn - coeffs[b1] * yn + state[xz2];
2643  state[xz2] = coeffs[a2] * xn - coeffs[b2] * yn;
2644  return xn*coeffs[d0] + yn*coeffs[c0];
2645  }
2646 
2647  protected:
2648  enum { xz1, xz2, yz1, yz2, numStates };
2649  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2650  enum { a0, a1, a2, b1, b2, c0, d0 };
2651  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2652  double fc = 440.0;
2653  double boostCut_dB = 0.0;
2654  double sampleRate = 1.0;
2655  };
2656 
2672  {
2673  public:
2674  ParametricFilter(void) {} /* C-TOR */
2675  ~ParametricFilter(void) {} /* D-TOR */
2676 
2677  public:
2679  void reset(double _sampleRate)
2680  {
2681  for (uint32_t i = 0; i<numStates; i++)
2682  state[i] = 0.0;
2683 
2684  sampleRate = _sampleRate;
2685  }
2686 
2688  void setParameters(double _fc, double _Q, double _boostCut_dB)
2689  {
2690  if (fc == _fc && Q == _Q && boostCut_dB == _boostCut_dB)
2691  return;
2692  fc = _fc;
2693  Q = _Q;
2694  boostCut_dB = _boostCut_dB;
2695 
2696  // --- see book for formulae
2697  double theta_c = kTwoPi*fc / sampleRate;
2698  double mu = pow(10.0, boostCut_dB / 20.0);
2699 
2700  // --- clamp to 0.95 pi/2 (you can experiment with this)
2701  double tanArg = theta_c / (2.0 * Q);
2702  if (tanArg >= 0.95*kPi / 2.0) tanArg = 0.95*kPi / 2.0;
2703 
2704  // --- intermediate variables (you can condense this if you wish)
2705  double zeta = 4.0 / (1.0 + mu);
2706  double betaNumerator = 1.0 - zeta*tan(tanArg);
2707  double betaDenominator = 1.0 + zeta*tan(tanArg);
2708 
2709  double beta = 0.5*(betaNumerator / betaDenominator);
2710  double gamma = (0.5 + beta)*(cos(theta_c));
2711  double alpha = (0.5 - beta);
2712 
2713  // --- update coeffs
2714  coeffs[a0] = alpha;
2715  coeffs[a1] = 0.0;
2716  coeffs[a2] = -alpha;
2717  coeffs[b1] = -2.0*gamma;
2718  coeffs[b2] = 2.0*beta;
2719 
2720  coeffs[c0] = mu - 1.0;
2721  coeffs[d0] = 1.0;
2722  }
2723 
2730  double processAudioSample(double xn)
2731  {
2732  // --- transposed canonical
2733  double yn = coeffs[a0] * xn + state[xz1];
2734 
2735  // --- shuffle/update
2736  state[xz1] = coeffs[a1] * xn - coeffs[b1] * yn + state[xz2];
2737  state[xz2] = coeffs[a2] * xn - coeffs[b2] * yn;
2738  return xn*coeffs[d0] + yn*coeffs[c0];
2739  }
2740 
2741  protected:
2742  enum { xz1, xz2, yz1, yz2, numStates };
2743  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2744  enum { a0, a1, a2, b1, b2, c0, d0 };
2745  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2746  double fc = 0.0;
2747  double Q = 0.0;
2748  double boostCut_dB = 0.0;
2749  double sampleRate = 1.0;
2750  };
2751 
2752 
2768  {
2769  public:
2770  LP1PFilter(void) {} /* C-TOR */
2771  ~LP1PFilter(void) {} /* D-TOR */
2772 
2773  public:
2775  void reset(double _sampleRate)
2776  {
2777  clear();
2778  sampleRate = _sampleRate;
2779  }
2780 
2782  void clear()
2783  {
2784  for (uint32_t i = 0; i<numStates; i++)
2785  state[i] = 0.0;
2786  }
2787 
2789  void setParameters(double _fc)
2790  {
2791  if (fc == _fc)
2792  return;
2793 
2794  fc = _fc;
2795 
2796  // --- see book for formulae
2797  double theta_c = 2.0*kPi*fc / sampleRate;
2798  double gamma = 2.0 - cos(theta_c);
2799 
2800  double filter_b1 = pow((gamma*gamma - 1.0), 0.5) - gamma;
2801  double filter_a0 = 1.0 + filter_b1;
2802 
2803  // --- update coeffs
2804  coeffs[a0] = filter_a0;
2805  coeffs[a1] = 0.0;
2806  coeffs[a2] = 0.0;
2807  coeffs[b1] = filter_b1;
2808  coeffs[b2] = 0.0;
2809  }
2810 
2818  double processAudioSample(double xn)
2819  {
2820  // --- transposed canonical
2821  double yn = coeffs[a0] * xn + state[xz1];
2822 
2823  // --- shuffle/update
2824  state[xz1] = coeffs[a1] * xn - coeffs[b1] * yn + state[xz2];
2825  state[xz2] = coeffs[a2] * xn - coeffs[b2] * yn;
2826  return yn;
2827  }
2828 
2829  protected:
2830  enum { xz1, xz2, yz1, yz2, numStates };
2831  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2832  enum { a0, a1, a2, b1, b2 };
2833  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2834  double fc = 5.0;
2835  double Q = 0.5;
2836  double sampleRate = 1.0;
2837  };
2838 
2842  enum class PluckFilterType {kPluck, kPluckAndBridge, kPickup, kPluckAndPickup, kBridge, kPluckPickupBridge};
2843 
2844 
2863  {
2864  public:
2865  PluckPosFilter(void) {} /* C-TOR */
2866  ~PluckPosFilter(void) {} /* D-TOR */
2867 
2868  public:
2870  void clear()
2871  {
2872  combDelay.clear();
2874  }
2875 
2884  void reset(double _sampleRate, double minimumPitch = MIDI_NOTE_0_FREQ) // 8.176 = MIDI note 0
2885  {
2886  // ---
2887  combDelay.reset(_sampleRate, minimumPitch);
2888  combDelay.clear();
2889 
2890  pickupFilter.reset(_sampleRate);
2891  pickupFilter.setParameters(2500.0, 1.5); // guitar pickup settings
2892 
2893  bridgeIntegrator.reset(_sampleRate);
2894  bridgeIntegrator.setParameters(20.0); // lower than the lowest note to synthesize which is note 0
2895  }
2896 
2903  void setDelayInSamples(double _delaySamples)
2904  {
2905  // --- the (-1) is needed here because of the way the circular buffer counts samples for read/write
2906  combDelay.setDelayInSamples(_delaySamples - 1);
2907  }
2908 
2918  double processAudioSample(double xn, PluckFilterType type)
2919  {
2920  if (type == PluckFilterType::kBridge)
2921  return 12.0*bridgeIntegrator.processAudioSample(xn);
2922 
2923  if (type == PluckFilterType::kPickup)
2924  return pickupFilter.processAudioSample(xn);
2925 
2926  // --- pluck position
2927  double yn = combDelay.readDelay();
2928  combDelay.writeDelay(xn);
2929 
2930  // --- output pluck
2931  double pluck = 0.5*(xn - yn);
2932  if (type == PluckFilterType::kPluck)
2933  return pluck;
2934 
2935  // --- pluck and pickup
2936  if (type == PluckFilterType::kPluckAndPickup)
2937  return pickupFilter.processAudioSample(pluck);
2938 
2939  // --- pluck and bridge
2940  if (type == PluckFilterType::kPluckAndBridge)
2941  return 12.0*bridgeIntegrator.processAudioSample(pluck);
2942 
2943  if (type == PluckFilterType::kPluckPickupBridge)
2944  {
2945  double pu = 2.0*pickupFilter.processAudioSample(pluck);
2946  return 12.0*bridgeIntegrator.processAudioSample(pu);
2947  }
2948 
2949 
2950  return xn; // should never get here
2951  }
2952 
2953  protected:
2956  LP2Filter pickupFilter;
2957  };
2958 
2959 }// namespace
2960 
3226 #endif /* defined(__synthDefs_h__) */
void setDelayInSamples(double _delaySamples)
set comb delay time - this will be based on virtual plucking position on string
Definition: synthbase.h:2903
void reset(double _sampleRate)
Definition: synthbase.h:2775
const double SVF_Q_SLOPE
Definition: synthbase.h:968
void setCCMIDIData(uint32_t index, uint32_t value)
set the CC MIDI value
Definition: synthbase.cpp:1288
Object that acts as the PCM sample database, as shared synth-wide resource. You should study this esp...
Definition: synthbase.h:1346
uint32_t tableLength
length
Definition: synthbase.h:1239
virtual IWavetableSource * getTableSource(const char *uniqueTableName)=0
get a table source based on its unique name string
void reset()
reset the counter
Definition: synthbase.h:332
std::unique_ptr< GlideModulator > glideModulator
built-in glide modulator for oscillators
Definition: synthbase.h:1575
IPCMSampleDatabase * sampleDatabase
PCM sample database, usually owned by engine.
Definition: synthbase.h:1084
virtual bool addTableSource(const char *uniqueTableName, IWavetableSource *tableSource, uint32_t &uniqueIndex)=0
adds a table to the database
virtual bool getModuleCoreStrings(std::vector< std::string > &moduleCoreStrings)
Gets a std::vector of the names of the four cores in this module.
Definition: synthbase.cpp:1570
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2153
float * getOutputBuffer(uint32_t channel)
Get a naked pointer to an audio OUTPUT buffer by channel.
Definition: synthbase.cpp:162
SynthClock hardSyncClock
clock for reset oscillator
Definition: synthbase.h:387
bool setGlideTime(double glideTime_mSec, double sampleRate)
Change the glide time; this is optional.
Definition: synthbase.cpp:773
Implements a first order APF that is used to generate a fractional delay for the physcial model of a ...
Definition: synthbase.h:2019
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2458
SynthLabTableSet ** tablePtrs
set of table-sets
Definition: synthbase.h:1182
const uint32_t NUM_MODULE_CORES
Definition: synthconstants.h:136
IModulator * modulationOutputs
output modulation values
Definition: synthbase.h:1075
~PCMSampleDatabase()
clear out the table sources
Definition: synthbase.cpp:1080
void setXFadeTimeSamples(uint32_t _xfadeTimeSamples)
Definition: synthbase.h:293
double phaseInc
phase inc = fo/fs
Definition: synthbase.h:171
std::shared_ptr< Modulators > modulationOutput
Definition: synthbase.h:1660
uint32_t numActiveChannels
number of active channels; not used in SynthLab but available
Definition: synthbase.h:736
double g
one pole filter feedback coefficient
Definition: synthbase.h:344
float ** fmBuffers
used for DX synths (phase modulator synths)
Definition: synthbase.h:1080
virtual void setModValue(uint32_t index, double value)=0
set a modulation value to the array for a certain channel
void setAuxDAWDataFloat(uint32_t index, float value)
set the aux data with a float
Definition: synthbase.cpp:1313
void initWithClock(SynthClock &clock)
Initialize this clock with another SynthClock.
Definition: synthbase.cpp:211
The CircularBuffer object implements a simple circular buffer. It uses a wrap mask to wrap the read o...
Definition: synthbase.h:1737
double processAudioSample(double xn, PluckFilterType type)
run the string of filters
Definition: synthbase.h:2918
bool isActive()
checks to see if the modulator is running, or completed
Definition: synthbase.h:429
virtual bool addModuleCore(std::shared_ptr< ModuleCore > core)
adds a module core to the module&#39;s set of four
Definition: synthbase.cpp:1603
void writeBuffer(T input)
Definition: synthbase.h:1775
Ultra compact timer object that is used for many different functionalities.
Definition: synthbase.h:195
~WavetableDatabase()
clear out the table sources
Definition: synthbase.cpp:952
double outputComp
output scaling factor (NOT volume or attenuation, waveform specific)
Definition: synthbase.h:1282
void reset(double _sampleRate)
Definition: synthbase.h:2449
double timeSigNumerator
time signature numerator
Definition: synthbase.h:1400
double sampleRate
fs
Definition: synthstructures.h:246
virtual float getAuxDAWDataFloat(uint32_t index)=0
get aux data as a float datatype, may or may not be MIDI value
Compact modulo counter with wrapping used as the timebase for all oscillators.
Definition: synthbase.h:137
sampleSourceMap sampleDatabase
map that connects PCM sample set names to source objects
Definition: synthbase.h:1363
const double kPi
pi to 80 decimal places
Definition: synthconstants.h:536
double outputComp
output scaling factor
Definition: synthbase.h:1146
std::shared_ptr< AudioBuffer > audioBuffers
Definition: synthbase.h:1666
void reset(double _sampleRate)
Definition: synthbase.h:2128
void destroyOutputBuffers()
Destroy dynamically allocated output buffer; done at destruct time, or if client want to re-size buff...
Definition: synthbase.cpp:69
virtual bool clearModuleCores()
Clears out the module core pointer list.
Definition: synthbase.cpp:1730
void setExpireSamples(uint32_t _targetValueInSamples)
set target value
Definition: synthbase.h:205
uint32_t endMIDINote
ending MIDI note for the glide
Definition: synthstructures.h:244
BQCoeffs bq
coefficients
Definition: synthbase.h:2002
void reset(double _sampleRate, double minimumPitch=MIDI_NOTE_0_FREQ)
reset the delay, calculate a new length based on sample rate and minimum pitch
Definition: synthbase.h:2884
virtual bool removeTableSource(const char *uniqueTableName)=0
remove a table from the database
IMidiInputData * midiInputData
MIDI input daa, usually owned by engine.
Definition: synthbase.h:1085
void advanceClock(uint32_t ticks=1)
Nudge the clock on the modulator; this is used for block processing where the modulator output output...
Definition: synthbase.cpp:727
float ** inputBuffers
set of input bufers, one per channel
Definition: synthbase.h:1078
uint32_t xfadeTime_Samples
the target crossfade time
Definition: synthbase.h:260
const double KORG35_Q_SLOPE
Definition: synthbase.h:969
void setParameters(double shelfFreq, double boostCut_dB)
Definition: synthbase.h:2611
virtual bool selectModuleCore(uint32_t index)
Select a core.
Definition: synthbase.cpp:1653
double doPinkingFilter(double white)
run the pinking filter
Definition: synthbase.cpp:874
void copyCoeffs(BQAudioFilter &destination)
Definition: synthbase.h:1977
Interface for wavetable sources.
Definition: synthbase.h:609
void setParameters(double shelfFreq, double boostCut_dB)
Definition: synthbase.h:2532
virtual bool reset(double _sampleRate)=0
double bN[3]
Definition: synthbase.h:512
double BPM
current BPM, needed for LFO sync to BPM
Definition: synthbase.h:1094
void advanceClock(uint32_t ticks=1)
Nudge the clock on the modulator; this is used for block processing where the modulator output output...
Definition: synthbase.cpp:809
virtual bool haveValidSamples()=0
query for valid samples; needed if WAV parsing fails and we need to delete the entry ...
void addPhaseOffset(double _phaseOffset, bool wrap=true)
For phase modulation, this adds a phase offset and then optionally checks/wraps the counter as needed...
Definition: synthbase.cpp:302
SynthModule(std::shared_ptr< MidiInputData > _midiInputData)
Constructs a SynthModule.
Definition: synthbase.cpp:1403
double modEnd
ramp mod end value
Definition: synthbase.h:437
virtual uint32_t getAuxDAWDataUINT(uint32_t index)
get aux data value
Definition: synthbase.cpp:1244
void setAuxDAWDataUINT(uint32_t index, uint32_t value)
set the aux data with a uint32_t
Definition: synthbase.cpp:1300
Encapsulates the audio buffering requirements of any module that uses audio samples for input and/or ...
Definition: synthbase.h:80
std::shared_ptr< Modulators > modulationInput
Definition: synthbase.h:1657
double absoluteBufferTime_Sec
the time in seconds of the sample index at top of buffer
Definition: synthbase.h:1398
const char * moduleName
module name must be set in derived constructor
Definition: synthbase.h:1569
virtual bool clearSampleSources() override
clear all entries from the std::map
Definition: synthbase.cpp:1175
void setSamplesInBlock(uint32_t _samplesInBlock)
Set the number of samples in a block for processing.
Definition: synthbase.cpp:176
Implements a simple 2nd order HPF.
Definition: synthbase.h:2356
uint32_t moduleType
type of module, LFO_MODULE, EG_MODULE, etc...
Definition: synthbase.h:1568
float ** getInputBuffers()
Definition: synthbase.h:96
const double GUI_Q_MIN
Definition: synthbase.h:966
uint32_t samplesToProcess
number of samples in this block
Definition: synthbase.h:1090
bool crossfade(XFadeType xfadeType, double inputA, double inputB, double &output)
Perform crossfade FROM A to B on a pair of input values to oroduce a single output value...
Definition: synthbase.cpp:421
std::shared_ptr< MidiInputData > midiInputData
Definition: synthbase.h:1663
virtual bool removeSampleSource(const char *uniqueSampleSetName) override
remove a PCM sample source from the database
Definition: synthbase.cpp:1150
Object that acts as the wavetable database, as shared synth-wide resource. You should study this espe...
Definition: synthbase.h:1305
bool advanceWrapClock(uint32_t renderInterval=1)
Advance the clock some number of tics by adding the phaseInc value and then check to see if modulo co...
Definition: synthbase.cpp:251
const double DIODE_Q_SLOPE
Definition: synthbase.h:971
void reset(double startValue=0.0)
Reset to initial state.
Definition: synthbase.cpp:226
double timerInc
timer incrementer value
Definition: synthbase.h:433
double freqOffset
FM.
Definition: synthbase.h:173
void saveState()
Freeze and save the current state of the clock; for PM and FM.
Definition: synthbase.cpp:354
double state[4]
state variables
Definition: synthbase.h:2166
void reset()
Reset to initial state; just resets counters to 0.
Definition: synthbase.cpp:459
void clear()
Definition: synthbase.h:2281
void resetTimer()
reset the counter
Definition: synthbase.h:202
uint32_t xfadeTime_Counter
counter for timer
Definition: synthbase.h:261
double phaseOffset
PM.
Definition: synthbase.h:172
virtual double getModValue(uint32_t index)
get a value from a slot in the modulation array
Definition: synthbase.cpp:1374
const char * waveformName
string for the GUI
Definition: synthbase.h:1149
Implementation of a high shelving filter.
Definition: synthbase.h:2594
Interface for PCM sample sources.
Definition: synthbase.h:766
~AudioBuffer()
As one of the few objects that uses naked pointers (for maximum compatibility between plugin framewor...
Definition: synthbase.cpp:39
std::map< std::string, IWavetableSource *> wavetableSourceMap
map that connects wavetable names to source objects
Definition: synthbase.h:1323
bool standAloneMode
flag for stand-alone mode of operation outside of SynthLab
Definition: synthbase.h:1574
void createCircularBufferPowerOfTwo(uint32_t _bufferLengthPowerOfTwo)
Definition: synthbase.h:1756
Implements a simple 2nd order LPF.
Definition: synthbase.h:2266
Implementation of a constant-Q parametric EQ filter.
Definition: synthbase.h:2671
double z1
one pole filter state variable
Definition: synthbase.h:345
virtual uint32_t getSelectedCoreIndex()
get the index of the selected core
Definition: synthbase.cpp:1640
const uint32_t UNDEFINED_MODULE
Definition: synthconstants.h:112
IPCMSampleDatabase * getIPCMSampleDatabase()
Definition: synthbase.h:1359
uint32_t wrapMask
wrapping mask = length - 1
Definition: synthbase.h:1240
void setCoeffs(BQCoeffs &_coeffs)
Definition: synthbase.h:1972
virtual uint32_t getCCMIDIData(uint32_t index)
get a CC MIDI data value
Definition: synthbase.cpp:1226
double frequency_Hz
clock frequency
Definition: synthbase.h:174
double state[4]
state registers
Definition: synthbase.h:2001
std::shared_ptr< Modulators > getModulationInput()
Definition: synthbase.h:1624
std::default_random_engine defaultGeneratorEngine
Definition: synthbase.h:502
virtual IWavetableSource * getTableSource(const char *uniqueTableName) override
selects a table source based on the unique table name
Definition: synthbase.cpp:965
Simple object that generates white, gaussian white or pink noise.
Definition: synthbase.h:495
bool reset(double _sampleRate, double startPhase, int32_t xfadeSamples=16)
Specialized reset function that:
Definition: synthbase.cpp:568
void reset()
Definition: synthbase.h:1962
virtual void setSampleLoopMode(SampleLoopMode _loopMode)=0
Set the looping mode:
Simple version of the AudioFilter object from Designing Audio Effects Plugins in C++ 2nd Ed...
Definition: synthbase.h:1954
Structure to hold the seven coeffieicents used in the AudioFilter object from Designing Audio Effects...
Definition: synthbase.h:1935
Definition: addosccore.cpp:4
const double MOOG_Q_SLOPE
Definition: synthbase.h:970
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2558
virtual int32_t getWaveformIndex(const char *uniqueTableName) override
get the vector index of a waveform, use at reset() or startup, not runtime
Definition: synthbase.cpp:1061
void clear()
Definition: synthbase.h:2870
double coeffs[5]
biquad coefficients
Definition: synthbase.h:2168
Definition: synthstructures.h:235
uint32_t blockSize
the maximum block size
Definition: synthbase.h:115
virtual bool getAllModuleStrings(std::vector< std::string > &moduleStrings, std::string ignoreStr)
Gets a std::vector of all Module Strings concatenated from all cores in succession.
Definition: synthbase.cpp:1488
std::shared_ptr< AudioBuffer > getAudioBuffers()
Definition: synthbase.h:1628
XFader()
simple construction
Definition: synthbase.h:242
double countDownTimer
current timer value; this always counts DOWN regardless of the polarity of the modulation (up or down...
Definition: synthbase.h:479
uint32_t getModuleType()
Definition: synthbase.h:1546
MidiInputData()
clears out all data arrays
Definition: synthbase.cpp:1194
virtual IPCMSampleSource * getSampleSource(const char *uniqueSampleSetName)=0
get a PCM sample source based on its unique name string
virtual bool addSampleSource(const char *uniqueSampleSetName, IPCMSampleSource *sampleSource)=0
adds a PCM sample to the database
uint32_t getInputChannelCount()
Definition: synthbase.h:100
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2045
Holds all MIDI input data values.
Definition: synthbase.h:1423
std::string * tableNames
names of tables
Definition: synthbase.h:1183
Simple interface for SynthLab filters.
Definition: synthbase.h:1017
ModuleCoreData coreData
core strings (16) and mod knob labels (4)
Definition: synthbase.h:1573
void reset(double _sampleRate)
Definition: synthbase.h:2679
void reset(double _sampleRate)
Definition: synthbase.h:2196
virtual bool startGlideModulation(GlideInfo &glideInfo)
starts the built-in glide modulator
Definition: synthbase.cpp:1587
void clearMidiEvents()
Clear the queue.
Definition: synthbase.cpp:918
uint32_t globalMIDIData[kNumMIDIGlobals]
the global MIDI INPUT table that is shared across the voices via the IMIDIData interface ...
Definition: synthbase.h:1446
virtual uint32_t getWaveTableLength()=0
void removePhaseOffset()
Remove existing a phase offset to the reset clock; for supporting phase modulation.
Definition: synthbase.cpp:643
void writeDelay(double xn)
write a value into the top of the delay
Definition: synthbase.h:1896
T readBuffer(double delayInFractionalSamples)
Definition: synthbase.h:1800
std::shared_ptr< double > table
the table (shared)
Definition: synthbase.h:1279
uint32_t getTick()
tick count
Definition: synthbase.h:216
double sampleRate
fs
Definition: synthbase.h:1089
void initInputValues()
set default values in modulator array
Definition: synthbase.cpp:1347
bool startModulator(double startValue, double endValue, double modTime_mSec, double sampleRate)
Setup the timers and start the ramp modulator running. The modulator produces an output on the range ...
Definition: synthbase.cpp:661
Implementation of a one-pole LPF.
Definition: synthbase.h:2767
void reset(double _sampleRate)
Definition: synthbase.h:2274
Modulators()
constructs the modulator object
Definition: synthbase.cpp:1328
Crossfades two values (from A to B) and then holds B for some amount of time.
Definition: synthbase.h:283
IModulator * getModulatorPtr()
Definition: synthbase.h:1484
Specialized version of the RampModulator, with nearly identically named functions to peform the porta...
Definition: synthbase.h:457
virtual float getAuxDAWDataFloat(uint32_t index)
get aux data value
Definition: synthbase.cpp:1262
bool running
state variable
Definition: synthbase.h:262
uint32_t * tableLengths
pointers to lengths of each of the hex encoded tables
Definition: synthbase.h:1139
float ** outputBuffer
array of output buffer pointers
Definition: synthbase.h:112
bool setHardSyncFrequency(double hardSyncFrequency)
Sets the new reset oscillator frequency in Hz.
Definition: synthbase.cpp:584
uint32_t getExpireSamples()
Definition: synthbase.h:209
T readBuffer(int32_t delayInSamples)
Definition: synthbase.h:1785
Holds the audio output samples from reading a PCM sample file.
Definition: synthbase.h:733
virtual int32_t getWaveformIndex(const char *uniqueTableName)
Definition: synthbase.h:714
float ** outputBuffers
set of output bufers, one per channel
Definition: synthbase.h:1079
Structure for holding information about a static wavetable, that is read from a static location...
Definition: synthbase.h:1208
virtual bool clearTableSources()=0
clear all source pointers
void setUnisonMode(double _unisonDetuneCents, double _unisonStarPhase)
Definition: synthbase.h:1631
void restoreState()
Restore the clock to its last saved state; for PM and FM.
Definition: synthbase.cpp:366
SampleLoopMode
Definition: synthbase.h:741
double modRange
range of modulation output
Definition: synthbase.h:435
uint32_t tableLength
length
Definition: synthbase.h:1280
Implements a first order feedforward LPF with coefficients a0 = a1 = 0.5.
Definition: synthbase.h:2074
void setParameters(double _fc)
Definition: synthbase.h:2789
Implements a simple 2nd order BPF.
Definition: synthbase.h:2188
Abstract base class that encapsulates functionality of a module; used with the Module-Core paradigm...
Definition: synthbase.h:1600
Structure for holding information about a static wavetable, that is read from a static location...
Definition: synthbase.h:1264
void clear()
Definition: synthbase.h:2782
virtual int32_t getState()
Definition: synthbase.h:1617
double processAudioSample(double xn)
Definition: synthbase.h:1987
bool timerExpired()
check if we hit target
Definition: synthbase.h:212
const double HSYNC_MOD_SLOPE
Definition: synthbase.h:972
virtual double selectSample(double oscFrequency)=0
Selects a PCM sample based on the current oscillation frequency (after all modulations have been appl...
unsigned int tablePtrsCount
number of pointers
Definition: synthbase.h:1181
bool timerActive
state of modulator, running (true) or expired (false)
Definition: synthbase.h:477
std::unique_ptr< GlideModulator > glideModulator
Definition: synthbase.h:1669
uint32_t wrapMask
mask = length - 1
Definition: synthbase.h:1281
const char * waveformName
waveform name string
Definition: synthbase.h:1243
void addPhaseOffset(double offset)
Add a phase offset to the reset clock; for supporting phase modulation.
Definition: synthbase.cpp:634
void reset()
Definition: synthbase.h:2082
Interface for wavetable databases.
Definition: synthbase.h:669
Implements a modulator object.
Definition: synthbase.h:1467
virtual bool addSampleSource(const char *uniqueSampleSetName, IPCMSampleSource *sampleSource) override
add a PCM sample source to the database
Definition: synthbase.cpp:1123
Minute implementation of a 2nd order resonator filter.
Definition: synthbase.h:2441
uint32_t counter
the timer counter
Definition: synthbase.h:219
double getNextModulationValue(uint32_t advanceClock=1)
Get the current output of the modulator; this is called repeatedly over the ramp modulation time...
Definition: synthbase.cpp:787
void clear()
Definition: synthbase.h:1863
double outputComp
output scaling factor (NOT volume or attenuation, waveform specific)
Definition: synthbase.h:1241
Interface for modulator objects.
Definition: synthbase.h:551
Definition: synthbase.h:37
virtual bool clearSampleSources()=0
clear all the sample sources
PluckFilterType
Definition: synthbase.h:2842
void reset(double _sampleRate, double minimumPitch=MIDI_NOTE_0_FREQ)
reset the delay, calculate a new length based on sample rate and minimum pitch
Definition: synthbase.h:1872
Interface for a MIDI input data object.
Definition: synthbase.h:904
uint32_t ccMIDIData[kNumMIDICCs]
the global MIDI CC INPUT table that is shared across the voices via the IMIDIData interface ...
Definition: synthbase.h:1447
XFadeData getCrossfadeData()
Returns the current state of the crossfade or hold.
Definition: synthbase.cpp:487
virtual bool clearTableSources() override
clear all entries from the std::map
Definition: synthbase.cpp:1048
uint32_t getBlockSize()
Definition: synthbase.h:104
void setFrequency(double _frequency_Hz, double _sampleRate)
Set the clock frequency, which calculates the current phase increment value.
Definition: synthbase.cpp:288
const double * dTable
table of 64-bit doubles
Definition: synthbase.h:1238
void * moduleParameters
module parameters, cloaked as void* – varies according to module
Definition: synthbase.h:1086
double doSlewLimiter(double input)
Definition: synthbase.h:336
void setSlewValue(double _g)
b1 coefficient
Definition: synthbase.h:335
virtual double * getModArrayPtr(uint32_t index)
get a pointer to a slot in the modulation array
Definition: synthbase.cpp:1361
void setXFadeTime(uint32_t _xfadeTime_Samples)
Set the current crossfade time.
Definition: synthbase.cpp:403
void clear()
fast clearing of modulator array
Definition: synthbase.cpp:1337
virtual bool selectDefaultModuleCore()
Select the default core, which is always the first in the list.
Definition: synthbase.cpp:1671
std::shared_ptr< AudioBuffer > fmBuffer
Definition: synthbase.h:1672
void reset()
Resets object to initialized state.
Definition: synthbase.cpp:391
uint32_t xfadeTime_Samples
target crossfade time
Definition: synthbase.h:304
uint64_t getMidiEventCount()
Definition: synthbase.cpp:926
virtual int32_t getState()
Definition: synthbase.h:1535
void setParameters(double _fc, double _Q, double _boostCut_dB)
Definition: synthbase.h:2688
void flushDelays()
Definition: synthbase.h:1965
double doLinearInterp(double y1, double y2, double fractional_X)
performs linear interpolation of fractional x distance between two adjacent (x,y) points; returns int...
Definition: synthbase.h:1713
virtual void packCores()
packs the cores into non-null ordering
Definition: synthbase.cpp:1686
void startHardSync(SynthClock oscClock)
Starts the hard sync operation as a result of being reset, using the main oscillator&#39;s SynthClock to ...
Definition: synthbase.cpp:598
Crossfades two values (from A to B)
Definition: synthbase.h:239
const double kTwoPi
2pi to 80 decimal places
Definition: synthconstants.h:543
IWavetableDatabase * wavetableDatabase
wavetable database, usually owned by engine
Definition: synthbase.h:1083
virtual uint32_t getCCMIDIData(uint32_t index)=0
get a MIDI CC value
virtual bool initialize(const char *_dllDirectory)
Definition: synthbase.h:1614
uint32_t xfadeTime_Counter
crossfade timer counter
Definition: synthbase.h:305
uint32_t timeSigDenomintor
time signature denominator
Definition: synthbase.h:1401
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2406
int32_t preferredIndex
preferred index of this DYNAMIC core
Definition: synthbase.h:1572
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
CoreProcData coreProcessData
Definition: synthbase.h:1686
Implements a simple slew limiter using a one pole lowpass filter.
Definition: synthbase.h:325
void addFrequencyOffset(double _freqOffset)
For frequency modulation, this adds a frequency offset, and recalculates the phase increment value...
Definition: synthbase.cpp:334
void setFMBuffer(std::shared_ptr< AudioBuffer > pmBuffer)
Definition: synthbase.h:1636
virtual bool removeSampleSource(const char *uniqueSampleSetName)=0
remove a PCM sample set from the database
double countUpTimer
current timer value; this always counts UP regardless of the polarity of the modulation (up or down) ...
Definition: synthbase.h:434
double glideRange
range (distance between MIDI note numbers, as double)
Definition: synthbase.h:480
void removePhaseOffset()
For phase modulation, this removes a phase offset, notice that the function does not attempt to wrap ...
Definition: synthbase.cpp:320
This structure holds all of the information needed to for the plugin framework to send MIDI informati...
Definition: synthbase.h:1384
virtual bool addTableSource(const char *uniqueTableName, IWavetableSource *tableSource, uint32_t &uniqueIndex) override
add a table source to the database
Definition: synthbase.cpp:999
const double GUI_Q_MAX
Definition: synthbase.h:967
void removeFrequencyOffset()
For frequency modulation, this removes a frequency offset and recalculates the phase inc...
Definition: synthbase.cpp:345
MIDINoteEvent noteEvent
the MIDI note event for the current audio block
Definition: synthbase.h:1095
bool timerActive
state of modulator, running (true) or expired (false)
Definition: synthbase.h:432
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2636
XFader hardSyncFader
crossfader for smearing discontinuity
Definition: synthbase.h:389
bool startGlideModulation(GlideInfo &glideInfo)
Definition: synthbase.h:1541
void * moduleHandle
used for dynamically loading cores from DLLs
Definition: synthbase.h:1570
double doPinkNoise()
Function generate pink noise by filtering white noise.
Definition: synthbase.cpp:859
const uint32_t kDefaultWaveTableLength
Definition: synthbase.h:1190
virtual bool reset(CoreProcData &processInfo)=0
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2320
uint32_t moduleIndex
index of this core
Definition: synthbase.h:1571
double doHardSyncXFade(double inA, double inB)
Perform the crossfade on the two oscillator signals to smear over the discontinuity.
Definition: synthbase.cpp:620
virtual void setStandAloneMode(bool b)
Sets the stand-alone mode flag on all cores.
Definition: synthbase.cpp:1713
This super-structure holds a set of SynthLabTableSet called a "bank" and used in the morphing wavetab...
Definition: synthbase.h:1173
void setInterpolate(bool b)
Definition: synthbase.h:1828
IModulator * modulationInputs
input modulation values
Definition: synthbase.h:1074
SynthClock & operator=(const SynthClock &params)
Overloaded = operator for setting two clocks equal to each other by copying member values from a sour...
Definition: synthbase.cpp:189
IWavetableDatabase * getIWavetableDatabase()
Definition: synthbase.h:1320
void pushMidiEvent(midiEvent event)
Add a MIDI event to the queue.
Definition: synthbase.cpp:908
This is a very specialized object that performs the hard-sync operation using two SynthClocks...
Definition: synthbase.h:365
Interface for PCM sample databases.
Definition: synthbase.h:838
double getNextModulationValue(uint32_t advanceClock=1)
Get the current output of the modulator; this is called repeatedly over the ramp modulation time...
Definition: synthbase.cpp:699
void setExpireMilliSec(double timeMSec, double sampleRate)
set target value
Definition: synthbase.h:206
float ** inputBuffer
array of input buffer pointers
Definition: synthbase.h:111
double modStart
ramp mod start value
Definition: synthbase.h:436
void setAlpha(double _alpha)
Definition: synthbase.h:2034
Implements a first order HPF with fc = 2.0Hz.
Definition: synthbase.h:2120
void destroyInputBuffers()
Destroy dynamically allocated input buffer; done at destruct time, or if client want to re-size buffe...
Definition: synthbase.cpp:51
void setDelayInSamples(double _delaySamples)
set delay time in samples; used to access the delay when reading
Definition: synthbase.h:1885
virtual uint32_t getGlobalMIDIData(uint32_t index)
get a global MIDI data value
Definition: synthbase.cpp:1210
This is a tiny modulator object that produces an output that ramps up or down linearly between two va...
Definition: synthbase.h:412
double hardSyncFrequency
reset oscillator rate
Definition: synthbase.h:390
double unisonStartPhase
unison start phase value for this core
Definition: synthbase.h:1092
double processAudioSample(double xn, double loss=1.0)
run the filter
Definition: synthbase.h:2480
const uint64_t * uTable
table of 64-bit HEX values
Definition: synthbase.h:1237
Definition: synthbase.h:1855
XFadeType
Definition: synthconstants.h:81
uint32_t samplesInBlock
the number of samples to process in the block (in case of partial blocks)
Definition: synthbase.h:116
virtual bool removeTableSource(const char *uniqueTableName) override
remove a table source from the database
Definition: synthbase.cpp:1029
double mcounter
modulo counter [0.0, +1.0], this is the value you use
Definition: synthbase.h:170
double unisonDetuneCents
detuning value for this core
Definition: synthbase.h:1091
std::vector< midiEvent > midiEventQueue
queue
Definition: synthbase.h:1405
uint32_t startMIDINote
starting MIDI note for the glide
Definition: synthstructures.h:243
virtual void selectTable(uint32_t midiNoteNumber)=0
Objects that access the database will select a table based on the user&#39;s waveform selection...
void reset(double _sampleRate)
Definition: synthbase.h:2523
virtual uint32_t getGlobalMIDIData(uint32_t index)=0
get a global MIDI data value
void advanceClock(uint32_t renderInterval=1)
Advance the clock some number of tics by adding the phaseInc value.
Definition: synthbase.cpp:239
void setGlobalMIDIData(uint32_t index, uint32_t value)
set the global MIDI value
Definition: synthbase.cpp:1276
const char * waveformName
waveform name
Definition: synthbase.h:1284
void reset(double _sampleRate)
Definition: synthbase.h:2364
void createCircularBuffer(uint32_t _bufferLength)
Definition: synthbase.h:1748
double state[NUM_VARS]
for state save
Definition: synthbase.h:177
double doWhiteNoise()
Function generate white noise.
Definition: synthbase.cpp:842
bool holding
state variable for holding
Definition: synthbase.h:308
double auxData[kNumMIDIAuxes]
the aux values, specific to SynthLab
Definition: synthbase.h:1448
virtual IPCMSampleSource * getSampleSource(const char *uniqueSampleSetName) override
selects a PCM sample source based on the unique table name
Definition: synthbase.cpp:1094
ModuleCoreData & getModuleData()
provides access to the core data:
Definition: synthbase.h:1564
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2373
double BPM
beats per minute, aka "tempo"
Definition: synthbase.h:1399
DelayLine combDelay
for pluck position
Definition: synthbase.h:2954
double doGaussianWhiteNoise(double mean=0.0, double variance=1.0)
Function generate gaussian white noise.
Definition: synthbase.cpp:832
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2730
virtual bool getModKnobStrings(std::vector< std::string > &modKnobStrings)
Gets a std::vector of Mod Knob label strings for the selected core.
Definition: synthbase.cpp:1518
Implementation of a low shelving filter.
Definition: synthbase.h:2515
virtual double readWaveTable(double normalizedPhaseInc)=0
Read a table at a normalized index where 0.0 is the start of the table and 1.0 is the end of it...
uint32_t targetValueInSamples
curent target galue
Definition: synthbase.h:220
This structure defines a set of wavetables that are usually found in .h files and compiled into the s...
Definition: synthbase.h:1126
virtual uint32_t getAuxDAWDataUINT(uint32_t index)=0
get aux data as a uint32_t datatype, may or may not be MIDI value
void reset(double _sampleRate)
Definition: synthbase.h:2602
virtual double getModValue(uint32_t index)=0
get a modulation value from the array for a certain channel
bool startModulator(double startNote, double endNote, double glideTime_mSec, double sampleRate)
Setup the timers and start the ramp modulator running. The modulator produces an output on the range ...
Definition: synthbase.cpp:751
std::shared_ptr< ModuleCore > moduleCores[NUM_MODULE_CORES]
Definition: synthbase.h:1675
virtual ~SynthModule()
Removes cores, if any.
Definition: synthbase.cpp:1421
ModuleCoreData moduleData
modulestrings (16) and mod knob labels (4)
Definition: synthbase.h:1679
void setHoldTimeSamples(double _holdTimeSamples)
Setting the hold time is slightly more complicated than the crossfade time becuase it may be done at ...
Definition: synthbase.cpp:470
virtual uint32_t getValidSampleCount()=0
query for valid sample count (not used in SynthLab but avialable)
Holds an array of filter output values; SynthLab filters can produce multiple outputs at once...
Definition: synthbase.h:988
const char * dllPath
path to the plugin, used for finding PCM sample WAV files
Definition: synthbase.h:1087
bool wrapClock()
Wrap the modulo counter; note that this will wrap the modulo counter as many times as needed to get i...
Definition: synthbase.cpp:263
double audioOutput[STEREO_CHANNELS]
array of audio output samples
Definition: synthbase.h:735
double readDelay()
read a delayed value at the location specified in the call to setDelayInSamples() ...
Definition: synthbase.h:1908
void flushBuffers()
clear out the audio; used often
Definition: synthbase.cpp:127
void advanceTimer(uint32_t ticks=1)
advance by 1
Definition: synthbase.h:215
void flushBuffer()
Definition: synthbase.h:1744
virtual double * getModArrayPtr(uint32_t index)=0
Used for the modulation matrix to have instant access to the array.
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2231
void init(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize)
Main initializer that creates the new arrays and sets up the object.
Definition: synthbase.cpp:92
Information about a MIDI event.
Definition: synthstructures.h:166
virtual const char * getWaveformName()=0
void reset()
Definition: synthbase.h:2027
This structure holds all of the information needed to call functions on a ModuleCore object...
Definition: synthbase.h:1071
ModuleCore()
Constructs a ModuleCore.
Definition: synthbase.h:1524
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2818
uint64_t ** ppHexTableSet
pointers to sets of hex encoded tables
Definition: synthbase.h:1140
Comnination of three filters in one; note that the figure in the book does not show the variety of co...
Definition: synthbase.h:2862
Contains the two sets of strings unique to each core: the module strings (waveforms for oscillators) ...
Definition: synthstructures.h:264
double timerInc
timer incrementer value
Definition: synthbase.h:478
bool isActive()
checks to see if the modulator is running, or completed
Definition: synthbase.h:474
double glideTime_mSec
glide time to cover the range of notes
Definition: synthstructures.h:245
virtual bool getModuleStrings(std::vector< std::string > &moduleStrings, std::string ignoreStr="")
Gets a std::vector of Module Strings.
Definition: synthbase.cpp:1437
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2288
const uint32_t kNumMIDICCs
Definition: synthconstants.h:577
virtual void setModValue(uint32_t index, double value)
set a value into a slot in the modulation array
Definition: synthbase.cpp:1388
bool setModTime(double modTime_mSec, double sampleRate)
Change the modulation time; this is optional.
Definition: synthbase.cpp:685
Abstract base class that encapsulates functionality of a module core; used with the Module-Core parad...
Definition: synthbase.h:1516
const uint32_t MAX_MODULATION_CHANNELS
Definition: synthconstants.h:39
IMidiInputData * getIMIDIInputData()
Definition: synthbase.h:1442
virtual void deleteSamples()=0
Delete the samples, part of destruction process.
SynthClock crossFadeClock
crossfading timer
Definition: synthbase.h:388
float * getInputBuffer(uint32_t channel)
Get a naked pointer to an audio INPUT buffer by channel.
Definition: synthbase.cpp:148
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2205
virtual PCMSampleOutput readSample(double &readIndex, double inc)=0
Read a PCM sample at a fractional read index location (not normalized)
double sampleRate
fs
Definition: synthbase.h:391
LP1PFilter bridgeIntegrator
for bridge LPF
Definition: synthbase.h:2955
Information about a MIDI note event (note on or note off).
Definition: synthstructures.h:212
uint32_t holdTime_Counter
hold timer counter
Definition: synthbase.h:307
midiEvent * getMidiEvent(uint32_t index)
gets a MIDI event within the event queue
Definition: synthbase.cpp:939
double fc
hardcoded fc value
Definition: synthbase.h:2169
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2094
uint32_t holdTime_Samples
target hold time
Definition: synthbase.h:306