SynthLab SDK
synthbase.h
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 {
32  // ---------------------- SYNTH OBJECTS WITHOUT BASE CLASES --------------------------------------------- //
33  //
34  /*
35  These are simple, stand-alone objects or primary synth objects that perform intrinsically
36  basic/fundamental synth operations.
37 
38  Many of these are used as base classes for extended objects.
39 
40  These are NOT interfaces, which are defined in a separate section of this file.
41  */
42  //
43  // ------------------------------------------------------------------------------------------------------- //
44 
66  {
67  public:
68  AudioBuffer() {}
69  AudioBuffer(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
70  ~AudioBuffer();
71 
73  void init(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
74  void flushBuffers();
75 
77  float* getInputBuffer(uint32_t channel);
78  float* getOutputBuffer(uint32_t channel);
79 
81  float** getInputBuffers() { return inputBuffer; }
82  float** getOutputBuffers() { return outputBuffer; }
83 
85  uint32_t getInputChannelCount() { return numInputChannels; }
86  uint32_t getOutputChannelCount() { return numOutputChannels; }
87 
89  uint32_t getBlockSize() { return blockSize; }
90  uint32_t getSamplesInBlock() { return samplesInBlock; }
91  void setSamplesInBlock(uint32_t _samplesInBlock);
92 
93  protected:
94  void destroyInputBuffers();
95  void destroyOutputBuffers();
96  float** inputBuffer = nullptr;
97  float** outputBuffer = nullptr;
98  uint32_t numInputChannels = 1;
99  uint32_t numOutputChannels = 1;
100  uint32_t blockSize = 64;
101  uint32_t samplesInBlock = 64;
102  };
103 
104 
123  {
124  public:
125  SynthClock() {}
126  ~SynthClock() {}
127  SynthClock& operator=(const SynthClock& params);
128 
130  void reset(double startValue = 0.0);
131  void initWithClock(SynthClock& clock);
132 
134  void advanceClock(uint32_t renderInterval = 1);
135  bool advanceWrapClock(uint32_t renderInterval = 1);
136  bool wrapClock();
137 
139  void setFrequency(double _frequency_Hz, double _sampleRate);
140  double getFrequency() { return frequency_Hz; }
141 
143  void addPhaseOffset(double _phaseOffset, bool wrap = true);
144  void removePhaseOffset();
145 
147  void addFrequencyOffset(double _freqOffset);
148  void removeFrequencyOffset();
149 
151  void saveState();
152  void restoreState();
153 
154  public: // for fastest access
155  double mcounter = 0.0;
156  double phaseInc = 0.0;
157  double phaseOffset = 0.0;
158  double freqOffset = 0.0;
159  double frequency_Hz = 0.0;
160  double sampleRate = 0.0;
161  enum { MOD_COUNTER, PHASE_INC, PHASE_OFFSET, FREQUENCY_HZ, NUM_VARS };
162  double state[NUM_VARS] = { 0.0, 0.0, 0.0, 0.0 };
163  };
164 
180  class Timer
181  {
182  public:
183  Timer() {}
184  ~Timer() {}
185 
187  void resetTimer() { counter = 0; }
188 
190  void setExpireSamples(uint32_t _targetValueInSamples) { targetValueInSamples = _targetValueInSamples; }
191  void setExpireMilliSec(double timeMSec, double sampleRate) { setExpireSamples(sampleRate*(timeMSec / 1000.0)); }
192 
194  uint32_t getExpireSamples() { return targetValueInSamples; }
195 
197  bool timerExpired() { return (counter >= targetValueInSamples); }
198 
200  void advanceTimer(uint32_t ticks = 1) { counter += ticks; }
201  uint32_t getTick() { return counter; }
202 
203  protected:
204  uint32_t counter = 0;
205  uint32_t targetValueInSamples = 0;
206  };
207 
224  class XFader
225  {
226  public:
227  XFader() {}
228  XFader(uint32_t _xfadeTime_Samples);
229 
231  void reset();
232 
234  void setXFadeTime(uint32_t _xfadeTime_Samples);
235  void startCrossfade() { running = true; }
236  void stopCrossfade() { running = false; }
237  bool isCrossfading() { return running; }
238 
239  // --- crossfade FROM A to B
240  // returns TRUE if the crossfade is still going (needs more samples)
241  // FALSE if the crossfade is finished (done)
242  bool crossfade(XFadeType xfadeType, double inputA, double inputB, double& output);
243 
244  protected:
245  uint32_t xfadeTime_Samples = 4410;
246  uint32_t xfadeTime_Counter = 0;
247  bool running = false;
248  };
249 
250 
269  {
270  public:
271  XHoldFader() {}
272  ~XHoldFader() {}
273 
274  // --- fader functions
275  void reset();
276 
278  inline void setXFadeTimeSamples(double _xfadeTimeSamples){ xfadeTime_Samples = _xfadeTimeSamples; }
279  inline uint32_t getXFadeTimeSamples(){ return xfadeTime_Samples; }
280 
282  void setHoldTimeSamples(double _holdTimeSamples);
283  inline double getHoldTimeSamples() { return holdTime_Samples; }
284 
286  XFadeData getCrossfadeData();
287 
288  protected:
289  uint32_t xfadeTime_Samples = 4410;
290  uint32_t xfadeTime_Counter = 0;
291  uint32_t holdTime_Samples = 4410;
292  uint32_t holdTime_Counter = 0;
293  bool holding = false;
294  };
295 
296 
311  {
312  public:
313  SlewLimiter() {}
314  ~SlewLimiter() {}
315 
316  // --- slewing functions
317  void reset() { z1 = 0; }
318 
319  // --- slew value is: 0 <= slewvalue <= 0.9999
320  void setSlewValue(double _g) { g = _g; }
321  inline double doSlewLimiter(double input)
322  {
323  double output = input*(1.0 - g) + g*z1;
324  z1 = output;
325  return output;
326  }
327 
328  protected:
329  double g = 0;
330  double z1 = 0.0;
331  };
332 
333 
351  {
352  public:
353  Synchronizer() {}
354  ~Synchronizer() {}
355 
357  bool reset(double _sampleRate, double startPhase, int32_t xfadeSamples = 16);
358 
361  SynthClock& getHardSyncClock() { return hardSyncClock; }
362  SynthClock& getCrossFadeClock() { return crossFadeClock; }
363  void startHardSync(SynthClock oscClock);
364  double doHardSyncXFade(double inA, double inB);
365  bool isProcessing() { return hardSyncFader.isCrossfading(); }
366 
368  void addPhaseOffset(double offset);
369  void removePhaseOffset();
370 
371  protected:
375  double hardSyncFrequency = 440.0;
376  double sampleRate = 44100.0;
377  };
378 
379 
398  {
399  public:
400  RampModulator() {}
401  ~RampModulator() {}
402 
404  bool startModulator(double startValue, double endValue, double modTime_mSec, double sampleRate);
405 
407  bool setModTime(double modTime_mSec, double sampleRate);
408 
410  double getNextModulationValue(uint32_t advanceClock = 1);
411 
413  void advanceClock(uint32_t ticks = 1);
414  inline bool isActive() { return timerActive; }
415 
416  protected:
417  bool timerActive = false;
418  double timerInc = 0.0;
419  double countUpTimer = 0.0;
420  double modRange = 1.0;
421  double modStart = 0.0;
422  double modEnd = 1.0;
423  };
424 
443  {
444  public:
445  GlideModulator() {}
446  ~GlideModulator() {}
447 
449  bool startModulator(double startNote, double endNote, double glideTime_mSec, double sampleRate);
450 
452  bool setGlideTime(double glideTime_mSec, double sampleRate);
453 
455  double getNextModulationValue(uint32_t advanceClock = 1);
456 
458  void advanceClock(uint32_t ticks = 1);
459  inline bool isActive() { return timerActive; }
460 
461  protected:
462  bool timerActive = false;
463  double timerInc = 0.0;
464  double countDownTimer = 1.0;
465  double glideRange = 1.0;
466  };
467 
481  {
482  public:
483  NoiseGenerator() {}
484  ~NoiseGenerator() {}
485 
487  std::default_random_engine defaultGeneratorEngine;
488 
490  double doGaussianWhiteNoise(double mean = 0.0, double variance = 1.0);
491  double doWhiteNoise();
492  double doPinkNoise();
493  double doPinkingFilter(double white);
494 
496  double bN[3] = { 0.0, 0.0, 0.0 };
497  };
498 
499  // ---------------------- SYNTH INTERFACE OBJECTS-------------------------------------------------------- //
500  //
501  /*
502  These are pure abstrace interfaces to be used as base classes for the synth objects. These allow
503  container objects to hold (shared) simple interface pointers, or the actual object pointers; all
504  object interfacing is done through the common objec model interfaces here.
505  */
506  //
507  // ------------------------------------------------------------------------------------------------------- //
508 
531  {
532  public:
541  virtual double* getModArrayPtr(uint32_t index) = 0;
542 
551  virtual double getModValue(uint32_t index) = 0;
552 
562  virtual void setModValue(uint32_t index, double value) = 0;
563  };
564 
565  // ---------------------- WAVETABLES --------------------------------------------------------- //
589  {
590  public:
599  virtual void selectTable(uint32_t midiNoteNumber) = 0;
600 
610  virtual double readWaveTable(double normalizedPhaseInc) = 0;
611 
615  virtual uint32_t getWaveTableLength() = 0;
616 
617 
621  virtual const char* getWaveformName() = 0;
622  };
623 
644  {
645  public:
654  virtual IWavetableSource* getTableSource(const char* uniqueTableName) = 0;
655 
665  virtual bool addTableSource(const char* uniqueTableName, IWavetableSource* tableSource) = 0;
666 
674  virtual bool removeTableSource(const char* uniqueTableName) = 0;
675 
683  virtual bool clearTableSources() = 0;
684  };
685 
686 
687  // ---------------------- PCM SAMPLES --------------------------------------------------------- //
703  {
704  double audioOutput[STEREO_CHANNELS] = { 0.0, 0.0 };
705  uint32_t numActiveChannels = 0;
706  };
707 
710  enum class SampleLoopMode { loop, sustain, oneShot };
711 
736  {
737  public:
744  virtual double selectSample(double oscFrequency) = 0;
745 
756  virtual PCMSampleOutput readSample(double& readIndex, double inc) = 0;
757 
767  virtual void setSampleLoopMode(SampleLoopMode _loopMode) = 0;
768 
773  virtual void deleteSamples() = 0;
774 
779  virtual uint32_t getValidSampleCount() = 0;
780 
785  virtual bool haveValidSamples() = 0;
786  };
787 
808  {
809  public:
819  virtual IPCMSampleSource* getSampleSource(const char* uniqueSampleSetName) = 0;
820 
830  virtual bool addSampleSource(const char* uniqueSampleSetName, IPCMSampleSource* sampleSource) = 0;
831 
832 
841  virtual bool removeSampleSource(const char* uniqueSampleSetName) = 0;
842 
849  virtual bool clearSampleSources() = 0;
850  };
851 
874  {
875  public:
887  virtual uint32_t getGlobalMIDIData(uint32_t index) = 0;
888 
900  virtual uint32_t getCCMIDIData(uint32_t index) = 0;
901 
910  virtual uint32_t getAuxDAWDataUINT(uint32_t index) = 0;
911 
920  virtual float getAuxDAWDataFloat(uint32_t index) = 0;
921  };
922 
926  enum { LPF1, LPF2, LPF3, LPF4, HPF1, HPF2, HPF3, HPF4, BPF2, BPF4, BSF2, BSF4,
927  APF1, APF2, ANM_LPF1, ANM_LPF2, ANM_LPF3, ANM_LPF4, NUM_FILTER_OUTPUTS };
928 
943  {
944  double filter[NUM_FILTER_OUTPUTS];
945  };
946 
947 
967  {
975  virtual bool reset(double _sampleRate) = 0;
976 
983  virtual bool update() = 0;
984 
992  virtual FilterOutput process(double xn) = 0;
993 
1001  virtual void setFilterParams(double _fc, double _Q) = 0;
1002  };
1003 
1004 
1021  {
1025 
1027  float** inputBuffers = nullptr;
1028  float** outputBuffers = nullptr;
1029  float** fmBuffers = nullptr;
1030 
1035  void* moduleParameters = nullptr;
1036  const char* dllPath = nullptr;
1037 
1038  double sampleRate = 0.0;
1039  uint32_t samplesToProcess = 64;
1040  double unisonDetuneCents = 0.0;
1041  double unisonStartPhase = 0.0;
1042 
1043  double BPM = 120.0;
1045  };
1046 
1047  // ----------------------------------- SYNTH OBJECTS ----------------------------------------------------- //
1048  //
1049  /*
1050  Fundamental objects that are used throughout SynthLab
1051  */
1052  //
1053  // ------------------------------------------------------------------------------------------------------- //
1054 
1076  {
1077  // --- multi initializer construction
1078  SynthLabTableSet(const char* _waveformName, double _tableFs,
1079  uint32_t* _tableLengths, uint64_t** _ppHexTableSet, double _outputComp)
1080  : waveformName(_waveformName)
1081  , tableFs(_tableFs)
1082  , tableLengths(_tableLengths)
1083  , ppHexTableSet(_ppHexTableSet)
1084  , outputComp(_outputComp)
1085  { }
1086 
1087  // --- ptr to array of table lengths
1088  uint32_t* tableLengths = nullptr;
1089  uint64_t** ppHexTableSet = nullptr;
1090 
1091  // --- fs for this table set
1092  double tableFs = 44100.0;
1093 
1094  // --- output scaling factor (NOT volume or attenuation, waveform specific)
1095  double outputComp = 1.0;
1096 
1097  // --- GUI string for this waveform
1098  const char* waveformName;
1099  };
1100 
1121  {
1122  SynthLabBankSet(unsigned int _tablePtrsCount, SynthLabTableSet** _tablePtrs, std::string* _tableNames)
1123  : tablePtrsCount(_tablePtrsCount)
1124  , tablePtrs(_tablePtrs)
1125  , tableNames(_tableNames) {}
1126 
1127  unsigned int tablePtrsCount = 32;
1129  std::string* tableNames = nullptr;
1130  };
1131 
1135  const uint32_t kDefaultWaveTableLength = 256;
1136 
1154  {
1155  StaticWavetable() {}
1156 
1157  StaticWavetable(const uint64_t* _table, uint32_t _tableLength, const char* _waveformName,
1158  double _outputComp = 1.0, double _tableFs = 44100)
1159  : uTable(_table)
1160  , tableLength(_tableLength)
1161  , waveformName(_waveformName)
1162  , outputComp(_outputComp)
1163  , tableFs(_tableFs)
1164  {
1165  wrapMask = tableLength - 1;
1166  dTable = nullptr;
1167  }
1168 
1169  StaticWavetable(const double* _table, uint32_t _tableLength, const char* _waveformName,
1170  double _outputComp = 1.0, double _tableFs = 44100)
1171  : dTable(_table)
1172  , tableLength(_tableLength)
1173  , waveformName(_waveformName)
1174  , outputComp(_outputComp)
1175  , tableFs(_tableFs)
1176  {
1177  wrapMask = tableLength - 1;
1178  uTable = nullptr;
1179  }
1180 
1181  // --- either/or static tables
1182  const uint64_t* uTable;
1183  const double* dTable;
1186  double outputComp = 1.0;
1187  double tableFs = 44100.0;
1188  const char* waveformName;
1189  };
1190 
1210  {
1211  DynamicWavetable() {}
1212 
1213  DynamicWavetable(std::shared_ptr<double> _table, uint32_t _tableLength, const char* _waveformName,
1214  double _outputComp = 1.0, double _tableFs = 44100)
1215  : table(_table)
1216  , tableLength(_tableLength)
1217  , waveformName(_waveformName)
1218  , outputComp(_outputComp)
1219  , tableFs(_tableFs)
1220  {
1221  wrapMask = tableLength - 1;
1222  }
1223 
1224  std::shared_ptr<double> table = nullptr;
1227  double outputComp = 1.0;
1228  double tableFs = 44100.0;
1229  const char* waveformName;
1230  };
1231 
1232 
1251  {
1252  public:
1253  WavetableDatabase() {}
1255 
1257  virtual IWavetableSource* getTableSource(const char* uniqueTableName) override;
1258  virtual bool addTableSource(const char* uniqueTableName, IWavetableSource* tableSource) override;
1259  virtual bool removeTableSource(const char* uniqueTableName) override;
1260  virtual bool clearTableSources() override;
1261 
1264 
1265  protected:
1266  typedef std::map < std::string, IWavetableSource* > wavetableSourceMap;
1267  wavetableSourceMap wavetableDatabase;
1268  };
1269 
1270 
1289  {
1290  public:
1291  PCMSampleDatabase() {}
1293 
1295  virtual IPCMSampleSource* getSampleSource(const char* uniqueSampleSetName) override;
1296  virtual bool addSampleSource(const char* uniqueSampleSetName, IPCMSampleSource* sampleSource) override;
1297  virtual bool removeSampleSource(const char* uniqueSampleSetName) override;
1298  virtual bool clearSampleSources() override;
1299 
1302 
1303  protected:
1304  typedef std::map < std::string, IPCMSampleSource* >sampleSourceMap;
1305  sampleSourceMap sampleDatabase;
1306  std::vector<IPCMSampleSource*> sources;
1307  };
1308 
1327  {
1328  public:
1329  SynthProcessInfo(){}
1330  SynthProcessInfo(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
1331  ~SynthProcessInfo() {}
1332 
1334  void pushMidiEvent(midiEvent event);
1335  void clearMidiEvents();
1336  uint32_t getMidiEventCount();
1337  midiEvent* getMidiEvent(uint32_t index);
1338 
1340  double absoluteBufferTime_Sec = 0.0;
1341  double BPM = 0.0;
1342  double timeSigNumerator = 0.0;
1343  uint32_t timeSigDenomintor = 0;
1344 
1345  protected:
1347  std::vector<midiEvent> midiEventQueue;
1348  };
1349 
1366  {
1367  public:
1368  MidiInputData();
1369  ~MidiInputData() {}
1370 
1372  virtual uint32_t getGlobalMIDIData(uint32_t index);
1373  virtual uint32_t getCCMIDIData(uint32_t index);
1374  virtual uint32_t getAuxDAWDataUINT(uint32_t index);
1375  virtual float getAuxDAWDataFloat(uint32_t index);
1376 
1378  void setGlobalMIDIData(uint32_t index, uint32_t value);
1379  void setCCMIDIData(uint32_t index, uint32_t value);
1380  void setAuxDAWDataUINT(uint32_t index, uint32_t value);
1381  void setAuxDAWDataFloat(uint32_t index, float value);
1382 
1384  IMidiInputData* getIMIDIInputData() { return this; }
1385 
1386  protected:
1387  // --- shared MIDI tables, via IMIDIData
1388  uint32_t globalMIDIData[kNumMIDIGlobals];
1390  double auxData[kNumMIDIAuxes];
1391  };
1392 
1409  class Modulators : public IModulator
1410  {
1411  public:
1412  Modulators();
1413 
1415  virtual double* getModArrayPtr(uint32_t index);
1416  virtual double getModValue(uint32_t index);
1417  virtual void setModValue(uint32_t index, double value);
1418 
1419  // --- fast clearing of array
1420  void clear();
1421 
1423  void initInputValues();
1424 
1426  IModulator* getModulatorPtr() { return this; }
1427 
1428  protected:
1429  // --- array of modulation inputs or outputs
1430  double modArray[MAX_MODULATION_CHANNELS];
1431  };
1432 
1459  {
1460  public:
1467  virtual ~ModuleCore() { }
1468 
1470  virtual bool reset(CoreProcData& processInfo) = 0;
1471  virtual bool update(CoreProcData& processInfo) = 0;
1472  virtual bool render(CoreProcData& processInfo) = 0;
1473  virtual bool doNoteOn(CoreProcData& processInfo) = 0;
1474  virtual bool doNoteOff(CoreProcData& processInfo) = 0;
1475 
1477  virtual int32_t getState() { return -1; }
1478  virtual bool shutdown() { return false; }
1479  virtual void setSustainOverride(bool sustain) { return; }
1480  virtual void setStandAloneMode(bool b) { standAloneMode = b; }
1481 
1483  bool startGlideModulation(GlideInfo& glideInfo) {
1484  return glideModulator->startModulator(glideInfo.startMIDINote, glideInfo.endMIDINote, glideInfo.glideTime_mSec, glideInfo.sampleRate);
1485  }
1486 
1488  uint32_t getModuleType() { return moduleType; }
1489  const char* getModuleName() { return moduleName; }
1490  void* getModuleHandle() { return moduleHandle; }
1491  void setModuleHandle(void* handle) { moduleHandle = handle; }
1492  uint32_t getModuleIndex() { return moduleIndex; }
1493  void setModuleIndex(uint32_t index) { moduleIndex = index; }
1494 
1505 
1506  protected:
1507  // --- module
1509  const char* moduleName = nullptr;
1510  void* moduleHandle = nullptr;
1511  uint32_t moduleIndex = 0;
1513  bool standAloneMode = false;
1514  std::unique_ptr<GlideModulator> glideModulator;
1515  };
1516 
1540  {
1541  public:
1542  SynthModule(std::shared_ptr<MidiInputData> _midiInputData);
1543  virtual ~SynthModule();
1544 
1546  virtual bool reset(double _sampleRate) = 0;
1547  virtual bool update() = 0;
1548  virtual bool render(uint32_t samplesToProcess = 1) = 0;
1549  virtual bool doNoteOn(MIDINoteEvent& noteEvent) = 0;
1550  virtual bool doNoteOff(MIDINoteEvent& noteEvent) = 0;
1551 
1553  virtual bool initialize(const char* _dllDirectory) { dllDirectory = _dllDirectory; return true; }
1554 
1556  virtual int32_t getState() { return -1; }
1557  virtual bool shutdown() { return false; }
1558 
1560  virtual bool startGlideModulation(GlideInfo& glideInfo);
1561 
1563  std::shared_ptr<Modulators> getModulationInput() { return modulationInput; }
1564  std::shared_ptr<Modulators> getModulationOutput() { return modulationOutput; }
1565 
1567  std::shared_ptr<AudioBuffer> getAudioBuffers() { return audioBuffers; }
1568 
1570  void setUnisonMode(double _unisonDetuneCents, double _unisonStarPhase) {
1571  unisonDetuneCents = _unisonDetuneCents; unisonStartPhase = _unisonStarPhase;
1572  }
1573 
1575  void setFMBuffer(std::shared_ptr<AudioBuffer> pmBuffer) { fmBuffer = pmBuffer; }
1576  void clearFMBuffer() { fmBuffer = nullptr; }
1577 
1580  virtual bool getModuleStrings(std::vector<std::string>& moduleStrings, std::string ignoreStr = "");
1581  virtual bool getModuleStrings(uint32_t coreIndex, std::vector<std::string>& moduleStrings, std::string ignoreStr);
1582  virtual bool getAllModuleStrings(std::vector<std::string>& moduleStrings, std::string ignoreStr);
1583  virtual bool getModKnobStrings(std::vector<std::string>& modKnobStrings);
1584  virtual bool getModKnobStrings(uint32_t coreIndex, std::vector<std::string>& modKnobStrings);
1585  virtual bool getModuleCoreStrings(std::vector<std::string>& moduleCoreStrings);
1586  virtual bool addModuleCore(std::shared_ptr<ModuleCore> core);
1587  virtual uint32_t getSelectedCoreIndex();
1588  virtual bool selectModuleCore(uint32_t index);
1589  virtual bool selectDefaultModuleCore();
1590  virtual bool clearModuleCores();
1591  virtual void setStandAloneMode(bool b);
1592 
1593  protected:
1595  std::shared_ptr<Modulators> modulationInput = std::make_shared<Modulators>();
1596 
1598  std::shared_ptr<Modulators> modulationOutput = std::make_shared<Modulators>();
1599 
1601  std::shared_ptr<MidiInputData> midiInputData = nullptr;
1602 
1604  std::shared_ptr<AudioBuffer> audioBuffers = nullptr;
1605 
1607  std::unique_ptr<GlideModulator> glideModulator;
1608 
1610  std::shared_ptr<AudioBuffer> fmBuffer = nullptr;
1611 
1613  std::shared_ptr<ModuleCore> moduleCores[NUM_MODULE_CORES];
1614  std::shared_ptr<ModuleCore> selectedCore = nullptr;
1615 
1618 
1619  double unisonDetuneCents = 0.0;
1620  double unisonStartPhase = 0.0;
1621  bool standAloneMode = false;
1622 
1625  std::string dllDirectory;
1626  };
1627 
1628 
1629  // ----------------------------------- FX-FILTERING OBJECTS ---------------------------------------------- //
1630  //
1631  /*
1632  Objects taken primarily from Will Pirkle's FX book (2nd edition)
1633  Most objects are heavily detailed in the book Designing Audio Effects Plugins in C++ 2nd Ed and
1634  at http://aspikplugins.com/sdkdocs/html/index.html
1635  */
1636  //
1637  // ------------------------------------------------------------------------------------------------------- //
1638 
1651  inline double doLinearInterp(double y1, double y2, double fractional_X)
1652  {
1653  // --- check invalid condition
1654  if (fractional_X >= 1.0) return y2;
1655 
1656  // --- use weighted sum method of interpolating
1657  return fractional_X*y2 + (1.0 - fractional_X)*y1;
1658  }
1659 
1674  template <typename T>
1676  {
1677  public:
1678  CircularBuffer() {} /* C-TOR */
1679  ~CircularBuffer() {} /* D-TOR */
1680 
1682  void flushBuffer() { memset(&buffer[0], 0, bufferLength * sizeof(T)); }
1683 
1686  void createCircularBuffer(uint32_t _bufferLength)
1687  {
1688  // --- find nearest power of 2 for buffer, and create
1689  createCircularBufferPowerOfTwo((uint32_t)(pow(2, ceil(log(_bufferLength) / log(2)))));
1690  }
1691 
1694  void createCircularBufferPowerOfTwo(uint32_t _bufferLengthPowerOfTwo)
1695  {
1696  // --- reset to top
1697  writeIndex = 0;
1698 
1699  // --- find nearest power of 2 for buffer, save it as bufferLength
1700  bufferLength = _bufferLengthPowerOfTwo;
1701 
1702  // --- save (bufferLength - 1) for use as wrapping mask
1703  wrapMask = bufferLength - 1;
1704 
1705  // --- create new buffer
1706  buffer.reset(new T[bufferLength]);
1707 
1708  // --- flush buffer
1709  flushBuffer();
1710  }
1711 
1713  void writeBuffer(T input)
1714  {
1715  // --- write and increment index counter
1716  buffer[writeIndex++] = input;
1717 
1718  // --- wrap if index > bufferlength - 1
1719  writeIndex &= wrapMask;
1720  }
1721 
1723  T readBuffer(int delayInSamples)//, bool readBeforeWrite = true)
1724  {
1725  // --- subtract to make read index
1726  // note: -1 here is because we read-before-write,
1727  // so the *last* write location is what we use for the calculation
1728  int readIndex = (writeIndex - 1) - delayInSamples;
1729 
1730  // --- autowrap index
1731  readIndex &= wrapMask;
1732 
1733  // --- read it
1734  return buffer[readIndex];
1735  }
1736 
1738  T readBuffer(double delayInFractionalSamples)
1739  {
1740  // --- truncate delayInFractionalSamples and read the int part
1741  T y1 = readBuffer((int)delayInFractionalSamples);
1742 
1743  // --- if no interpolation, just return value
1744  if (!interpolate) return y1;
1745 
1746  // --- else do interpolation
1747  //
1748  int readIndexNext = (int)delayInFractionalSamples + 1;
1749 
1750  // --- autowrap index
1751  readIndexNext &= wrapMask;
1752 
1753  // --- read the sample at n+1 (one sample OLDER)
1754  T y2 = readBuffer(readIndexNext);
1755 
1756  // --- get fractional part
1757  double fraction = delayInFractionalSamples - (uint32_t)delayInFractionalSamples;
1758 
1759  // --- do the interpolation (you could try different types here)
1760  return doLinearInterp(y1, y2, fraction);
1761  }
1762 
1764  void setInterpolate(bool b) { interpolate = b; }
1765 
1766  private:
1767  std::unique_ptr<T[]> buffer = nullptr;
1768  uint32_t writeIndex = 0;
1769  uint32_t bufferLength = 1024;
1770  uint32_t wrapMask = 1023;
1771  bool interpolate = true;
1772  };
1773 
1792  {
1793  public:
1794  DelayLine(void) {} /* C-TOR */
1795  ~DelayLine(void) {} /* D-TOR */
1796 
1797  public:
1799  void clear(){ delayBuffer.flushBuffer();}
1800 
1808  void reset(double _sampleRate, double minimumPitch = MIDI_NOTE_0_FREQ) // 8.176 = MIDI note 0
1809  {
1810  // ---
1811  delayBuffer.createCircularBuffer(_sampleRate / minimumPitch);
1812  clear();
1813  }
1814 
1821  void setDelayInSamples(double _delaySamples)
1822  {
1823  delaySamples = _delaySamples;
1824  }
1825 
1832  void writeDelay(double xn)
1833  {
1834  // --- write to delay buffer
1835  delayBuffer.writeBuffer(xn);
1836  }
1837 
1844  double readDelay()
1845  {
1846  double yn = delayBuffer.readBuffer(delaySamples);
1847  return yn;
1848  }
1849 
1850  private:
1851  // --- our only variable
1852  double delaySamples = 0;
1853 
1854  // --- delay buffer of doubles
1855  CircularBuffer<double> delayBuffer;
1856  };
1857 
1858 
1871  struct BQCoeffs
1872  {
1873  // --- filter coefficients
1874  double coeff[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
1875  };
1876 
1891  {
1892  public:
1893  BQAudioFilter(void) {} /* C-TOR */
1894  ~BQAudioFilter(void) {} /* D-TOR */
1895 
1896  public:
1898  void reset(){ flushDelays(); }
1899 
1902  {
1903  for (uint32_t i = 0; i<numStates; i++)
1904  state[i] = 0.0;
1905  }
1906 
1908  void setCoeffs(BQCoeffs& _coeffs) {
1909  bq = _coeffs;
1910  }
1911 
1913  void copyCoeffs(BQAudioFilter& destination) {
1914  destination.setCoeffs(bq);
1915  }
1916 
1923  double processAudioSample(double xn)
1924  {
1925  double yn = bq.coeff[a0] * xn + bq.coeff[a1] * state[xz1] + bq.coeff[a2] * state[xz2] - bq.coeff[b1] * state[yz1] - bq.coeff[b2] * state[yz2];
1926  state[xz2] = state[xz1];
1927  state[xz1] = xn;
1928  state[yz2] = state[yz1];
1929  state[yz1] = yn;
1930 
1931  return xn*bq.coeff[d0] + yn*bq.coeff[c0];
1932  }
1933 
1934  protected:
1935  enum { a0, a1, a2, b1, b2, c0, d0 };
1936  enum { xz1, xz2, yz1, yz2, numStates };
1937  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
1939  };
1940 
1941 
1956  {
1957  public:
1958  FracDelayAPF(void) {} /* C-TOR */
1959  ~FracDelayAPF(void) {} /* D-TOR */
1960 
1961  public:
1963  void reset()
1964  {
1965  state[0] = 0.0;
1966  state[1] = 0.0;
1967  }
1968 
1970  void setAlpha(double _alpha)
1971  {
1972  alpha = _alpha;
1973  }
1974 
1981  double processAudioSample(double xn)
1982  {
1983  double yn = xn*alpha + state[0] - alpha*state[1];
1984  state[0] = xn;
1985  state[1] = yn;
1986  return yn;
1987  }
1988 
1989  private:
1990  // --- our only coefficient
1991  double alpha = 0.0;
1992  double state[2] = { 0.0, 0.0 };
1993  };
1994 
1995 
2011  {
2012  public:
2013  ResLoopFilter(void) {} /* C-TOR */
2014  ~ResLoopFilter(void) {} /* D-TOR */
2015 
2016  public:
2018  void reset()
2019  {
2020  state[0] = 0.0;
2021  state[1] = 0.0;
2022  }
2023 
2030  double processAudioSample(double xn)
2031  {
2032  double yn = 0.5*xn + 0.5*state[0];
2033  state[0] = xn;
2034  return yn;
2035  }
2036 
2037  private:
2038  double state[2] = { 0.0, 0.0 };
2039  };
2040 
2041 
2057  {
2058  public:
2059  DCRemovalFilter(void) {} /* C-TOR */
2060  ~DCRemovalFilter(void) {} /* D-TOR */
2061 
2062  public:
2064  void reset(double _sampleRate)
2065  {
2066  for (uint32_t i = 0; i<numStates; i++)
2067  state[i] = 0.0;
2068 
2069  sampleRate = _sampleRate;
2070 
2071  // --- see book for formulae
2072  double theta_c = kTwoPi*fc / sampleRate;
2073  double gamma = cos(theta_c) / (1.0 + sin(theta_c));
2074 
2075  // --- update coeffs
2076  coeffs[a0] = (1.0 + gamma) / 2.0;
2077  coeffs[a1] = -(1.0 + gamma) / 2.0;
2078  coeffs[a2] = 0.0;
2079  coeffs[b1] = -gamma;
2080  coeffs[b2] = 0.0;
2081  }
2082 
2089  double processAudioSample(double xn)
2090  {
2091  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2092  state[xz2] = state[xz1];
2093  state[xz1] = xn;
2094  state[yz2] = state[yz1];
2095  state[yz1] = yn;
2096  return yn;
2097  }
2098 
2099  protected:
2100  enum { xz1, xz2, yz1, yz2, numStates };
2101  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2102  enum { a0, a1, a2, b1, b2 };
2103  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2104  double fc = 2.0;
2105  double sampleRate = 1.0;
2106  };
2107 
2108 
2123  class TinyBPF
2124  {
2125  public:
2126  TinyBPF(void) {} /* C-TOR */
2127  ~TinyBPF(void) {} /* D-TOR */
2128 
2129  public:
2131  void reset(double _sampleRate)
2132  {
2133  for (uint32_t i = 0; i<numStates; i++)
2134  state[i] = 0.0;
2135 
2136  sampleRate = _sampleRate;
2137  }
2138 
2140  void setParameters(double _fc, double _Q)
2141  {
2142  if (fc == _fc && Q == _Q)
2143  return;
2144 
2145  fc = _fc;
2146  Q = _Q;
2147 
2148  // --- see book for formulae
2149  double K = tan(kPi*fc / sampleRate);
2150  double delta = K*K*Q + K + Q;
2151 
2152  // --- update coeffs
2153  coeffs[a0] = K / delta;;
2154  coeffs[a1] = 0.0;
2155  coeffs[a2] = -K / delta;
2156  coeffs[b1] = 2.0*Q*(K*K - 1) / delta;
2157  coeffs[b2] = (K*K*Q - K + Q) / delta;
2158  }
2159 
2166  double processAudioSample(double xn)
2167  {
2168  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2169  state[xz2] = state[xz1];
2170  state[xz1] = xn;
2171  state[yz2] = state[yz1];
2172  state[yz1] = yn;
2173  return yn;
2174  }
2175 
2176  protected:
2177  enum { xz1, xz2, yz1, yz2, numStates };
2178  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2179  enum { a0, a1, a2, b1, b2 };
2180  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2181  double fc = 5.0;
2182  double Q = 0.5;
2183  double sampleRate = 1.0;
2184  };
2185 
2201  {
2202  public:
2203  LP2Filter(void) {} /* C-TOR */
2204  ~LP2Filter(void) {} /* D-TOR */
2205 
2206  public:
2208  void reset(double _sampleRate)
2209  {
2210  sampleRate = _sampleRate;
2211  clear();
2212  }
2213 
2215  void clear()
2216  {
2217  for (uint32_t i = 0; i<numStates; i++)
2218  state[i] = 0.0;
2219  }
2220 
2222  void setParameters(double _fc, double _Q)
2223  {
2224  if (fc == _fc && Q == _Q)
2225  return;
2226 
2227  fc = _fc;
2228  Q = _Q;
2229 
2230  // --- see book for formulae
2231  double theta_c = 2.0*kPi*fc / sampleRate;
2232  double d = 1.0 / Q;
2233  double betaNumerator = 1.0 - ((d / 2.0)*(sin(theta_c)));
2234  double betaDenominator = 1.0 + ((d / 2.0)*(sin(theta_c)));
2235 
2236  double beta = 0.5*(betaNumerator / betaDenominator);
2237  double gamma = (0.5 + beta)*(cos(theta_c));
2238  double alpha = (0.5 + beta - gamma) / 2.0;
2239 
2240  // --- update coeffs
2241  coeffs[a0] = alpha;
2242  coeffs[a1] = 2.0*alpha;
2243  coeffs[a2] = alpha;
2244  coeffs[b1] = -2.0*gamma;
2245  coeffs[b2] = 2.0*beta;
2246  }
2247 
2254  double processAudioSample(double xn)
2255  {
2256  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2257  state[xz2] = state[xz1];
2258  state[xz1] = xn;
2259  state[yz2] = state[yz1];
2260  state[yz1] = yn;
2261  return yn;
2262  }
2263 
2264  protected:
2265  enum { xz1, xz2, yz1, yz2, numStates };
2266  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2267  enum { a0, a1, a2, b1, b2 };
2268  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2269  double fc = 5.0;
2270  double Q = 0.5;
2271  double sampleRate = 1.0;
2272  };
2273 
2274 
2290  {
2291  public:
2292  HP2Filter(void) {} /* C-TOR */
2293  ~HP2Filter(void) {} /* D-TOR */
2294 
2295  public:
2297  void reset(double _sampleRate)
2298  {
2299  for (uint32_t i = 0; i<numStates; i++)
2300  state[i] = 0.0;
2301 
2302  sampleRate = _sampleRate;
2303  }
2304 
2306  void setParameters(double _fc, double _Q)
2307  {
2308  if (fc == _fc && Q == _Q)
2309  return;
2310 
2311  fc = _fc;
2312  Q = _Q;
2313 
2314  double theta_c = kTwoPi*fc / sampleRate;
2315  double d = 1.0 / Q;
2316 
2317  // --- see book for formulae
2318  double betaNumerator = 1.0 - ((d / 2.0)*(sin(theta_c)));
2319  double betaDenominator = 1.0 + ((d / 2.0)*(sin(theta_c)));
2320 
2321  double beta = 0.5*(betaNumerator / betaDenominator);
2322  double gamma = (0.5 + beta)*(cos(theta_c));
2323  double alpha = (0.5 + beta + gamma) / 2.0;
2324 
2325  // --- update coeffs
2326  coeffs[a0] = alpha;
2327  coeffs[a1] = -2.0*alpha;
2328  coeffs[a2] = alpha;
2329  coeffs[b1] = -2.0*gamma;
2330  coeffs[b2] = 2.0*beta;
2331  }
2332 
2339  double processAudioSample(double xn)
2340  {
2341  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2342  state[xz2] = state[xz1];
2343  state[xz1] = xn;
2344  state[yz2] = state[yz1];
2345  state[yz1] = yn;
2346  return yn;
2347  }
2348 
2349  protected:
2350  enum { xz1, xz2, yz1, yz2, numStates };
2351  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2352  enum { a0, a1, a2, b1, b2 };
2353  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2354  double fc = 5.0;
2355  double Q = 0.5;
2356  double sampleRate = 1.0;
2357  };
2358 
2374  {
2375  public:
2376  TinyReson(void) {} /* C-TOR */
2377  ~TinyReson(void) {} /* D-TOR */
2378 
2379  public:
2381  void reset(double _sampleRate)
2382  {
2383  for(uint32_t i=0; i<numStates; i++)
2384  state[i] = 0.0;
2385 
2386  sampleRate = _sampleRate;
2387  }
2388 
2390  void setParameters(double _fc, double _Q)
2391  {
2392  if (fc == _fc && Q == _Q)
2393  return;
2394 
2395  fc = _fc;
2396  Q = _Q;
2397 
2398  double theta_c = kTwoPi*fc / sampleRate;
2399  double BW = fc / Q;
2400  coeffs[b2] = exp(-2.0*kPi*(BW / sampleRate));
2401  coeffs[b1] = ((-4.0*coeffs[b2]) / (1.0 + coeffs[b2]))*cos(theta_c);
2402  coeffs[a0] = 1.0 - pow(coeffs[b2], 0.5);
2403  coeffs[a2] = -coeffs[a0];
2404  }
2405 
2412  double processAudioSample(double xn, double loss = 1.0)
2413  {
2414  double yn = coeffs[a0]*xn + coeffs[a2]*state[xz2] - coeffs[b1]*state[yz1] -coeffs[b2]*state[yz2];
2415  state[xz2] = state[xz1];
2416  state[xz1] = xn;
2417  state[yz2] = state[yz1];
2418  state[yz1] = yn * loss;
2419  return yn;
2420  }
2421 
2422  protected:
2423  enum { xz1, xz2, yz1, yz2, numStates };
2424  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2425  enum { a0, a2, b1, b2 };
2426  double coeffs[4] = { 0.0, 0.0, 0.0, 0.0 };
2427  double fc = 440.0;
2428  double Q = 0.5;
2429  double sampleRate = 1.0;
2430  };
2431 
2447  {
2448  public:
2449  LowShelfFilter(void) {} /* C-TOR */
2450  ~LowShelfFilter(void) {} /* D-TOR */
2451 
2452  public:
2454  void reset(double _sampleRate)
2455  {
2456  for (uint32_t i = 0; i<numStates; i++)
2457  state[i] = 0.0;
2458 
2459  sampleRate = _sampleRate;
2460  }
2461 
2463  void setParameters(double shelfFreq, double boostCut_dB)
2464  {
2465  double theta_c = kTwoPi*shelfFreq / sampleRate;
2466  double mu = pow(10.0, boostCut_dB / 20.0);
2467 
2468  double beta = 4.0 / (1.0 + mu);
2469  double delta = beta*tan(theta_c / 2.0);
2470  double gamma = (1.0 - delta) / (1.0 + delta);
2471 
2472  // --- update coeffs
2473  coeffs[a0] = (1.0 - gamma) / 2.0;
2474  coeffs[a1] = (1.0 - gamma) / 2.0;
2475  coeffs[a2] = 0.0;
2476  coeffs[b1] = -gamma;
2477  coeffs[b2] = 0.0;
2478 
2479  coeffs[c0] = mu - 1.0;
2480  coeffs[d0] = 1.0;
2481  }
2482 
2489  double processAudioSample(double xn)
2490  {
2491  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2492  state[xz2] = state[xz1];
2493  state[xz1] = xn;
2494  state[yz2] = state[yz1];
2495  state[yz1] = yn;
2496 
2497  return xn*coeffs[d0] + yn*coeffs[c0];
2498  }
2499 
2500  protected:
2501  enum { xz1, xz2, yz1, yz2, numStates };
2502  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2503  enum { a0, a1, a2, b1, b2, c0, d0 };
2504  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2505  double fc = 440.0;
2506  double boostCut_dB = 0.0;
2507  double sampleRate = 1.0;
2508  };
2509 
2510 
2526  {
2527  public:
2528  HighShelfFilter(void) {} /* C-TOR */
2529  ~HighShelfFilter(void) {} /* D-TOR */
2530 
2531  public:
2533  void reset(double _sampleRate)
2534  {
2535  for (uint32_t i = 0; i<numStates; i++)
2536  state[i] = 0.0;
2537 
2538  sampleRate = _sampleRate;
2539  }
2540 
2542  void setParameters(double shelfFreq, double boostCut_dB)
2543  {
2544  double theta_c = kTwoPi*shelfFreq / sampleRate;
2545  double mu = pow(10.0, boostCut_dB / 20.0);
2546 
2547  double beta = (1.0 + mu) / 4.0;
2548  double delta = beta*tan(theta_c / 2.0);
2549  double gamma = (1.0 - delta) / (1.0 + delta);
2550 
2551  coeffs[a0] = (1.0 + gamma) / 2.0;
2552  coeffs[a1] = -coeffs[a0];
2553  coeffs[a2] = 0.0;
2554  coeffs[b1] = -gamma;
2555  coeffs[b2] = 0.0;
2556 
2557  coeffs[c0] = mu - 1.0;
2558  coeffs[d0] = 1.0;
2559  }
2560 
2567  double processAudioSample(double xn)
2568  {
2569  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2570  state[xz2] = state[xz1];
2571  state[xz1] = xn;
2572  state[yz2] = state[yz1];
2573  state[yz1] = yn;
2574 
2575  return xn*coeffs[d0] + yn*coeffs[c0];
2576  }
2577 
2578  protected:
2579  enum { xz1, xz2, yz1, yz2, numStates };
2580  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2581  enum { a0, a1, a2, b1, b2, c0, d0 };
2582  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2583  double fc = 440.0;
2584  double boostCut_dB = 0.0;
2585  double sampleRate = 1.0;
2586  };
2587 
2603  {
2604  public:
2605  ParametricFilter(void) {} /* C-TOR */
2606  ~ParametricFilter(void) {} /* D-TOR */
2607 
2608  public:
2610  void reset(double _sampleRate)
2611  {
2612  for (uint32_t i = 0; i<numStates; i++)
2613  state[i] = 0.0;
2614 
2615  sampleRate = _sampleRate;
2616  }
2617 
2619  void setParameters(double _fc, double _Q, double _boostCut_dB)
2620  {
2621  if (fc == _fc && Q == _Q && boostCut_dB == _boostCut_dB)
2622  return;
2623  fc = _fc;
2624  Q = _Q;
2625  boostCut_dB = _boostCut_dB;
2626 
2627  // --- see book for formulae
2628  double theta_c = kTwoPi*fc / sampleRate;
2629  double mu = pow(10.0, boostCut_dB / 20.0);
2630 
2631  // --- clamp to 0.95 pi/2 (you can experiment with this)
2632  double tanArg = theta_c / (2.0 * Q);
2633  if (tanArg >= 0.95*kPi / 2.0) tanArg = 0.95*kPi / 2.0;
2634 
2635  // --- intermediate variables (you can condense this if you wish)
2636  double zeta = 4.0 / (1.0 + mu);
2637  double betaNumerator = 1.0 - zeta*tan(tanArg);
2638  double betaDenominator = 1.0 + zeta*tan(tanArg);
2639 
2640  double beta = 0.5*(betaNumerator / betaDenominator);
2641  double gamma = (0.5 + beta)*(cos(theta_c));
2642  double alpha = (0.5 - beta);
2643 
2644  // --- update coeffs
2645  coeffs[a0] = alpha;
2646  coeffs[a1] = 0.0;
2647  coeffs[a2] = -alpha;
2648  coeffs[b1] = -2.0*gamma;
2649  coeffs[b2] = 2.0*beta;
2650 
2651  coeffs[c0] = mu - 1.0;
2652  coeffs[d0] = 1.0;
2653  }
2654 
2661  double processAudioSample(double xn)
2662  {
2663  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2664  state[xz2] = state[xz1];
2665  state[xz1] = xn;
2666  state[yz2] = state[yz1];
2667  state[yz1] = yn;
2668 
2669  return xn*coeffs[d0] + yn*coeffs[c0];
2670  }
2671 
2672  protected:
2673  enum { xz1, xz2, yz1, yz2, numStates };
2674  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2675  enum { a0, a1, a2, b1, b2, c0, d0 };
2676  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2677  double fc = 0.0;
2678  double Q = 0.0;
2679  double boostCut_dB = 0.0;
2680  double sampleRate = 1.0;
2681  };
2682 
2683 
2699  {
2700  public:
2701  LP1PFilter(void) {} /* C-TOR */
2702  ~LP1PFilter(void) {} /* D-TOR */
2703 
2704  public:
2706  void reset(double _sampleRate)
2707  {
2708  clear();
2709  sampleRate = _sampleRate;
2710  }
2711 
2713  void clear()
2714  {
2715  for (uint32_t i = 0; i<numStates; i++)
2716  state[i] = 0.0;
2717  }
2718 
2720  void setParameters(double _fc)
2721  {
2722  if (fc == _fc)
2723  return;
2724 
2725  fc = _fc;
2726 
2727  // --- see book for formulae
2728  double theta_c = 2.0*kPi*fc / sampleRate;
2729  double gamma = 2.0 - cos(theta_c);
2730 
2731  double filter_b1 = pow((gamma*gamma - 1.0), 0.5) - gamma;
2732  double filter_a0 = 1.0 + filter_b1;
2733 
2734  // --- update coeffs
2735  coeffs[a0] = filter_a0;
2736  coeffs[a1] = 0.0;
2737  coeffs[a2] = 0.0;
2738  coeffs[b1] = filter_b1;
2739  coeffs[b2] = 0.0;
2740  }
2741 
2749  double processAudioSample(double xn)
2750  {
2751  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2752  state[xz2] = state[xz1];
2753  state[xz1] = xn;
2754  state[yz2] = state[yz1];
2755  state[yz1] = yn;
2756  return yn;
2757  }
2758 
2759  protected:
2760  enum { xz1, xz2, yz1, yz2, numStates };
2761  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2762  enum { a0, a1, a2, b1, b2 };
2763  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2764  double fc = 5.0;
2765  double Q = 0.5;
2766  double sampleRate = 1.0;
2767  };
2768 
2772  enum class PluckFilterType {kPluck, kPluckAndBridge, kPickup, kPluckAndPickup, kBridge, kPluckPickupBridge};
2773 
2774 
2793  {
2794  public:
2795  PluckPosFilter(void) {} /* C-TOR */
2796  ~PluckPosFilter(void) {} /* D-TOR */
2797 
2798  public:
2800  void clear()
2801  {
2802  combDelay.clear();
2804  }
2805 
2814  void reset(double _sampleRate, double minimumPitch = MIDI_NOTE_0_FREQ) // 8.176 = MIDI note 0
2815  {
2816  // ---
2817  combDelay.reset(_sampleRate, minimumPitch);
2818  combDelay.clear();
2819 
2820  pickupFilter.reset(_sampleRate);
2821  pickupFilter.setParameters(2500.0, 1.5); // guitar pickup settings
2822 
2823  bridgeIntegrator.reset(_sampleRate);
2824  bridgeIntegrator.setParameters(20.0); // lower than the lowest note to synthesize which is note 0
2825  }
2826 
2833  void setDelayInSamples(double _delaySamples)
2834  {
2835  // --- the (-1) is needed here because of the way the circular buffer counts samples for read/write
2836  combDelay.setDelayInSamples(_delaySamples - 1);
2837  }
2838 
2848  double processAudioSample(double xn, PluckFilterType type)
2849  {
2850  if (type == PluckFilterType::kBridge)
2851  return 12.0*bridgeIntegrator.processAudioSample(xn);
2852 
2853  if (type == PluckFilterType::kPickup)
2854  return pickupFilter.processAudioSample(xn);
2855 
2856  // --- pluck position
2857  double yn = combDelay.readDelay();
2858  combDelay.writeDelay(xn);
2859 
2860  // --- output pluck
2861  double pluck = 0.5*(xn - yn);
2862  if (type == PluckFilterType::kPluck)
2863  return pluck;
2864 
2865  // --- pluck and pickup
2866  if (type == PluckFilterType::kPluckAndPickup)
2867  return pickupFilter.processAudioSample(pluck);
2868 
2869  // --- pluck and bridge
2870  if (type == PluckFilterType::kPluckAndBridge)
2871  return 12.0*bridgeIntegrator.processAudioSample(pluck);
2872 
2873  if (type == PluckFilterType::kPluckPickupBridge)
2874  {
2875  double pu = 2.0*pickupFilter.processAudioSample(pluck);
2876  return 12.0*bridgeIntegrator.processAudioSample(pu);
2877  }
2878 
2879 
2880  return xn; // should never get here
2881  }
2882 
2883  protected:
2886  LP2Filter pickupFilter;
2887  };
2888 
2889 
2890 
2891 
2892 } // namespace
2893 
3159 #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:2833
void reset(double _sampleRate)
Definition: synthbase.h:2706
std::string * tableNames
names of tables
Definition: synthbase.h:1129
void setCCMIDIData(uint32_t index, uint32_t value)
set the CC MIDI value
Definition: synthbase.cpp:1241
Object that acts as the PCM sample database, as shared synth-wide resource. You should study this esp...
Definition: synthbase.h:1288
uint32_t tableLength
length
Definition: synthbase.h:1184
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:317
const char * dllPath
path to the plugin, used for finding PCM sample WAV files
Definition: synthbase.h:1036
std::shared_ptr< Modulators > modulationInput
Definition: synthbase.h:1595
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:1522
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2089
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:372
bool setGlideTime(double glideTime_mSec, double sampleRate)
Change the glide time; this is optional.
Definition: synthbase.cpp:764
Implements a first order APF that is used to generate a fractional delay for the physcial model of a ...
Definition: synthbase.h:1955
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2390
const uint32_t NUM_MODULE_CORES
Definition: synthconstants.h:132
~PCMSampleDatabase()
clear out the table sources
Definition: synthbase.cpp:1032
double phaseInc
phase inc = fo/fs
Definition: synthbase.h:156
uint32_t numActiveChannels
number of active channels; not used in SynthLab but available
Definition: synthbase.h:705
double g
one pole filter feedback coefficient
Definition: synthbase.h:329
std::unique_ptr< GlideModulator > glideModulator
Definition: synthbase.h:1607
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:1266
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:1675
double processAudioSample(double xn, PluckFilterType type)
run the string of filters
Definition: synthbase.h:2848
bool isActive()
checks to see if the modulator is running, or completed
Definition: synthbase.h:414
virtual bool addModuleCore(std::shared_ptr< ModuleCore > core)
adds a module core to the module&#39;s set of four
Definition: synthbase.cpp:1555
void writeBuffer(T input)
Definition: synthbase.h:1713
Ultra compact timer object that is used for many different functionalities.
Definition: synthbase.h:180
~WavetableDatabase()
clear out the table sources
Definition: synthbase.cpp:936
void setXFadeTimeSamples(double _xfadeTimeSamples)
Definition: synthbase.h:278
std::shared_ptr< ModuleCore > moduleCores[NUM_MODULE_CORES]
Definition: synthbase.h:1613
double outputComp
output scaling factor (NOT volume or attenuation, waveform specific)
Definition: synthbase.h:1227
void reset(double _sampleRate)
Definition: synthbase.h:2381
std::vector< midiEvent > midiEventQueue
queue
Definition: synthbase.h:1347
double timeSigNumerator
time signature numerator
Definition: synthbase.h:1342
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
IMidiInputData * midiInputData
MIDI input daa, usually owned by engine.
Definition: synthbase.h:1034
Compact modulo counter with wrapping used as the timebase for all oscillators.
Definition: synthbase.h:122
uint32_t globalMIDIData[kNumMIDIGlobals]
the global MIDI INPUT table that is shared across the voices via the IMIDIData interface ...
Definition: synthbase.h:1388
sampleSourceMap sampleDatabase
map that connects PCM sample set names to source objects
Definition: synthbase.h:1305
const double kPi
pi to 80 decimal places
Definition: synthconstants.h:522
double outputComp
output scaling factor
Definition: synthbase.h:1095
void reset(double _sampleRate)
Definition: synthbase.h:2064
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:1638
void setExpireSamples(uint32_t _targetValueInSamples)
set target value
Definition: synthbase.h:190
uint32_t endMIDINote
ending MIDI note for the glide
Definition: synthstructures.h:244
BQCoeffs bq
coefficients
Definition: synthbase.h:1938
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:2814
virtual bool removeTableSource(const char *uniqueTableName)=0
remove a table from the database
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:718
uint32_t xfadeTime_Samples
the target crossfade time
Definition: synthbase.h:245
void setParameters(double shelfFreq, double boostCut_dB)
Definition: synthbase.h:2542
virtual bool selectModuleCore(uint32_t index)
Select a core.
Definition: synthbase.cpp:1589
double doPinkingFilter(double white)
run the pinking filter
Definition: synthbase.cpp:858
void copyCoeffs(BQAudioFilter &destination)
Definition: synthbase.h:1913
Interface for wavetable sources.
Definition: synthbase.h:588
void setParameters(double shelfFreq, double boostCut_dB)
Definition: synthbase.h:2463
float ** outputBuffer
array of output buffer pointers
Definition: synthbase.h:97
IModulator * modulationInputs
input modulation values
Definition: synthbase.h:1023
virtual bool reset(double _sampleRate)=0
double BPM
current BPM, needed for LFO sync to BPM
Definition: synthbase.h:1043
std::shared_ptr< AudioBuffer > audioBuffers
Definition: synthbase.h:1604
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:800
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:293
SynthModule(std::shared_ptr< MidiInputData > _midiInputData)
Constructs a SynthModule.
Definition: synthbase.cpp:1356
double modEnd
ramp mod end value
Definition: synthbase.h:422
virtual uint32_t getAuxDAWDataUINT(uint32_t index)
get aux data value
Definition: synthbase.cpp:1197
void setAuxDAWDataUINT(uint32_t index, uint32_t value)
set the aux data with a uint32_t
Definition: synthbase.cpp:1253
std::shared_ptr< AudioBuffer > fmBuffer
Definition: synthbase.h:1610
Encapsulates the audio buffering requirements of any module that uses audio samples for input and/or ...
Definition: synthbase.h:65
double absoluteBufferTime_Sec
the time in seconds of the sample index at top of buffer
Definition: synthbase.h:1340
virtual bool clearSampleSources() override
clear all entries from the std::map
Definition: synthbase.cpp:1127
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:2289
uint32_t moduleType
type of module, LFO_MODULE, EG_MODULE, etc...
Definition: synthbase.h:1508
float ** getInputBuffers()
Definition: synthbase.h:81
uint32_t samplesToProcess
number of samples in this block
Definition: synthbase.h:1039
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:412
virtual bool removeSampleSource(const char *uniqueSampleSetName) override
remove a PCM sample source from the database
Definition: synthbase.cpp:1102
IModulator * modulationOutputs
output modulation values
Definition: synthbase.h:1024
Object that acts as the wavetable database, as shared synth-wide resource. You should study this espe...
Definition: synthbase.h:1250
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
void reset(double startValue=0.0)
Reset to initial state.
Definition: synthbase.cpp:226
double timerInc
timer incrementer value
Definition: synthbase.h:418
double freqOffset
FM.
Definition: synthbase.h:158
std::shared_ptr< Modulators > modulationOutput
Definition: synthbase.h:1598
void saveState()
Freeze and save the current state of the clock; for PM and FM.
Definition: synthbase.cpp:345
void reset()
Reset to initial state; just resets counters to 0.
Definition: synthbase.cpp:450
void clear()
Definition: synthbase.h:2215
void resetTimer()
reset the counter
Definition: synthbase.h:187
uint32_t xfadeTime_Counter
counter for timer
Definition: synthbase.h:246
double phaseOffset
PM.
Definition: synthbase.h:157
virtual double getModValue(uint32_t index)
get a value from a slot in the modulation array
Definition: synthbase.cpp:1327
Implementation of a high shelving filter.
Definition: synthbase.h:2525
Interface for PCM sample sources.
Definition: synthbase.h:735
~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:1266
bool standAloneMode
flag for stand-alone mode of operation outside of SynthLab
Definition: synthbase.h:1513
void createCircularBufferPowerOfTwo(uint32_t _bufferLengthPowerOfTwo)
Definition: synthbase.h:1694
Implements a simple 2nd order LPF.
Definition: synthbase.h:2200
Implementation of a constant-Q parametric EQ filter.
Definition: synthbase.h:2602
const char * waveformName
string for the GUI
Definition: synthbase.h:1098
double z1
one pole filter state variable
Definition: synthbase.h:330
virtual uint32_t getSelectedCoreIndex()
get the index of the selected core
Definition: synthbase.cpp:1576
const uint32_t UNDEFINED_MODULE
Definition: synthconstants.h:110
IPCMSampleDatabase * getIPCMSampleDatabase()
Definition: synthbase.h:1301
uint32_t wrapMask
wrapping mask = length - 1
Definition: synthbase.h:1185
void setCoeffs(BQCoeffs &_coeffs)
Definition: synthbase.h:1908
virtual uint32_t getCCMIDIData(uint32_t index)
get a CC MIDI data value
Definition: synthbase.cpp:1179
double frequency_Hz
clock frequency
Definition: synthbase.h:159
std::shared_ptr< Modulators > getModulationInput()
Definition: synthbase.h:1563
std::default_random_engine defaultGeneratorEngine
Definition: synthbase.h:487
virtual IWavetableSource * getTableSource(const char *uniqueTableName) override
selects a table source based on the unique table name
Definition: synthbase.cpp:949
Simple object that generates white, gaussian white or pink noise.
Definition: synthbase.h:480
std::shared_ptr< MidiInputData > midiInputData
Definition: synthbase.h:1601
bool reset(double _sampleRate, double startPhase, int32_t xfadeSamples=16)
Specialized reset function that:
Definition: synthbase.cpp:559
IPCMSampleDatabase * sampleDatabase
PCM sample database, usually owned by engine.
Definition: synthbase.h:1033
void reset()
Definition: synthbase.h:1898
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:1890
Structure to hold the seven coeffieicents used in the AudioFilter object from Designing Audio Effects...
Definition: synthbase.h:1871
Definition: synthengine.cpp:16
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2489
void clear()
Definition: synthbase.h:2800
virtual bool addTableSource(const char *uniqueTableName, IWavetableSource *tableSource) override
add a table source to the database
Definition: synthbase.cpp:977
Definition: synthstructures.h:235
uint32_t blockSize
the maximum block size
Definition: synthbase.h:100
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:1441
std::shared_ptr< AudioBuffer > getAudioBuffers()
Definition: synthbase.h:1567
XFader()
simple construction
Definition: synthbase.h:227
double countDownTimer
current timer value; this always counts DOWN regardless of the polarity of the modulation (up or down...
Definition: synthbase.h:464
uint32_t getModuleType()
Definition: synthbase.h:1488
MidiInputData()
clears out all data arrays
Definition: synthbase.cpp:1147
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:85
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:1981
Holds all MIDI input data values.
Definition: synthbase.h:1365
Simple interface for SynthLab filters.
Definition: synthbase.h:966
ModuleCoreData coreData
core strings (16) and mod knob labels (4)
Definition: synthbase.h:1512
uint64_t ** ppHexTableSet
pointers to sets of hex encoded tables
Definition: synthbase.h:1089
void reset(double _sampleRate)
Definition: synthbase.h:2610
void reset(double _sampleRate)
Definition: synthbase.h:2131
virtual bool startGlideModulation(GlideInfo &glideInfo)
starts the built-in glide modulator
Definition: synthbase.cpp:1539
std::unique_ptr< GlideModulator > glideModulator
built-in glide modulator for oscillators
Definition: synthbase.h:1514
void clearMidiEvents()
Clear the queue.
Definition: synthbase.cpp:902
virtual uint32_t getWaveTableLength()=0
void removePhaseOffset()
Remove existing a phase offset to the reset clock; for supporting phase modulation.
Definition: synthbase.cpp:634
void writeDelay(double xn)
write a value into the top of the delay
Definition: synthbase.h:1832
T readBuffer(double delayInFractionalSamples)
Definition: synthbase.h:1738
uint32_t getTick()
tick count
Definition: synthbase.h:201
uint32_t getMidiEventCount()
Definition: synthbase.cpp:910
double sampleRate
fs
Definition: synthbase.h:1038
void initInputValues()
set default values in modulator array
Definition: synthbase.cpp:1300
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:652
Implementation of a one-pole LPF.
Definition: synthbase.h:2698
void reset(double _sampleRate)
Definition: synthbase.h:2208
Modulators()
constructs the modulator object
Definition: synthbase.cpp:1281
Crossfades two values (from A to B) and then holds B for some amount of time.
Definition: synthbase.h:268
IModulator * getModulatorPtr()
Definition: synthbase.h:1426
Specialized version of the RampModulator, with nearly identically named functions to peform the porta...
Definition: synthbase.h:442
virtual float getAuxDAWDataFloat(uint32_t index)
get aux data value
Definition: synthbase.cpp:1215
bool running
state variable
Definition: synthbase.h:247
bool setHardSyncFrequency(double hardSyncFrequency)
Sets the new reset oscillator frequency in Hz.
Definition: synthbase.cpp:575
uint32_t getExpireSamples()
Definition: synthbase.h:194
Holds the audio output samples from reading a PCM sample file.
Definition: synthbase.h:702
Structure for holding information about a static wavetable, that is read from a static location...
Definition: synthbase.h:1153
virtual bool clearTableSources()=0
clear all source pointers
void setUnisonMode(double _unisonDetuneCents, double _unisonStarPhase)
Definition: synthbase.h:1570
void restoreState()
Restore the clock to its last saved state; for PM and FM.
Definition: synthbase.cpp:357
SampleLoopMode
Definition: synthbase.h:710
uint32_t ccMIDIData[kNumMIDICCs]
the global MIDI CC INPUT table that is shared across the voices via the IMIDIData interface ...
Definition: synthbase.h:1389
double modRange
range of modulation output
Definition: synthbase.h:420
uint32_t tableLength
length
Definition: synthbase.h:1225
Implements a first order feedforward LPF with coefficients a0 = a1 = 0.5.
Definition: synthbase.h:2010
void setParameters(double _fc)
Definition: synthbase.h:2720
Implements a simple 2nd order BPF.
Definition: synthbase.h:2123
Abstract base class that encapsulates functionality of a module; used with the Module-Core paradigm...
Definition: synthbase.h:1539
Structure for holding information about a static wavetable, that is read from a static location...
Definition: synthbase.h:1209
void clear()
Definition: synthbase.h:2713
virtual int32_t getState()
Definition: synthbase.h:1556
double processAudioSample(double xn)
Definition: synthbase.h:1923
bool timerExpired()
check if we hit target
Definition: synthbase.h:197
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:1127
bool timerActive
state of modulator, running (true) or expired (false)
Definition: synthbase.h:462
uint32_t wrapMask
mask = length - 1
Definition: synthbase.h:1226
void addPhaseOffset(double offset)
Add a phase offset to the reset clock; for supporting phase modulation.
Definition: synthbase.cpp:625
void reset()
Definition: synthbase.h:2018
Interface for wavetable databases.
Definition: synthbase.h:643
Implements a modulator object.
Definition: synthbase.h:1409
virtual bool addSampleSource(const char *uniqueSampleSetName, IPCMSampleSource *sampleSource) override
add a PCM sample source to the database
Definition: synthbase.cpp:1075
Minute implementation of a 2nd order resonator filter.
Definition: synthbase.h:2373
T readBuffer(int delayInSamples)
Definition: synthbase.h:1723
const char * waveformName
waveform name string
Definition: synthbase.h:1188
uint32_t counter
the timer counter
Definition: synthbase.h:204
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:778
void clear()
Definition: synthbase.h:1799
double outputComp
output scaling factor (NOT volume or attenuation, waveform specific)
Definition: synthbase.h:1186
Interface for modulator objects.
Definition: synthbase.h:530
virtual bool clearSampleSources()=0
clear all the sample sources
PluckFilterType
Definition: synthbase.h:2772
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:1808
Interface for a MIDI input data object.
Definition: synthbase.h:873
XFadeData getCrossfadeData()
Returns the current state of the crossfade or hold.
Definition: synthbase.cpp:478
virtual bool clearTableSources() override
clear all entries from the std::map
Definition: synthbase.cpp:1020
uint32_t getBlockSize()
Definition: synthbase.h:89
void setFrequency(double _frequency_Hz, double _sampleRate)
Set the clock frequency, which calculates the current phase increment value.
Definition: synthbase.cpp:279
double doSlewLimiter(double input)
Definition: synthbase.h:321
void setSlewValue(double _g)
b1 coefficient
Definition: synthbase.h:320
virtual double * getModArrayPtr(uint32_t index)
get a pointer to a slot in the modulation array
Definition: synthbase.cpp:1314
void setXFadeTime(uint32_t _xfadeTime_Samples)
Set the current crossfade time.
Definition: synthbase.cpp:394
void clear()
fast clearing of modulator array
Definition: synthbase.cpp:1290
virtual bool selectDefaultModuleCore()
Select the default core, which is always the first in the list.
Definition: synthbase.cpp:1605
void reset()
Resets object to initialized state.
Definition: synthbase.cpp:382
double coeffs[5]
biquad coefficients
Definition: synthbase.h:2103
uint32_t xfadeTime_Samples
target crossfade time
Definition: synthbase.h:289
virtual int32_t getState()
Definition: synthbase.h:1477
void setParameters(double _fc, double _Q, double _boostCut_dB)
Definition: synthbase.h:2619
void flushDelays()
Definition: synthbase.h:1901
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:1651
const char * waveformName
waveform name
Definition: synthbase.h:1229
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:589
Crossfades two values (from A to B)
Definition: synthbase.h:224
std::shared_ptr< double > table
the table (shared)
Definition: synthbase.h:1224
virtual bool addTableSource(const char *uniqueTableName, IWavetableSource *tableSource)=0
adds a table to the database
const double kTwoPi
2pi to 80 decimal places
Definition: synthconstants.h:529
virtual uint32_t getCCMIDIData(uint32_t index)=0
get a MIDI CC value
virtual bool initialize(const char *_dllDirectory)
Definition: synthbase.h:1553
uint32_t xfadeTime_Counter
crossfade timer counter
Definition: synthbase.h:290
uint32_t timeSigDenomintor
time signature denominator
Definition: synthbase.h:1343
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2339
CoreProcData coreProcessData
Definition: synthbase.h:1624
Implements a simple slew limiter using a one pole lowpass filter.
Definition: synthbase.h:310
void addFrequencyOffset(double _freqOffset)
For frequency modulation, this adds a frequency offset, and recalculates the phase increment value...
Definition: synthbase.cpp:325
void setFMBuffer(std::shared_ptr< AudioBuffer > pmBuffer)
Definition: synthbase.h:1575
virtual bool removeSampleSource(const char *uniqueSampleSetName)=0
remove a PCM sample set from the database
float ** outputBuffers
set of output bufers, one per channel
Definition: synthbase.h:1028
double countUpTimer
current timer value; this always counts UP regardless of the polarity of the modulation (up or down) ...
Definition: synthbase.h:419
void * moduleParameters
module parameters, cloaked as void* – varies according to module
Definition: synthbase.h:1035
double glideRange
range (distance between MIDI note numbers, as double)
Definition: synthbase.h:465
void removePhaseOffset()
For phase modulation, this removes a phase offset, notice that the function does not attempt to wrap ...
Definition: synthbase.cpp:311
This structure holds all of the information needed to for the plugin framework to send MIDI informati...
Definition: synthbase.h:1326
float ** inputBuffers
set of input bufers, one per channel
Definition: synthbase.h:1027
float ** fmBuffers
used for DX synths (phase modulator synths)
Definition: synthbase.h:1029
void removeFrequencyOffset()
For frequency modulation, this removes a frequency offset and recalculates the phase inc...
Definition: synthbase.cpp:336
MIDINoteEvent noteEvent
the MIDI note event for the current audio block
Definition: synthbase.h:1044
IWavetableDatabase * wavetableDatabase
wavetable database, usually owned by engine
Definition: synthbase.h:1032
bool timerActive
state of modulator, running (true) or expired (false)
Definition: synthbase.h:417
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2567
XFader hardSyncFader
crossfader for smearing discontinuity
Definition: synthbase.h:374
bool startGlideModulation(GlideInfo &glideInfo)
Definition: synthbase.h:1483
double doPinkNoise()
Function generate pink noise by filtering white noise.
Definition: synthbase.cpp:843
const uint32_t kDefaultWaveTableLength
Definition: synthbase.h:1135
virtual bool reset(CoreProcData &processInfo)=0
double audioOutput[STEREO_CHANNELS]
array of audio output samples
Definition: synthbase.h:704
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2254
const double * dTable
table of 64-bit doubles
Definition: synthbase.h:1183
uint32_t moduleIndex
index of this core
Definition: synthbase.h:1511
double doHardSyncXFade(double inA, double inB)
Perform the crossfade on the two oscillator signals to smear over the discontinuity.
Definition: synthbase.cpp:611
virtual void setStandAloneMode(bool b)
Sets the stand-alone mode flag on all cores.
Definition: synthbase.cpp:1621
This super-structure holds a set of SynthLabTableSet called a "bank" and used in the morphing wavetab...
Definition: synthbase.h:1120
void setInterpolate(bool b)
Definition: synthbase.h:1764
double state[4]
state registers
Definition: synthbase.h:1937
SynthLabTableSet ** tablePtrs
set of table-sets
Definition: synthbase.h:1128
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:1263
void pushMidiEvent(midiEvent event)
Add a MIDI event to the queue.
Definition: synthbase.cpp:892
This is a very specialized object that performs the hard-sync operation using two SynthClocks...
Definition: synthbase.h:350
Interface for PCM sample databases.
Definition: synthbase.h:807
float ** inputBuffer
array of input buffer pointers
Definition: synthbase.h:96
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:690
void setExpireMilliSec(double timeMSec, double sampleRate)
set target value
Definition: synthbase.h:191
double modStart
ramp mod start value
Definition: synthbase.h:421
void setAlpha(double _alpha)
Definition: synthbase.h:1970
Implements a first order HPF with fc = 2.0Hz.
Definition: synthbase.h:2056
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:1821
virtual uint32_t getGlobalMIDIData(uint32_t index)
get a global MIDI data value
Definition: synthbase.cpp:1163
This is a tiny modulator object that produces an output that ramps up or down linearly between two va...
Definition: synthbase.h:397
double state[NUM_VARS]
for state save
Definition: synthbase.h:162
double hardSyncFrequency
reset oscillator rate
Definition: synthbase.h:375
double unisonStartPhase
unison start phase value for this core
Definition: synthbase.h:1041
uint32_t * tableLengths
pointers to lengths of each of the hex encoded tables
Definition: synthbase.h:1088
double processAudioSample(double xn, double loss=1.0)
run the filter
Definition: synthbase.h:2412
Definition: synthbase.h:1791
const uint64_t * uTable
table of 64-bit HEX values
Definition: synthbase.h:1182
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:101
virtual bool removeTableSource(const char *uniqueTableName) override
remove a table source from the database
Definition: synthbase.cpp:1003
double mcounter
modulo counter [0.0, +1.0], this is the value you use
Definition: synthbase.h:155
double unisonDetuneCents
detuning value for this core
Definition: synthbase.h:1040
double state[4]
state variables
Definition: synthbase.h:2101
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:2454
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:1229
void reset(double _sampleRate)
Definition: synthbase.h:2297
void createCircularBuffer(uint32_t _bufferLength)
Definition: synthbase.h:1686
double doWhiteNoise()
Function generate white noise.
Definition: synthbase.cpp:833
bool holding
state variable for holding
Definition: synthbase.h:293
virtual IPCMSampleSource * getSampleSource(const char *uniqueSampleSetName) override
selects a PCM sample source based on the unique table name
Definition: synthbase.cpp:1046
ModuleCoreData & getModuleData()
provides access to the core data:
Definition: synthbase.h:1504
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2306
double BPM
beats per minute, aka "tempo"
Definition: synthbase.h:1341
DelayLine combDelay
for pluck position
Definition: synthbase.h:2884
double doGaussianWhiteNoise(double mean=0.0, double variance=1.0)
Function generate gaussian white noise.
Definition: synthbase.cpp:823
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2661
double bN[3]
Definition: synthbase.h:496
virtual bool getModKnobStrings(std::vector< std::string > &modKnobStrings)
Gets a std::vector of Mod Knob label strings for the selected core.
Definition: synthbase.cpp:1470
Implementation of a low shelving filter.
Definition: synthbase.h:2446
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:205
This structure defines a set of wavetables that are usually found in .h files and compiled into the s...
Definition: synthbase.h:1075
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:2533
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:742
virtual ~SynthModule()
Removes cores, if any.
Definition: synthbase.cpp:1374
ModuleCoreData moduleData
modulestrings (16) and mod knob labels (4)
Definition: synthbase.h:1617
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:461
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:942
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 readDelay()
read a delayed value at the location specified in the call to setDelayInSamples() ...
Definition: synthbase.h:1844
void flushBuffers()
clear out the audio; used often
Definition: synthbase.cpp:127
void advanceTimer(uint32_t ticks=1)
advance by 1
Definition: synthbase.h:200
void flushBuffer()
Definition: synthbase.h:1682
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:2166
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:1963
This structure holds all of the information needed to call functions on a ModuleCore object...
Definition: synthbase.h:1020
ModuleCore()
Constructs a ModuleCore.
Definition: synthbase.h:1466
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2749
Comnination of three filters in one; note that the figure in the book does not show the variety of co...
Definition: synthbase.h:2792
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:463
bool isActive()
checks to see if the modulator is running, or completed
Definition: synthbase.h:459
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:1390
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2222
const uint32_t kNumMIDICCs
Definition: synthconstants.h:562
virtual void setModValue(uint32_t index, double value)
set a value into a slot in the modulation array
Definition: synthbase.cpp:1341
void * moduleHandle
used for dynamically loading cores from DLLs
Definition: synthbase.h:1510
const char * moduleName
module name must be set in derived constructor
Definition: synthbase.h:1509
bool setModTime(double modTime_mSec, double sampleRate)
Change the modulation time; this is optional.
Definition: synthbase.cpp:676
Abstract base class that encapsulates functionality of a module core; used with the Module-Core parad...
Definition: synthbase.h:1458
const uint32_t MAX_MODULATION_CHANNELS
Definition: synthconstants.h:39
IMidiInputData * getIMIDIInputData()
Definition: synthbase.h:1384
virtual void deleteSamples()=0
Delete the samples, part of destruction process.
SynthClock crossFadeClock
crossfading timer
Definition: synthbase.h:373
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:2140
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:376
LP1PFilter bridgeIntegrator
for bridge LPF
Definition: synthbase.h:2885
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:292
midiEvent * getMidiEvent(uint32_t index)
gets a MIDI event within the event queue
Definition: synthbase.cpp:923
double fc
hardcoded fc value
Definition: synthbase.h:2104
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2030
double auxData[kNumMIDIAuxes]
the aux values, specific to SynthLab
Definition: synthbase.h:1390
uint32_t holdTime_Samples
target hold time
Definition: synthbase.h:291