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 
245 namespace SynthLab
246 {
247  // ---------------------- SYNTH OBJECTS WITHOUT BASE CLASES --------------------------------------------- //
248  //
249  /*
250  These are simple, stand-alone objects or primary synth objects that perform intrinsically
251  basic/fundamental synth operations.
252 
253  Many of these are used as base classes for extended objects.
254 
255  These are NOT interfaces, which are defined in a separate section of this file.
256  */
257  //
258  // ------------------------------------------------------------------------------------------------------- //
259 
281  {
282  public:
283  AudioBuffer() {}
284  AudioBuffer(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
285  ~AudioBuffer();
286 
288  void init(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
289  void flushBuffers();
290 
292  float* getInputBuffer(uint32_t channel);
293  float* getOutputBuffer(uint32_t channel);
294 
296  float** getInputBuffers() { return inputBuffer; }
297  float** getOutputBuffers() { return outputBuffer; }
298 
300  uint32_t getInputChannelCount() { return numInputChannels; }
301  uint32_t getOutputChannelCount() { return numOutputChannels; }
302 
304  uint32_t getBlockSize() { return blockSize; }
305  uint32_t getSamplesInBlock() { return samplesInBlock; }
306  void setSamplesInBlock(uint32_t _samplesInBlock);
307 
308  protected:
309  float** inputBuffer = nullptr;
310  float** outputBuffer = nullptr;
311  uint32_t numInputChannels = 1;
312  uint32_t numOutputChannels = 1;
313  uint32_t blockSize = 64;
314  uint32_t samplesInBlock = 64;
315  };
316 
317 
336  {
337  public:
338  SynthClock() {}
339  ~SynthClock() {}
340  SynthClock& operator=(const SynthClock& params);
341 
343  void reset(double startValue = 0.0);
344  void initWithClock(SynthClock& clock);
345 
347  void advanceClock(uint32_t renderInterval = 1);
348  bool advanceWrapClock(uint32_t renderInterval = 1);
349  bool wrapClock();
350 
352  void setFrequency(double _frequency_Hz, double _sampleRate);
353  double getFrequency() { return frequency_Hz; }
354 
356  void addPhaseOffset(double _phaseOffset, bool wrap = true);
357  void removePhaseOffset();
358 
360  void addFrequencyOffset(double _freqOffset);
361  void removeFrequencyOffset();
362 
364  void saveState();
365  void restoreState();
366 
367  public: // for fastest access
368  double mcounter = 0.0;
369  double phaseInc = 0.0;
370  double phaseOffset = 0.0;
371  double freqOffset = 0.0;
372  double frequency_Hz = 0.0;
373  double sampleRate = 0.0;
374  enum { MOD_COUNTER, PHASE_INC, PHASE_OFFSET, FREQUENCY_HZ, NUM_VARS };
375  double state[NUM_VARS] = { 0.0, 0.0, 0.0, 0.0 };
376  };
377 
393  class Timer
394  {
395  public:
396  Timer() {}
397  ~Timer() {}
398 
400  void resetTimer() { counter = 0; }
401 
403  void setExpireSamples(uint32_t _targetValueInSamples) { targetValueInSamples = _targetValueInSamples; }
404  void setExpireMilliSec(double timeMSec, double sampleRate) { setExpireSamples(sampleRate*(timeMSec / 1000.0)); }
405 
407  uint32_t getExpireSamples() { return targetValueInSamples; }
408 
410  bool timerExpired() { return (counter >= targetValueInSamples); }
411 
413  void advanceTimer(uint32_t ticks = 1) { counter += ticks; }
414  uint32_t getTick() { return counter; }
415 
416  protected:
417  uint32_t counter = 0;
418  uint32_t targetValueInSamples = 0;
419  };
420 
437  class XFader
438  {
439  public:
440  XFader() {}
441  XFader(uint32_t _xfadeTime_Samples);
442 
444  void reset();
445 
447  void setXFadeTime(uint32_t _xfadeTime_Samples);
448  void startCrossfade() { running = true; }
449  void stopCrossfade() { running = false; }
450  bool isCrossfading() { return running; }
451 
452  // --- crossfade FROM A to B
453  // returns TRUE if the crossfade is still going (needs more samples)
454  // FALSE if the crossfade is finished (done)
455  bool crossfade(XFadeType xfadeType, double inputA, double inputB, double& output);
456 
457  protected:
458  uint32_t xfadeTime_Samples = 4410;
459  uint32_t xfadeTime_Counter = 0;
460  bool running = false;
461  };
462 
463 
482  {
483  public:
484  XHoldFader() {}
485  ~XHoldFader() {}
486 
487  // --- fader functions
488  void reset();
489 
491  inline void setXFadeTimeSamples(double _xfadeTimeSamples){ xfadeTime_Samples = _xfadeTimeSamples; }
492  inline uint32_t getXFadeTimeSamples(){ return xfadeTime_Samples; }
493 
495  void setHoldTimeSamples(double _holdTimeSamples);
496  inline double getHoldTimeSamples() { return holdTime_Samples; }
497 
499  XFadeData getCrossfadeData();
500 
501  protected:
502  uint32_t xfadeTime_Samples = 4410;
503  uint32_t xfadeTime_Counter = 0;
504  uint32_t holdTime_Samples = 4410;
505  uint32_t holdTime_Counter = 0;
506  bool holding = false;
507  };
508 
509 
524  {
525  public:
526  SlewLimiter() {}
527  ~SlewLimiter() {}
528 
529  // --- slewing functions
530  void reset() { z1 = 0; }
531 
532  // --- slew value is: 0 <= slewvalue <= 0.9999
533  void setSlewValue(double _g) { g = _g; }
534  inline double doSlewLimiter(double input)
535  {
536  double output = input*(1.0 - g) + g*z1;
537  z1 = output;
538  return output;
539  }
540 
541  protected:
542  double g = 0;
543  double z1 = 0.0;
544  };
545 
546 
564  {
565  public:
566  Synchronizer() {}
567  ~Synchronizer() {}
568 
570  bool reset(double _sampleRate, double startPhase, int32_t xfadeSamples = 16);
571 
574  SynthClock& getHardSyncClock() { return hardSyncClock; }
575  SynthClock& getCrossFadeClock() { return crossFadeClock; }
576  void startHardSync(SynthClock oscClock);
577  double doHardSyncXFade(double inA, double inB);
578  bool isProcessing() { return hardSyncFader.isCrossfading(); }
579 
581  void addPhaseOffset(double offset);
582  void removePhaseOffset();
583 
584  protected:
588  double hardSyncFrequency = 440.0;
589  double sampleRate = 44100.0;
590  };
591 
592 
611  {
612  public:
613  RampModulator() {}
614  ~RampModulator() {}
615 
617  bool startModulator(double startValue, double endValue, double modTime_mSec, double sampleRate);
618 
620  bool setModTime(double modTime_mSec, double sampleRate);
621 
623  double getNextModulationValue(uint32_t advanceClock = 1);
624 
626  void advanceClock(uint32_t ticks = 1);
627  inline bool isActive() { return timerActive; }
628 
629  protected:
630  bool timerActive = false;
631  double timerInc = 0.0;
632  double countUpTimer = 0.0;
633  double modRange = 1.0;
634  double modStart = 0.0;
635  double modEnd = 1.0;
636  };
637 
656  {
657  public:
658  GlideModulator() {}
659  ~GlideModulator() {}
660 
662  bool startModulator(double startNote, double endNote, double glideTime_mSec, double sampleRate);
663 
665  bool setGlideTime(double glideTime_mSec, double sampleRate);
666 
668  double getNextModulationValue(uint32_t advanceClock = 1);
669 
671  void advanceClock(uint32_t ticks = 1);
672  inline bool isActive() { return timerActive; }
673 
674  protected:
675  bool timerActive = false;
676  double timerInc = 0.0;
677  double countDownTimer = 1.0;
678  double glideRange = 1.0;
679  };
680 
694  {
695  public:
696  NoiseGenerator() {}
697  ~NoiseGenerator() {}
698 
700  std::default_random_engine defaultGeneratorEngine;
701 
703  double doGaussianWhiteNoise(double mean = 0.0, double variance = 1.0);
704  double doWhiteNoise();
705  double doPinkNoise();
706  double doPinkingFilter(double white);
707 
709  double bN[3] = { 0.0, 0.0, 0.0 };
710  };
711 
712  // ---------------------- SYNTH INTERFACE OBJECTS-------------------------------------------------------- //
713  //
714  /*
715  These are pure abstrace interfaces to be used as base classes for the synth objects. These allow
716  container objects to hold (shared) simple interface pointers, or the actual object pointers; all
717  object interfacing is done through the common objec model interfaces here.
718  */
719  //
720  // ------------------------------------------------------------------------------------------------------- //
721 
744  {
745  public:
754  virtual double* getModArrayPtr(uint32_t index) = 0;
755 
764  virtual double getModValue(uint32_t index) = 0;
765 
775  virtual void setModValue(uint32_t index, double value) = 0;
776  };
777 
778  // ---------------------- WAVETABLES --------------------------------------------------------- //
802  {
803  public:
812  virtual void selectTable(uint32_t midiNoteNumber) = 0;
813 
823  virtual double readWaveTable(double normalizedPhaseInc) = 0;
824 
828  virtual uint32_t getWaveTableLength() = 0;
829 
830 
834  virtual const char* getWaveformName() = 0;
835  };
836 
857  {
858  public:
867  virtual IWavetableSource* getTableSource(const char* uniqueTableName) = 0;
868 
878  virtual bool addTableSource(const char* uniqueTableName, IWavetableSource* tableSource) = 0;
879 
887  virtual bool removeTableSource(const char* uniqueTableName) = 0;
888 
896  virtual bool clearTableSources() = 0;
897  };
898 
899 
900  // ---------------------- PCM SAMPLES --------------------------------------------------------- //
916  {
917  double audioOutput[STEREO_CHANNELS] = { 0.0, 0.0 };
918  uint32_t numActiveChannels = 0;
919  };
920 
923  enum class SampleLoopMode { loop, sustain, oneShot };
924 
949  {
950  public:
957  virtual double selectSample(double oscFrequency) = 0;
958 
969  virtual PCMSampleOutput readSample(double& readIndex, double inc) = 0;
970 
980  virtual void setSampleLoopMode(SampleLoopMode _loopMode) = 0;
981 
986  virtual void deleteSamples() = 0;
987 
992  virtual uint32_t getValidSampleCount() = 0;
993 
998  virtual bool haveValidSamples() = 0;
999  };
1000 
1021  {
1022  public:
1032  virtual IPCMSampleSource* getSampleSource(const char* uniqueSampleSetName) = 0;
1033 
1043  virtual bool addSampleSource(const char* uniqueSampleSetName, IPCMSampleSource* sampleSource) = 0;
1044 
1045 
1054  virtual bool removeSampleSource(const char* uniqueSampleSetName) = 0;
1055 
1062  virtual bool clearSampleSources() = 0;
1063  };
1064 
1087  {
1088  public:
1100  virtual uint32_t getGlobalMIDIData(uint32_t index) = 0;
1101 
1113  virtual uint32_t getCCMIDIData(uint32_t index) = 0;
1114 
1123  virtual uint32_t getAuxDAWDataUINT(uint32_t index) = 0;
1124 
1133  virtual float getAuxDAWDataFloat(uint32_t index) = 0;
1134  };
1135 
1139  enum { LPF1, LPF2, LPF3, LPF4, HPF1, HPF2, HPF3, HPF4, BPF2, BPF4, BSF2, BSF4,
1140  APF1, APF2, ANM_LPF1, ANM_LPF2, ANM_LPF3, ANM_LPF4, NUM_FILTER_OUTPUTS };
1141 
1156  {
1157  double filter[NUM_FILTER_OUTPUTS];
1158  };
1159 
1160 
1180  {
1188  virtual bool reset(double _sampleRate) = 0;
1189 
1196  virtual bool update() = 0;
1197 
1205  virtual FilterOutput process(double xn) = 0;
1206 
1214  virtual void setFilterParams(double _fc, double _Q) = 0;
1215  };
1216 
1217 
1234  {
1238 
1240  float** inputBuffers = nullptr;
1241  float** outputBuffers = nullptr;
1242  float** fmBuffers = nullptr;
1243 
1248  void* moduleParameters = nullptr;
1249  const char* dllPath = nullptr;
1250 
1251  double sampleRate = 0.0;
1252  uint32_t samplesToProcess = 64;
1253  double unisonDetuneCents = 0.0;
1254  double unisonStartPhase = 0.0;
1255 
1256  double BPM = 120.0;
1258  };
1259 
1260  // ----------------------------------- SYNTH OBJECTS ----------------------------------------------------- //
1261  //
1262  /*
1263  Fundamental objects that are used throughout SynthLab
1264  */
1265  //
1266  // ------------------------------------------------------------------------------------------------------- //
1267 
1289  {
1290  // --- multi initializer construction
1291  SynthLabTableSet(const char* _waveformName, double _tableFs,
1292  uint32_t* _tableLengths, uint64_t** _ppHexTableSet, double _outputComp)
1293  : waveformName(_waveformName)
1294  , tableFs(_tableFs)
1295  , tableLengths(_tableLengths)
1296  , ppHexTableSet(_ppHexTableSet)
1297  , outputComp(_outputComp)
1298  { }
1299 
1300  // --- ptr to array of table lengths
1301  uint32_t* tableLengths = nullptr;
1302  uint64_t** ppHexTableSet = nullptr;
1303 
1304  // --- fs for this table set
1305  double tableFs = 44100.0;
1306 
1307  // --- output scaling factor (NOT volume or attenuation, waveform specific)
1308  double outputComp = 1.0;
1309 
1310  // --- GUI string for this waveform
1311  const char* waveformName;
1312  };
1313 
1334  {
1335  SynthLabBankSet(unsigned int _tablePtrsCount, SynthLabTableSet** _tablePtrs, std::string* _tableNames)
1336  : tablePtrsCount(_tablePtrsCount)
1337  , tablePtrs(_tablePtrs)
1338  , tableNames(_tableNames) {}
1339 
1340  unsigned int tablePtrsCount = 32;
1342  std::string* tableNames = nullptr;
1343  };
1344 
1348  const uint32_t kDefaultWaveTableLength = 256;
1349 
1367  {
1368  StaticWavetable() {}
1369 
1370  StaticWavetable(const uint64_t* _table, uint32_t _tableLength, const char* _waveformName,
1371  double _outputComp = 1.0, double _tableFs = 44100)
1372  : uTable(_table)
1373  , tableLength(_tableLength)
1374  , waveformName(_waveformName)
1375  , outputComp(_outputComp)
1376  , tableFs(_tableFs)
1377  {
1378  wrapMask = tableLength - 1;
1379  dTable = nullptr;
1380  }
1381 
1382  StaticWavetable(const double* _table, uint32_t _tableLength, const char* _waveformName,
1383  double _outputComp = 1.0, double _tableFs = 44100)
1384  : dTable(_table)
1385  , tableLength(_tableLength)
1386  , waveformName(_waveformName)
1387  , outputComp(_outputComp)
1388  , tableFs(_tableFs)
1389  {
1390  wrapMask = tableLength - 1;
1391  uTable = nullptr;
1392  }
1393 
1394  // --- either/or static tables
1395  const uint64_t* uTable;
1396  const double* dTable;
1399  double outputComp = 1.0;
1400  double tableFs = 44100.0;
1401  const char* waveformName;
1402  };
1403 
1423  {
1424  DynamicWavetable() {}
1425 
1426  DynamicWavetable(std::shared_ptr<double> _table, uint32_t _tableLength, const char* _waveformName,
1427  double _outputComp = 1.0, double _tableFs = 44100)
1428  : table(_table)
1429  , tableLength(_tableLength)
1430  , waveformName(_waveformName)
1431  , outputComp(_outputComp)
1432  , tableFs(_tableFs)
1433  {
1434  wrapMask = tableLength - 1;
1435  }
1436 
1437  std::shared_ptr<double> table = nullptr;
1440  double outputComp = 1.0;
1441  double tableFs = 44100.0;
1442  const char* waveformName;
1443  };
1444 
1445 
1464  {
1465  public:
1466  WavetableDatabase() {}
1468 
1470  virtual IWavetableSource* getTableSource(const char* uniqueTableName) override;
1471  virtual bool addTableSource(const char* uniqueTableName, IWavetableSource* tableSource) override;
1472  virtual bool removeTableSource(const char* uniqueTableName) override;
1473  virtual bool clearTableSources() override;
1474 
1477 
1478  protected:
1479  typedef std::map < std::string, IWavetableSource* > wavetableSourceMap;
1480  wavetableSourceMap wavetableDatabase;
1481  };
1482 
1483 
1502  {
1503  public:
1504  PCMSampleDatabase() {}
1506 
1508  virtual IPCMSampleSource* getSampleSource(const char* uniqueSampleSetName) override;
1509  virtual bool addSampleSource(const char* uniqueSampleSetName, IPCMSampleSource* sampleSource) override;
1510  virtual bool removeSampleSource(const char* uniqueSampleSetName) override;
1511  virtual bool clearSampleSources() override;
1512 
1515 
1516  protected:
1517  typedef std::map < std::string, IPCMSampleSource* >sampleSourceMap;
1518  sampleSourceMap sampleDatabase;
1519  std::vector<IPCMSampleSource*> sources;
1520  };
1521 
1540  {
1541  public:
1542  SynthProcessInfo(){}
1543  SynthProcessInfo(uint32_t _numInputChannels, uint32_t _numOutputChannels, uint32_t _blockSize);
1544  ~SynthProcessInfo() {}
1545 
1547  void pushMidiEvent(midiEvent event);
1548  void clearMidiEvents();
1549  uint32_t getMidiEventCount();
1550  midiEvent* getMidiEvent(uint32_t index);
1551 
1553  double absoluteBufferTime_Sec = 0.0;
1554  double BPM = 0.0;
1555  double timeSigNumerator = 0.0;
1556  uint32_t timeSigDenomintor = 0;
1557 
1558  protected:
1560  std::vector<midiEvent> midiEventQueue;
1561  };
1562 
1579  {
1580  public:
1581  MidiInputData();
1582  ~MidiInputData() {}
1583 
1585  virtual uint32_t getGlobalMIDIData(uint32_t index);
1586  virtual uint32_t getCCMIDIData(uint32_t index);
1587  virtual uint32_t getAuxDAWDataUINT(uint32_t index);
1588  virtual float getAuxDAWDataFloat(uint32_t index);
1589 
1591  void setGlobalMIDIData(uint32_t index, uint32_t value);
1592  void setCCMIDIData(uint32_t index, uint32_t value);
1593  void setAuxDAWDataUINT(uint32_t index, uint32_t value);
1594  void setAuxDAWDataFloat(uint32_t index, float value);
1595 
1597  IMidiInputData* getIMIDIInputData() { return this; }
1598 
1599  protected:
1600  // --- shared MIDI tables, via IMIDIData
1601  uint32_t globalMIDIData[kNumMIDIGlobals];
1603  double auxData[kNumMIDIAuxes];
1604  };
1605 
1622  class Modulators : public IModulator
1623  {
1624  public:
1625  Modulators();
1626 
1628  virtual double* getModArrayPtr(uint32_t index);
1629  virtual double getModValue(uint32_t index);
1630  virtual void setModValue(uint32_t index, double value);
1631 
1632  // --- fast clearing of array
1633  void clear();
1634 
1636  void initInputValues();
1637 
1639  IModulator* getModulatorPtr() { return this; }
1640 
1641  protected:
1642  // --- array of modulation inputs or outputs
1643  double modArray[MAX_MODULATION_CHANNELS];
1644  };
1645 
1672  {
1673  public:
1680  virtual ~ModuleCore() { }
1681 
1683  virtual bool reset(CoreProcData& processInfo) = 0;
1684  virtual bool update(CoreProcData& processInfo) = 0;
1685  virtual bool render(CoreProcData& processInfo) = 0;
1686  virtual bool doNoteOn(CoreProcData& processInfo) = 0;
1687  virtual bool doNoteOff(CoreProcData& processInfo) = 0;
1688 
1690  virtual int32_t getState() { return -1; }
1691  virtual bool shutdown() { return false; }
1692  virtual void setSustainOverride(bool sustain) { return; }
1693  virtual void setStandAloneMode(bool b) { standAloneMode = b; }
1694 
1696  bool startGlideModulation(GlideInfo& glideInfo) {
1697  return glideModulator->startModulator(glideInfo.startMIDINote, glideInfo.endMIDINote, glideInfo.glideTime_mSec, glideInfo.sampleRate);
1698  }
1699 
1701  uint32_t getModuleType() { return moduleType; }
1702  const char* getModuleName() { return moduleName; }
1703  void* getModuleHandle() { return moduleHandle; }
1704  void setModuleHandle(void* handle) { moduleHandle = handle; }
1705  uint32_t getModuleIndex() { return moduleIndex; }
1706  void setModuleIndex(uint32_t index) { moduleIndex = index; }
1707 
1718 
1719  protected:
1720  // --- module
1722  const char* moduleName = nullptr;
1723  void* moduleHandle = nullptr;
1724  uint32_t moduleIndex = 0;
1726  bool standAloneMode = false;
1727  std::unique_ptr<GlideModulator> glideModulator;
1728  };
1729 
1753  {
1754  public:
1755  SynthModule(std::shared_ptr<MidiInputData> _midiInputData);
1756  virtual ~SynthModule();
1757 
1759  virtual bool reset(double _sampleRate) = 0;
1760  virtual bool update() = 0;
1761  virtual bool render(uint32_t samplesToProcess = 1) = 0;
1762  virtual bool doNoteOn(MIDINoteEvent& noteEvent) = 0;
1763  virtual bool doNoteOff(MIDINoteEvent& noteEvent) = 0;
1764 
1766  virtual bool initialize(const char* _dllDirectory) { dllDirectory = _dllDirectory; return true; }
1767 
1769  virtual int32_t getState() { return -1; }
1770  virtual bool shutdown() { return false; }
1771 
1773  virtual bool startGlideModulation(GlideInfo& glideInfo);
1774 
1776  std::shared_ptr<Modulators> getModulationInput() { return modulationInput; }
1777  std::shared_ptr<Modulators> getModulationOutput() { return modulationOutput; }
1778 
1780  std::shared_ptr<AudioBuffer> getAudioBuffers() { return audioBuffers; }
1781 
1783  void setUnisonMode(double _unisonDetuneCents, double _unisonStarPhase) {
1784  unisonDetuneCents = _unisonDetuneCents; unisonStartPhase = _unisonStarPhase;
1785  }
1786 
1788  void setFMBuffer(std::shared_ptr<AudioBuffer> pmBuffer) { fmBuffer = pmBuffer; }
1789  void clearFMBuffer() { fmBuffer = nullptr; }
1790 
1793  virtual bool getModuleStrings(std::vector<std::string>& moduleStrings, std::string ignoreStr = "");
1794  virtual bool getModuleStrings(uint32_t coreIndex, std::vector<std::string>& moduleStrings, std::string ignoreStr);
1795  virtual bool getAllModuleStrings(std::vector<std::string>& moduleStrings, std::string ignoreStr);
1796  virtual bool getModKnobStrings(std::vector<std::string>& modKnobStrings);
1797  virtual bool getModuleCoreStrings(std::vector<std::string>& moduleCoreStrings);
1798  virtual bool addModuleCore(std::shared_ptr<ModuleCore> core);
1799  virtual uint32_t getSelectedCoreIndex();
1800  virtual bool selectModuleCore(uint32_t index);
1801  virtual bool selectDefaultModuleCore();
1802  virtual bool clearModuleCores();
1803  virtual void setStandAloneMode(bool b);
1804 
1805  protected:
1807  std::shared_ptr<Modulators> modulationInput = std::make_shared<Modulators>();
1808 
1810  std::shared_ptr<Modulators> modulationOutput = std::make_shared<Modulators>();
1811 
1813  std::shared_ptr<MidiInputData> midiInputData = nullptr;
1814 
1816  std::shared_ptr<AudioBuffer> audioBuffers = nullptr;
1817 
1819  std::unique_ptr<GlideModulator> glideModulator;
1820 
1822  std::shared_ptr<AudioBuffer> fmBuffer = nullptr;
1823 
1825  std::shared_ptr<ModuleCore> moduleCores[NUM_MODULE_CORES];
1826  std::shared_ptr<ModuleCore> selectedCore = nullptr;
1827  double unisonDetuneCents = 0.0;
1828  double unisonStartPhase = 0.0;
1829  bool standAloneMode = false;
1830 
1833  std::string dllDirectory;
1834  };
1835 
1836 
1837  // ----------------------------------- FX-FILTERING OBJECTS ---------------------------------------------- //
1838  //
1839  /*
1840  Objects taken primarily from Will Pirkle's FX book (2nd edition)
1841  Most objects are heavily detailed in the book Designing Audio Effects Plugins in C++ 2nd Ed and
1842  at http://aspikplugins.com/sdkdocs/html/index.html
1843  */
1844  //
1845  // ------------------------------------------------------------------------------------------------------- //
1846 
1859  inline double doLinearInterp(double y1, double y2, double fractional_X)
1860  {
1861  // --- check invalid condition
1862  if (fractional_X >= 1.0) return y2;
1863 
1864  // --- use weighted sum method of interpolating
1865  return fractional_X*y2 + (1.0 - fractional_X)*y1;
1866  }
1867 
1882  template <typename T>
1884  {
1885  public:
1886  CircularBuffer() {} /* C-TOR */
1887  ~CircularBuffer() {} /* D-TOR */
1888 
1890  void flushBuffer() { memset(&buffer[0], 0, bufferLength * sizeof(T)); }
1891 
1894  void createCircularBuffer(uint32_t _bufferLength)
1895  {
1896  // --- find nearest power of 2 for buffer, and create
1897  createCircularBufferPowerOfTwo((uint32_t)(pow(2, ceil(log(_bufferLength) / log(2)))));
1898  }
1899 
1902  void createCircularBufferPowerOfTwo(uint32_t _bufferLengthPowerOfTwo)
1903  {
1904  // --- reset to top
1905  writeIndex = 0;
1906 
1907  // --- find nearest power of 2 for buffer, save it as bufferLength
1908  bufferLength = _bufferLengthPowerOfTwo;
1909 
1910  // --- save (bufferLength - 1) for use as wrapping mask
1911  wrapMask = bufferLength - 1;
1912 
1913  // --- create new buffer
1914  buffer.reset(new T[bufferLength]);
1915 
1916  // --- flush buffer
1917  flushBuffer();
1918  }
1919 
1921  void writeBuffer(T input)
1922  {
1923  // --- write and increment index counter
1924  buffer[writeIndex++] = input;
1925 
1926  // --- wrap if index > bufferlength - 1
1927  writeIndex &= wrapMask;
1928  }
1929 
1931  T readBuffer(int delayInSamples)//, bool readBeforeWrite = true)
1932  {
1933  // --- subtract to make read index
1934  // note: -1 here is because we read-before-write,
1935  // so the *last* write location is what we use for the calculation
1936  int readIndex = (writeIndex - 1) - delayInSamples;
1937 
1938  // --- autowrap index
1939  readIndex &= wrapMask;
1940 
1941  // --- read it
1942  return buffer[readIndex];
1943  }
1944 
1946  T readBuffer(double delayInFractionalSamples)
1947  {
1948  // --- truncate delayInFractionalSamples and read the int part
1949  T y1 = readBuffer((int)delayInFractionalSamples);
1950 
1951  // --- if no interpolation, just return value
1952  if (!interpolate) return y1;
1953 
1954  // --- else do interpolation
1955  //
1956  int readIndexNext = (int)delayInFractionalSamples + 1;
1957 
1958  // --- autowrap index
1959  readIndexNext &= wrapMask;
1960 
1961  // --- read the sample at n+1 (one sample OLDER)
1962  T y2 = readBuffer(readIndexNext);
1963 
1964  // --- get fractional part
1965  double fraction = delayInFractionalSamples - (uint32_t)delayInFractionalSamples;
1966 
1967  // --- do the interpolation (you could try different types here)
1968  return doLinearInterp(y1, y2, fraction);
1969  }
1970 
1972  void setInterpolate(bool b) { interpolate = b; }
1973 
1974  private:
1975  std::unique_ptr<T[]> buffer = nullptr;
1976  uint32_t writeIndex = 0;
1977  uint32_t bufferLength = 1024;
1978  uint32_t wrapMask = 1023;
1979  bool interpolate = true;
1980  };
1981 
2000  {
2001  public:
2002  DelayLine(void) {} /* C-TOR */
2003  ~DelayLine(void) {} /* D-TOR */
2004 
2005  public:
2007  void clear(){ delayBuffer.flushBuffer();}
2008 
2016  void reset(double _sampleRate, double minimumPitch = MIDI_NOTE_0_FREQ) // 8.176 = MIDI note 0
2017  {
2018  // ---
2019  delayBuffer.createCircularBuffer(_sampleRate / minimumPitch);
2020  clear();
2021  }
2022 
2029  void setDelayInSamples(double _delaySamples)
2030  {
2031  delaySamples = _delaySamples;
2032  }
2033 
2040  void writeDelay(double xn)
2041  {
2042  // --- write to delay buffer
2043  delayBuffer.writeBuffer(xn);
2044  }
2045 
2052  double readDelay()
2053  {
2054  double yn = delayBuffer.readBuffer(delaySamples);
2055  return yn;
2056  }
2057 
2058  private:
2059  // --- our only variable
2060  double delaySamples = 0;
2061 
2062  // --- delay buffer of doubles
2063  CircularBuffer<double> delayBuffer;
2064  };
2065 
2066 
2079  struct BQCoeffs
2080  {
2081  // --- filter coefficients
2082  double coeff[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2083  };
2084 
2099  {
2100  public:
2101  BQAudioFilter(void) {} /* C-TOR */
2102  ~BQAudioFilter(void) {} /* D-TOR */
2103 
2104  public:
2106  void reset(){ flushDelays(); }
2107 
2110  {
2111  for (uint32_t i = 0; i<numStates; i++)
2112  state[i] = 0.0;
2113  }
2114 
2116  void setCoeffs(BQCoeffs& _coeffs) {
2117  bq = _coeffs;
2118  }
2119 
2121  void copyCoeffs(BQAudioFilter& destination) {
2122  destination.setCoeffs(bq);
2123  }
2124 
2131  double processAudioSample(double xn)
2132  {
2133  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];
2134  state[xz2] = state[xz1];
2135  state[xz1] = xn;
2136  state[yz2] = state[yz1];
2137  state[yz1] = yn;
2138 
2139  return xn*bq.coeff[d0] + yn*bq.coeff[c0];
2140  }
2141 
2142  protected:
2143  enum { a0, a1, a2, b1, b2, c0, d0 };
2144  enum { xz1, xz2, yz1, yz2, numStates };
2145  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2147  };
2148 
2149 
2164  {
2165  public:
2166  FracDelayAPF(void) {} /* C-TOR */
2167  ~FracDelayAPF(void) {} /* D-TOR */
2168 
2169  public:
2171  void reset()
2172  {
2173  state[0] = 0.0;
2174  state[1] = 0.0;
2175  }
2176 
2178  void setAlpha(double _alpha)
2179  {
2180  alpha = _alpha;
2181  }
2182 
2189  double processAudioSample(double xn)
2190  {
2191  double yn = xn*alpha + state[0] - alpha*state[1];
2192  state[0] = xn;
2193  state[1] = yn;
2194  return yn;
2195  }
2196 
2197  private:
2198  // --- our only coefficient
2199  double alpha = 0.0;
2200  double state[2] = { 0.0, 0.0 };
2201  };
2202 
2203 
2219  {
2220  public:
2221  ResLoopFilter(void) {} /* C-TOR */
2222  ~ResLoopFilter(void) {} /* D-TOR */
2223 
2224  public:
2226  void reset()
2227  {
2228  state[0] = 0.0;
2229  state[1] = 0.0;
2230  }
2231 
2238  double processAudioSample(double xn)
2239  {
2240  double yn = 0.5*xn + 0.5*state[0];
2241  state[0] = xn;
2242  return yn;
2243  }
2244 
2245  private:
2246  double state[2] = { 0.0, 0.0 };
2247  };
2248 
2249 
2265  {
2266  public:
2267  DCRemovalFilter(void) {} /* C-TOR */
2268  ~DCRemovalFilter(void) {} /* D-TOR */
2269 
2270  public:
2272  void reset(double _sampleRate)
2273  {
2274  for (uint32_t i = 0; i<numStates; i++)
2275  state[i] = 0.0;
2276 
2277  sampleRate = _sampleRate;
2278 
2279  // --- see book for formulae
2280  double theta_c = kTwoPi*fc / sampleRate;
2281  double gamma = cos(theta_c) / (1.0 + sin(theta_c));
2282 
2283  // --- update coeffs
2284  coeffs[a0] = (1.0 + gamma) / 2.0;
2285  coeffs[a1] = -(1.0 + gamma) / 2.0;
2286  coeffs[a2] = 0.0;
2287  coeffs[b1] = -gamma;
2288  coeffs[b2] = 0.0;
2289  }
2290 
2297  double processAudioSample(double xn)
2298  {
2299  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2300  state[xz2] = state[xz1];
2301  state[xz1] = xn;
2302  state[yz2] = state[yz1];
2303  state[yz1] = yn;
2304  return yn;
2305  }
2306 
2307  protected:
2308  enum { xz1, xz2, yz1, yz2, numStates };
2309  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2310  enum { a0, a1, a2, b1, b2 };
2311  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2312  double fc = 2.0;
2313  double sampleRate = 1.0;
2314  };
2315 
2316 
2331  class TinyBPF
2332  {
2333  public:
2334  TinyBPF(void) {} /* C-TOR */
2335  ~TinyBPF(void) {} /* D-TOR */
2336 
2337  public:
2339  void reset(double _sampleRate)
2340  {
2341  for (uint32_t i = 0; i<numStates; i++)
2342  state[i] = 0.0;
2343 
2344  sampleRate = _sampleRate;
2345  }
2346 
2348  void setParameters(double _fc, double _Q)
2349  {
2350  if (fc == _fc && Q == _Q)
2351  return;
2352 
2353  fc = _fc;
2354  Q = _Q;
2355 
2356  // --- see book for formulae
2357  double K = tan(kPi*fc / sampleRate);
2358  double delta = K*K*Q + K + Q;
2359 
2360  // --- update coeffs
2361  coeffs[a0] = K / delta;;
2362  coeffs[a1] = 0.0;
2363  coeffs[a2] = -K / delta;
2364  coeffs[b1] = 2.0*Q*(K*K - 1) / delta;
2365  coeffs[b2] = (K*K*Q - K + Q) / delta;
2366  }
2367 
2374  double processAudioSample(double xn)
2375  {
2376  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2377  state[xz2] = state[xz1];
2378  state[xz1] = xn;
2379  state[yz2] = state[yz1];
2380  state[yz1] = yn;
2381  return yn;
2382  }
2383 
2384  protected:
2385  enum { xz1, xz2, yz1, yz2, numStates };
2386  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2387  enum { a0, a1, a2, b1, b2 };
2388  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2389  double fc = 5.0;
2390  double Q = 0.5;
2391  double sampleRate = 1.0;
2392  };
2393 
2409  {
2410  public:
2411  LP2Filter(void) {} /* C-TOR */
2412  ~LP2Filter(void) {} /* D-TOR */
2413 
2414  public:
2416  void reset(double _sampleRate)
2417  {
2418  sampleRate = _sampleRate;
2419  clear();
2420  }
2421 
2423  void clear()
2424  {
2425  for (uint32_t i = 0; i<numStates; i++)
2426  state[i] = 0.0;
2427  }
2428 
2430  void setParameters(double _fc, double _Q)
2431  {
2432  if (fc == _fc && Q == _Q)
2433  return;
2434 
2435  fc = _fc;
2436  Q = _Q;
2437 
2438  // --- see book for formulae
2439  double theta_c = 2.0*kPi*fc / sampleRate;
2440  double d = 1.0 / Q;
2441  double betaNumerator = 1.0 - ((d / 2.0)*(sin(theta_c)));
2442  double betaDenominator = 1.0 + ((d / 2.0)*(sin(theta_c)));
2443 
2444  double beta = 0.5*(betaNumerator / betaDenominator);
2445  double gamma = (0.5 + beta)*(cos(theta_c));
2446  double alpha = (0.5 + beta - gamma) / 2.0;
2447 
2448  // --- update coeffs
2449  coeffs[a0] = alpha;
2450  coeffs[a1] = 2.0*alpha;
2451  coeffs[a2] = alpha;
2452  coeffs[b1] = -2.0*gamma;
2453  coeffs[b2] = 2.0*beta;
2454  }
2455 
2462  double processAudioSample(double xn)
2463  {
2464  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2465  state[xz2] = state[xz1];
2466  state[xz1] = xn;
2467  state[yz2] = state[yz1];
2468  state[yz1] = yn;
2469  return yn;
2470  }
2471 
2472  protected:
2473  enum { xz1, xz2, yz1, yz2, numStates };
2474  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2475  enum { a0, a1, a2, b1, b2 };
2476  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2477  double fc = 5.0;
2478  double Q = 0.5;
2479  double sampleRate = 1.0;
2480  };
2481 
2482 
2498  {
2499  public:
2500  HP2Filter(void) {} /* C-TOR */
2501  ~HP2Filter(void) {} /* D-TOR */
2502 
2503  public:
2505  void reset(double _sampleRate)
2506  {
2507  for (uint32_t i = 0; i<numStates; i++)
2508  state[i] = 0.0;
2509 
2510  sampleRate = _sampleRate;
2511  }
2512 
2514  void setParameters(double _fc, double _Q)
2515  {
2516  if (fc == _fc && Q == _Q)
2517  return;
2518 
2519  fc = _fc;
2520  Q = _Q;
2521 
2522  double theta_c = kTwoPi*fc / sampleRate;
2523  double d = 1.0 / Q;
2524 
2525  // --- see book for formulae
2526  double betaNumerator = 1.0 - ((d / 2.0)*(sin(theta_c)));
2527  double betaDenominator = 1.0 + ((d / 2.0)*(sin(theta_c)));
2528 
2529  double beta = 0.5*(betaNumerator / betaDenominator);
2530  double gamma = (0.5 + beta)*(cos(theta_c));
2531  double alpha = (0.5 + beta + gamma) / 2.0;
2532 
2533  // --- update coeffs
2534  coeffs[a0] = alpha;
2535  coeffs[a1] = -2.0*alpha;
2536  coeffs[a2] = alpha;
2537  coeffs[b1] = -2.0*gamma;
2538  coeffs[b2] = 2.0*beta;
2539  }
2540 
2547  double processAudioSample(double xn)
2548  {
2549  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2550  state[xz2] = state[xz1];
2551  state[xz1] = xn;
2552  state[yz2] = state[yz1];
2553  state[yz1] = yn;
2554  return yn;
2555  }
2556 
2557  protected:
2558  enum { xz1, xz2, yz1, yz2, numStates };
2559  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2560  enum { a0, a1, a2, b1, b2 };
2561  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2562  double fc = 5.0;
2563  double Q = 0.5;
2564  double sampleRate = 1.0;
2565  };
2566 
2582  {
2583  public:
2584  TinyReson(void) {} /* C-TOR */
2585  ~TinyReson(void) {} /* D-TOR */
2586 
2587  public:
2589  void reset(double _sampleRate)
2590  {
2591  for(uint32_t i=0; i<numStates; i++)
2592  state[i] = 0.0;
2593 
2594  sampleRate = _sampleRate;
2595  }
2596 
2598  void setParameters(double _fc, double _Q)
2599  {
2600  if (fc == _fc && Q == _Q)
2601  return;
2602 
2603  fc = _fc;
2604  Q = _Q;
2605 
2606  double theta_c = kTwoPi*fc / sampleRate;
2607  double BW = fc / Q;
2608  coeffs[b2] = exp(-2.0*kPi*(BW / sampleRate));
2609  coeffs[b1] = ((-4.0*coeffs[b2]) / (1.0 + coeffs[b2]))*cos(theta_c);
2610  coeffs[a0] = 1.0 - pow(coeffs[b2], 0.5);
2611  coeffs[a2] = -coeffs[a0];
2612  }
2613 
2620  double processAudioSample(double xn, double loss = 1.0)
2621  {
2622  double yn = coeffs[a0]*xn + coeffs[a2]*state[xz2] - coeffs[b1]*state[yz1] -coeffs[b2]*state[yz2];
2623  state[xz2] = state[xz1];
2624  state[xz1] = xn;
2625  state[yz2] = state[yz1];
2626  state[yz1] = yn * loss;
2627  return yn;
2628  }
2629 
2630  protected:
2631  enum { xz1, xz2, yz1, yz2, numStates };
2632  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2633  enum { a0, a2, b1, b2 };
2634  double coeffs[4] = { 0.0, 0.0, 0.0, 0.0 };
2635  double fc = 440.0;
2636  double Q = 0.5;
2637  double sampleRate = 1.0;
2638  };
2639 
2655  {
2656  public:
2657  LowShelfFilter(void) {} /* C-TOR */
2658  ~LowShelfFilter(void) {} /* D-TOR */
2659 
2660  public:
2662  void reset(double _sampleRate)
2663  {
2664  for (uint32_t i = 0; i<numStates; i++)
2665  state[i] = 0.0;
2666 
2667  sampleRate = _sampleRate;
2668  }
2669 
2671  void setParameters(double shelfFreq, double boostCut_dB)
2672  {
2673  double theta_c = kTwoPi*shelfFreq / sampleRate;
2674  double mu = pow(10.0, boostCut_dB / 20.0);
2675 
2676  double beta = 4.0 / (1.0 + mu);
2677  double delta = beta*tan(theta_c / 2.0);
2678  double gamma = (1.0 - delta) / (1.0 + delta);
2679 
2680  // --- update coeffs
2681  coeffs[a0] = (1.0 - gamma) / 2.0;
2682  coeffs[a1] = (1.0 - gamma) / 2.0;
2683  coeffs[a2] = 0.0;
2684  coeffs[b1] = -gamma;
2685  coeffs[b2] = 0.0;
2686 
2687  coeffs[c0] = mu - 1.0;
2688  coeffs[d0] = 1.0;
2689  }
2690 
2697  double processAudioSample(double xn)
2698  {
2699  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2700  state[xz2] = state[xz1];
2701  state[xz1] = xn;
2702  state[yz2] = state[yz1];
2703  state[yz1] = yn;
2704 
2705  return xn*coeffs[d0] + yn*coeffs[c0];
2706  }
2707 
2708  protected:
2709  enum { xz1, xz2, yz1, yz2, numStates };
2710  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2711  enum { a0, a1, a2, b1, b2, c0, d0 };
2712  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2713  double fc = 440.0;
2714  double boostCut_dB = 0.0;
2715  double sampleRate = 1.0;
2716  };
2717 
2718 
2734  {
2735  public:
2736  HighShelfFilter(void) {} /* C-TOR */
2737  ~HighShelfFilter(void) {} /* D-TOR */
2738 
2739  public:
2741  void reset(double _sampleRate)
2742  {
2743  for (uint32_t i = 0; i<numStates; i++)
2744  state[i] = 0.0;
2745 
2746  sampleRate = _sampleRate;
2747  }
2748 
2750  void setParameters(double shelfFreq, double boostCut_dB)
2751  {
2752  double theta_c = kTwoPi*shelfFreq / sampleRate;
2753  double mu = pow(10.0, boostCut_dB / 20.0);
2754 
2755  double beta = (1.0 + mu) / 4.0;
2756  double delta = beta*tan(theta_c / 2.0);
2757  double gamma = (1.0 - delta) / (1.0 + delta);
2758 
2759  coeffs[a0] = (1.0 + gamma) / 2.0;
2760  coeffs[a1] = -coeffs[a0];
2761  coeffs[a2] = 0.0;
2762  coeffs[b1] = -gamma;
2763  coeffs[b2] = 0.0;
2764 
2765  coeffs[c0] = mu - 1.0;
2766  coeffs[d0] = 1.0;
2767  }
2768 
2775  double processAudioSample(double xn)
2776  {
2777  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2778  state[xz2] = state[xz1];
2779  state[xz1] = xn;
2780  state[yz2] = state[yz1];
2781  state[yz1] = yn;
2782 
2783  return xn*coeffs[d0] + yn*coeffs[c0];
2784  }
2785 
2786  protected:
2787  enum { xz1, xz2, yz1, yz2, numStates };
2788  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2789  enum { a0, a1, a2, b1, b2, c0, d0 };
2790  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2791  double fc = 440.0;
2792  double boostCut_dB = 0.0;
2793  double sampleRate = 1.0;
2794  };
2795 
2811  {
2812  public:
2813  ParametricFilter(void) {} /* C-TOR */
2814  ~ParametricFilter(void) {} /* D-TOR */
2815 
2816  public:
2818  void reset(double _sampleRate)
2819  {
2820  for (uint32_t i = 0; i<numStates; i++)
2821  state[i] = 0.0;
2822 
2823  sampleRate = _sampleRate;
2824  }
2825 
2827  void setParameters(double _fc, double _Q, double _boostCut_dB)
2828  {
2829  if (fc == _fc && Q == _Q && boostCut_dB == _boostCut_dB)
2830  return;
2831  fc = _fc;
2832  Q = _Q;
2833  boostCut_dB = _boostCut_dB;
2834 
2835  // --- see book for formulae
2836  double theta_c = kTwoPi*fc / sampleRate;
2837  double mu = pow(10.0, boostCut_dB / 20.0);
2838 
2839  // --- clamp to 0.95 pi/2 (you can experiment with this)
2840  double tanArg = theta_c / (2.0 * Q);
2841  if (tanArg >= 0.95*kPi / 2.0) tanArg = 0.95*kPi / 2.0;
2842 
2843  // --- intermediate variables (you can condense this if you wish)
2844  double zeta = 4.0 / (1.0 + mu);
2845  double betaNumerator = 1.0 - zeta*tan(tanArg);
2846  double betaDenominator = 1.0 + zeta*tan(tanArg);
2847 
2848  double beta = 0.5*(betaNumerator / betaDenominator);
2849  double gamma = (0.5 + beta)*(cos(theta_c));
2850  double alpha = (0.5 - beta);
2851 
2852  // --- update coeffs
2853  coeffs[a0] = alpha;
2854  coeffs[a1] = 0.0;
2855  coeffs[a2] = -alpha;
2856  coeffs[b1] = -2.0*gamma;
2857  coeffs[b2] = 2.0*beta;
2858 
2859  coeffs[c0] = mu - 1.0;
2860  coeffs[d0] = 1.0;
2861  }
2862 
2869  double processAudioSample(double xn)
2870  {
2871  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2872  state[xz2] = state[xz1];
2873  state[xz1] = xn;
2874  state[yz2] = state[yz1];
2875  state[yz1] = yn;
2876 
2877  return xn*coeffs[d0] + yn*coeffs[c0];
2878  }
2879 
2880  protected:
2881  enum { xz1, xz2, yz1, yz2, numStates };
2882  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2883  enum { a0, a1, a2, b1, b2, c0, d0 };
2884  double coeffs[7] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
2885  double fc = 0.0;
2886  double Q = 0.0;
2887  double boostCut_dB = 0.0;
2888  double sampleRate = 1.0;
2889  };
2890 
2891 
2907  {
2908  public:
2909  LP1PFilter(void) {} /* C-TOR */
2910  ~LP1PFilter(void) {} /* D-TOR */
2911 
2912  public:
2914  void reset(double _sampleRate)
2915  {
2916  clear();
2917  sampleRate = _sampleRate;
2918  }
2919 
2921  void clear()
2922  {
2923  for (uint32_t i = 0; i<numStates; i++)
2924  state[i] = 0.0;
2925  }
2926 
2928  void setParameters(double _fc)
2929  {
2930  if (fc == _fc)
2931  return;
2932 
2933  fc = _fc;
2934 
2935  // --- see book for formulae
2936  double theta_c = 2.0*kPi*fc / sampleRate;
2937  double gamma = 2.0 - cos(theta_c);
2938 
2939  double filter_b1 = pow((gamma*gamma - 1.0), 0.5) - gamma;
2940  double filter_a0 = 1.0 + filter_b1;
2941 
2942  // --- update coeffs
2943  coeffs[a0] = filter_a0;
2944  coeffs[a1] = 0.0;
2945  coeffs[a2] = 0.0;
2946  coeffs[b1] = filter_b1;
2947  coeffs[b2] = 0.0;
2948  }
2949 
2957  double processAudioSample(double xn)
2958  {
2959  double yn = coeffs[a0] * xn + coeffs[a1] * state[xz1] + coeffs[a2] * state[xz2] - coeffs[b1] * state[yz1] - coeffs[b2] * state[yz2];
2960  state[xz2] = state[xz1];
2961  state[xz1] = xn;
2962  state[yz2] = state[yz1];
2963  state[yz1] = yn;
2964  return yn;
2965  }
2966 
2967  protected:
2968  enum { xz1, xz2, yz1, yz2, numStates };
2969  double state[4] = { 0.0, 0.0, 0.0, 0.0 };
2970  enum { a0, a1, a2, b1, b2 };
2971  double coeffs[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
2972  double fc = 5.0;
2973  double Q = 0.5;
2974  double sampleRate = 1.0;
2975  };
2976 
2980  enum class PluckFilterType {kPluck, kPluckAndBridge, kPickup, kPluckAndPickup, kBridge, kPluckPickupBridge};
2981 
2982 
3001  {
3002  public:
3003  PluckPosFilter(void) {} /* C-TOR */
3004  ~PluckPosFilter(void) {} /* D-TOR */
3005 
3006  public:
3008  void clear()
3009  {
3010  combDelay.clear();
3012  }
3013 
3022  void reset(double _sampleRate, double minimumPitch = MIDI_NOTE_0_FREQ) // 8.176 = MIDI note 0
3023  {
3024  // ---
3025  combDelay.reset(_sampleRate, minimumPitch);
3026  combDelay.clear();
3027 
3028  pickupFilter.reset(_sampleRate);
3029  pickupFilter.setParameters(2500.0, 1.5); // guitar pickup settings
3030 
3031  bridgeIntegrator.reset(_sampleRate);
3032  bridgeIntegrator.setParameters(20.0); // lower than the lowest note to synthesize which is note 0
3033  }
3034 
3041  void setDelayInSamples(double _delaySamples)
3042  {
3043  // --- the (-1) is needed here because of the way the circular buffer counts samples for read/write
3044  combDelay.setDelayInSamples(_delaySamples - 1);
3045  }
3046 
3056  double processAudioSample(double xn, PluckFilterType type)
3057  {
3058  if (type == PluckFilterType::kBridge)
3059  return 12.0*bridgeIntegrator.processAudioSample(xn);
3060 
3061  if (type == PluckFilterType::kPickup)
3062  return pickupFilter.processAudioSample(xn);
3063 
3064  // --- pluck position
3065  double yn = combDelay.readDelay();
3066  combDelay.writeDelay(xn);
3067 
3068  // --- output pluck
3069  double pluck = 0.5*(xn - yn);
3070  if (type == PluckFilterType::kPluck)
3071  return pluck;
3072 
3073  // --- pluck and pickup
3074  if (type == PluckFilterType::kPluckAndPickup)
3075  return pickupFilter.processAudioSample(pluck);
3076 
3077  // --- pluck and bridge
3078  if (type == PluckFilterType::kPluckAndBridge)
3079  return 12.0*bridgeIntegrator.processAudioSample(pluck);
3080 
3081  if (type == PluckFilterType::kPluckPickupBridge)
3082  {
3083  double pu = 2.0*pickupFilter.processAudioSample(pluck);
3084  return 12.0*bridgeIntegrator.processAudioSample(pu);
3085  }
3086 
3087 
3088  return xn; // should never get here
3089  }
3090 
3091  protected:
3094  LP2Filter pickupFilter;
3095  };
3096 
3097 
3098 
3099 
3100 } // namespace
3101 
3102 #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:3041
void reset(double _sampleRate)
Definition: synthbase.h:2914
std::string * tableNames
names of tables
Definition: synthbase.h:1342
void setCCMIDIData(uint32_t index, uint32_t value)
set the CC MIDI value
Definition: synthbase.cpp:1197
Object that acts as the PCM sample database, as shared synth-wide resource. You should study this esp...
Definition: synthbase.h:1501
uint32_t tableLength
length
Definition: synthbase.h:1397
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:530
const char * dllPath
path to the plugin, used for finding PCM sample WAV files
Definition: synthbase.h:1249
std::shared_ptr< Modulators > modulationInput
Definition: synthbase.h:1807
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:1433
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2297
float * getOutputBuffer(uint32_t channel)
Get a naked pointer to an audio OUTPUT buffer by channel.
Definition: synthbase.cpp:118
SynthClock hardSyncClock
clock for reset oscillator
Definition: synthbase.h:585
bool setGlideTime(double glideTime_mSec, double sampleRate)
Change the glide time; this is optional.
Definition: synthbase.cpp:720
Implements a first order APF that is used to generate a fractional delay for the physcial model of a ...
Definition: synthbase.h:2163
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2598
const uint32_t NUM_MODULE_CORES
Definition: synthconstants.h:120
~PCMSampleDatabase()
clear out the table sources
Definition: synthbase.cpp:988
double phaseInc
phase inc = fo/fs
Definition: synthbase.h:369
uint32_t numActiveChannels
number of active channels; not used in SynthLab but available
Definition: synthbase.h:918
double g
one pole filter feedback coefficient
Definition: synthbase.h:542
std::unique_ptr< GlideModulator > glideModulator
Definition: synthbase.h:1819
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:1222
void initWithClock(SynthClock &clock)
Initialize this clock with another SynthClock.
Definition: synthbase.cpp:167
The CircularBuffer object implements a simple circular buffer. It uses a wrap mask to wrap the read o...
Definition: synthbase.h:1883
double processAudioSample(double xn, PluckFilterType type)
run the string of filters
Definition: synthbase.h:3056
bool isActive()
checks to see if the modulator is running, or completed
Definition: synthbase.h:627
virtual bool addModuleCore(std::shared_ptr< ModuleCore > core)
adds a module core to the module&#39;s set of four
Definition: synthbase.cpp:1466
void writeBuffer(T input)
Definition: synthbase.h:1921
Ultra compact timer object that is used for many different functionalities.
Definition: synthbase.h:393
~WavetableDatabase()
clear out the table sources
Definition: synthbase.cpp:892
void setXFadeTimeSamples(double _xfadeTimeSamples)
Definition: synthbase.h:491
std::shared_ptr< ModuleCore > moduleCores[NUM_MODULE_CORES]
Definition: synthbase.h:1825
double outputComp
output scaling factor (NOT volume or attenuation, waveform specific)
Definition: synthbase.h:1440
void reset(double _sampleRate)
Definition: synthbase.h:2589
std::vector< midiEvent > midiEventQueue
queue A
Definition: synthbase.h:1560
double timeSigNumerator
time signature numerator
Definition: synthbase.h:1555
double sampleRate
fs
Definition: synthstructures.h:213
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:1247
Compact modulo counter with wrapping used as the timebase for all oscillators.
Definition: synthbase.h:335
uint32_t globalMIDIData[kNumMIDIGlobals]
the global MIDI INPUT table that is shared across the voices via the IMIDIData interface ...
Definition: synthbase.h:1601
sampleSourceMap sampleDatabase
map that connects PCM sample set names to source objects
Definition: synthbase.h:1518
const double kPi
pi to 80 decimal places
Definition: synthconstants.h:508
double outputComp
output scaling factor
Definition: synthbase.h:1308
void reset(double _sampleRate)
Definition: synthbase.h:2272
virtual bool clearModuleCores()
Clears out the module core pointer list.
Definition: synthbase.cpp:1549
void setExpireSamples(uint32_t _targetValueInSamples)
set target value
Definition: synthbase.h:403
uint32_t endMIDINote
ending MIDI note for the glide
Definition: synthstructures.h:211
BQCoeffs bq
coefficients
Definition: synthbase.h:2146
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:3022
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:674
uint32_t xfadeTime_Samples
the target crossfade time
Definition: synthbase.h:458
void setParameters(double shelfFreq, double boostCut_dB)
Definition: synthbase.h:2750
virtual bool selectModuleCore(uint32_t index)
Select a core.
Definition: synthbase.cpp:1500
double doPinkingFilter(double white)
run the pinking filter
Definition: synthbase.cpp:814
void copyCoeffs(BQAudioFilter &destination)
Definition: synthbase.h:2121
Interface for wavetable sources.
Definition: synthbase.h:801
void setParameters(double shelfFreq, double boostCut_dB)
Definition: synthbase.h:2671
float ** outputBuffer
array of output buffer pointers
Definition: synthbase.h:310
IModulator * modulationInputs
input modulation values
Definition: synthbase.h:1236
virtual bool reset(double _sampleRate)=0
double BPM
current BPM, needed for LFO sync to BPM
Definition: synthbase.h:1256
std::shared_ptr< AudioBuffer > audioBuffers
Definition: synthbase.h:1816
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:756
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:249
SynthModule(std::shared_ptr< MidiInputData > _midiInputData)
Constructs a SynthModule.
Definition: synthbase.cpp:1312
double modEnd
ramp mod end value
Definition: synthbase.h:635
virtual uint32_t getAuxDAWDataUINT(uint32_t index)
get aux data value
Definition: synthbase.cpp:1153
void setAuxDAWDataUINT(uint32_t index, uint32_t value)
set the aux data with a uint32_t
Definition: synthbase.cpp:1209
std::shared_ptr< AudioBuffer > fmBuffer
Definition: synthbase.h:1822
Encapsulates the audio buffering requirements of any module that uses audio samples for input and/or ...
Definition: synthbase.h:280
double absoluteBufferTime_Sec
the time in seconds of the sample index at top of buffer
Definition: synthbase.h:1553
virtual bool clearSampleSources() override
clear all entries from the std::map
Definition: synthbase.cpp:1083
void setSamplesInBlock(uint32_t _samplesInBlock)
Set the number of samples in a block for processing.
Definition: synthbase.cpp:132
Implements a simple 2nd order HPF.
Definition: synthbase.h:2497
uint32_t moduleType
type of module, LFO_MODULE, EG_MODULE, etc...
Definition: synthbase.h:1721
float ** getInputBuffers()
Definition: synthbase.h:296
uint32_t samplesToProcess
number of samples in this block
Definition: synthbase.h:1252
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:368
virtual bool removeSampleSource(const char *uniqueSampleSetName) override
remove a PCM sample source from the database
Definition: synthbase.cpp:1058
IModulator * modulationOutputs
output modulation values
Definition: synthbase.h:1237
Object that acts as the wavetable database, as shared synth-wide resource. You should study this espe...
Definition: synthbase.h:1463
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:207
void reset(double startValue=0.0)
Reset to initial state.
Definition: synthbase.cpp:182
double timerInc
timer incrementer value
Definition: synthbase.h:631
double freqOffset
FM.
Definition: synthbase.h:371
std::shared_ptr< Modulators > modulationOutput
Definition: synthbase.h:1810
void saveState()
Freeze and save the current state of the clock; for PM and FM.
Definition: synthbase.cpp:301
void reset()
Reset to initial state; just resets counters to 0.
Definition: synthbase.cpp:406
void clear()
Definition: synthbase.h:2423
void resetTimer()
reset the counter
Definition: synthbase.h:400
uint32_t xfadeTime_Counter
counter for timer
Definition: synthbase.h:459
double phaseOffset
PM.
Definition: synthbase.h:370
virtual double getModValue(uint32_t index)
get a value from a slot in the modulation array
Definition: synthbase.cpp:1283
Implementation of a high shelving filter.
Definition: synthbase.h:2733
Interface for PCM sample sources.
Definition: synthbase.h:948
~AudioBuffer()
As one of the few objects that uses naked pointers (for maximum compatibility between plugin framewor...
Definition: synthbase.cpp:28
std::map< std::string, IWavetableSource *> wavetableSourceMap
map that connects wavetable names to source objects
Definition: synthbase.h:1479
bool standAloneMode
flag for stand-alone mode of operation outside of SynthLab
Definition: synthbase.h:1726
void createCircularBufferPowerOfTwo(uint32_t _bufferLengthPowerOfTwo)
Definition: synthbase.h:1902
Implements a simple 2nd order LPF.
Definition: synthbase.h:2408
Implementation of a constant-Q parametric EQ filter.
Definition: synthbase.h:2810
const char * waveformName
string for the GUI
Definition: synthbase.h:1311
double z1
one pole filter state variable
Definition: synthbase.h:543
virtual uint32_t getSelectedCoreIndex()
get the index of the selected core
Definition: synthbase.cpp:1487
const uint32_t UNDEFINED_MODULE
Definition: synthconstants.h:99
IPCMSampleDatabase * getIPCMSampleDatabase()
Definition: synthbase.h:1514
uint32_t wrapMask
wrapping mask = length - 1
Definition: synthbase.h:1398
void setCoeffs(BQCoeffs &_coeffs)
Definition: synthbase.h:2116
virtual uint32_t getCCMIDIData(uint32_t index)
get a CC MIDI data value
Definition: synthbase.cpp:1135
double frequency_Hz
clock frequency
Definition: synthbase.h:372
std::shared_ptr< Modulators > getModulationInput()
Definition: synthbase.h:1776
std::default_random_engine defaultGeneratorEngine
Definition: synthbase.h:700
virtual IWavetableSource * getTableSource(const char *uniqueTableName) override
selects a table source based on the unique table name
Definition: synthbase.cpp:905
Simple object that generates white, gaussian white or pink noise.
Definition: synthbase.h:693
std::shared_ptr< MidiInputData > midiInputData
Definition: synthbase.h:1813
bool reset(double _sampleRate, double startPhase, int32_t xfadeSamples=16)
Specialized reset function that:
Definition: synthbase.cpp:515
IPCMSampleDatabase * sampleDatabase
PCM sample database, usually owned by engine.
Definition: synthbase.h:1246
void reset()
Definition: synthbase.h:2106
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:2098
Structure to hold the seven coeffieicents used in the AudioFilter object from Designing Audio Effects...
Definition: synthbase.h:2079
Definition: synthlabcore.cpp:4
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2697
void clear()
Definition: synthbase.h:3008
virtual bool addTableSource(const char *uniqueTableName, IWavetableSource *tableSource) override
add a table source to the database
Definition: synthbase.cpp:933
Definition: synthstructures.h:202
uint32_t blockSize
the maximum block size
Definition: synthbase.h:313
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:1388
std::shared_ptr< AudioBuffer > getAudioBuffers()
Definition: synthbase.h:1780
XFader()
simple construction
Definition: synthbase.h:440
double countDownTimer
current timer value; this always counts DOWN regardless of the polarity of the modulation (up or down...
Definition: synthbase.h:677
uint32_t getModuleType()
Definition: synthbase.h:1701
MidiInputData()
clears out all data arrays
Definition: synthbase.cpp:1103
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:300
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2189
Holds all MIDI input data values.
Definition: synthbase.h:1578
Simple interface for SynthLab filters.
Definition: synthbase.h:1179
ModuleCoreData coreData
core strings (16) and mod knob labels (4)
Definition: synthbase.h:1725
uint64_t ** ppHexTableSet
pointers to sets of hex encoded tables
Definition: synthbase.h:1302
void reset(double _sampleRate)
Definition: synthbase.h:2818
void reset(double _sampleRate)
Definition: synthbase.h:2339
virtual bool startGlideModulation(GlideInfo &glideInfo)
starts the built-in glide modulator
Definition: synthbase.cpp:1450
std::unique_ptr< GlideModulator > glideModulator
built-in glide modulator for oscillators
Definition: synthbase.h:1727
void clearMidiEvents()
Clear the queue.
Definition: synthbase.cpp:858
virtual uint32_t getWaveTableLength()=0
void removePhaseOffset()
Remove existing a phase offset to the reset clock; for supporting phase modulation.
Definition: synthbase.cpp:590
void writeDelay(double xn)
write a value into the top of the delay
Definition: synthbase.h:2040
T readBuffer(double delayInFractionalSamples)
Definition: synthbase.h:1946
uint32_t getTick()
tick count
Definition: synthbase.h:414
uint32_t getMidiEventCount()
Definition: synthbase.cpp:866
double sampleRate
fs
Definition: synthbase.h:1251
void initInputValues()
set default values in modulator array
Definition: synthbase.cpp:1256
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:608
Implementation of a one-pole LPF.
Definition: synthbase.h:2906
void reset(double _sampleRate)
Definition: synthbase.h:2416
Modulators()
constructs the modulator object
Definition: synthbase.cpp:1237
Crossfades two values (from A to B) and then holds B for some amount of time.
Definition: synthbase.h:481
IModulator * getModulatorPtr()
Definition: synthbase.h:1639
Specialized version of the RampModulator, with nearly identically named functions to peform the porta...
Definition: synthbase.h:655
virtual float getAuxDAWDataFloat(uint32_t index)
get aux data value
Definition: synthbase.cpp:1171
bool running
state variable
Definition: synthbase.h:460
bool setHardSyncFrequency(double hardSyncFrequency)
Sets the new reset oscillator frequency in Hz.
Definition: synthbase.cpp:531
uint32_t getExpireSamples()
Definition: synthbase.h:407
Holds the audio output samples from reading a PCM sample file.
Definition: synthbase.h:915
Structure for holding information about a static wavetable, that is read from a static location...
Definition: synthbase.h:1366
virtual bool clearTableSources()=0
clear all source pointers
void setUnisonMode(double _unisonDetuneCents, double _unisonStarPhase)
Definition: synthbase.h:1783
void restoreState()
Restore the clock to its last saved state; for PM and FM.
Definition: synthbase.cpp:313
SampleLoopMode
Definition: synthbase.h:923
uint32_t ccMIDIData[kNumMIDICCs]
the global MIDI CC INPUT table that is shared across the voices via the IMIDIData interface ...
Definition: synthbase.h:1602
double modRange
range of modulation output
Definition: synthbase.h:633
uint32_t tableLength
length
Definition: synthbase.h:1438
Implements a first order feedforward LPF with coefficients a0 = a1 = 0.5.
Definition: synthbase.h:2218
void setParameters(double _fc)
Definition: synthbase.h:2928
Implements a simple 2nd order BPF.
Definition: synthbase.h:2331
Abstract base class that encapsulates functionality of a module; used with the Module-Core paradigm...
Definition: synthbase.h:1752
Structure for holding information about a static wavetable, that is read from a static location...
Definition: synthbase.h:1422
void clear()
Definition: synthbase.h:2921
virtual int32_t getState()
Definition: synthbase.h:1769
double processAudioSample(double xn)
Definition: synthbase.h:2131
bool timerExpired()
check if we hit target
Definition: synthbase.h:410
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:1340
bool timerActive
state of modulator, running (true) or expired (false)
Definition: synthbase.h:675
uint32_t wrapMask
mask = length - 1
Definition: synthbase.h:1439
void addPhaseOffset(double offset)
Add a phase offset to the reset clock; for supporting phase modulation.
Definition: synthbase.cpp:581
void reset()
Definition: synthbase.h:2226
Interface for wavetable databases.
Definition: synthbase.h:856
Implements a modulator object.
Definition: synthbase.h:1622
virtual bool addSampleSource(const char *uniqueSampleSetName, IPCMSampleSource *sampleSource) override
add a PCM sample source to the database
Definition: synthbase.cpp:1031
Minute implementation of a 2nd order resonator filter.
Definition: synthbase.h:2581
T readBuffer(int delayInSamples)
Definition: synthbase.h:1931
const char * waveformName
waveform name string
Definition: synthbase.h:1401
uint32_t counter
the timer counter
Definition: synthbase.h:417
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:734
void clear()
Definition: synthbase.h:2007
double outputComp
output scaling factor (NOT volume or attenuation, waveform specific)
Definition: synthbase.h:1399
Interface for modulator objects.
Definition: synthbase.h:743
virtual bool clearSampleSources()=0
clear all the sample sources
PluckFilterType
Definition: synthbase.h:2980
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:2016
Interface for a MIDI input data object.
Definition: synthbase.h:1086
XFadeData getCrossfadeData()
Returns the current state of the crossfade or hold.
Definition: synthbase.cpp:434
virtual bool clearTableSources() override
clear all entries from the std::map
Definition: synthbase.cpp:976
uint32_t getBlockSize()
Definition: synthbase.h:304
void setFrequency(double _frequency_Hz, double _sampleRate)
Set the clock frequency, which calculates the current phase increment value.
Definition: synthbase.cpp:235
double doSlewLimiter(double input)
Definition: synthbase.h:534
void setSlewValue(double _g)
b1 coefficient
Definition: synthbase.h:533
virtual double * getModArrayPtr(uint32_t index)
get a pointer to a slot in the modulation array
Definition: synthbase.cpp:1270
void setXFadeTime(uint32_t _xfadeTime_Samples)
Set the current crossfade time.
Definition: synthbase.cpp:350
void clear()
fast clearing of modulator array
Definition: synthbase.cpp:1246
virtual bool selectDefaultModuleCore()
Select the default core, which is always the first in the list.
Definition: synthbase.cpp:1516
void reset()
Resets object to initialized state.
Definition: synthbase.cpp:338
double coeffs[5]
biquad coefficients
Definition: synthbase.h:2311
uint32_t xfadeTime_Samples
target crossfade time
Definition: synthbase.h:502
virtual int32_t getState()
Definition: synthbase.h:1690
void setParameters(double _fc, double _Q, double _boostCut_dB)
Definition: synthbase.h:2827
void flushDelays()
Definition: synthbase.h:2109
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:1859
const char * waveformName
waveform name
Definition: synthbase.h:1442
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:545
Crossfades two values (from A to B)
Definition: synthbase.h:437
std::shared_ptr< double > table
the table (shared)
Definition: synthbase.h:1437
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:515
virtual uint32_t getCCMIDIData(uint32_t index)=0
get a MIDI CC value
virtual bool initialize(const char *_dllDirectory)
Definition: synthbase.h:1766
uint32_t xfadeTime_Counter
crossfade timer counter
Definition: synthbase.h:503
uint32_t timeSigDenomintor
time signature denominator
Definition: synthbase.h:1556
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2547
CoreProcData coreProcessData
Definition: synthbase.h:1832
Implements a simple slew limiter using a one pole lowpass filter.
Definition: synthbase.h:523
void addFrequencyOffset(double _freqOffset)
For frequency modulation, this adds a frequency offset, and recalculates the phase increment value...
Definition: synthbase.cpp:281
void setFMBuffer(std::shared_ptr< AudioBuffer > pmBuffer)
Definition: synthbase.h:1788
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:1241
double countUpTimer
current timer value; this always counts UP regardless of the polarity of the modulation (up or down) ...
Definition: synthbase.h:632
void * moduleParameters
module parameters, cloaked as void* – varies according to module
Definition: synthbase.h:1248
double glideRange
range (distance between MIDI note numbers, as double)
Definition: synthbase.h:678
void removePhaseOffset()
For phase modulation, this removes a phase offset, notice that the function does not attempt to wrap ...
Definition: synthbase.cpp:267
This structure holds all of the information needed to for the plugin framework to send MIDI informati...
Definition: synthbase.h:1539
float ** inputBuffers
set of input bufers, one per channel
Definition: synthbase.h:1240
float ** fmBuffers
used for DX synths (phase modulator synths)
Definition: synthbase.h:1242
void removeFrequencyOffset()
For frequency modulation, this removes a frequency offset and recalculates the phase inc...
Definition: synthbase.cpp:292
MIDINoteEvent noteEvent
the MIDI note event for the current audio block
Definition: synthbase.h:1257
IWavetableDatabase * wavetableDatabase
wavetable database, usually owned by engine
Definition: synthbase.h:1245
bool timerActive
state of modulator, running (true) or expired (false)
Definition: synthbase.h:630
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2775
XFader hardSyncFader
crossfader for smearing discontinuity
Definition: synthbase.h:587
bool startGlideModulation(GlideInfo &glideInfo)
Definition: synthbase.h:1696
double doPinkNoise()
Function generate pink noise by filtering white noise.
Definition: synthbase.cpp:799
const uint32_t kDefaultWaveTableLength
Definition: synthbase.h:1348
virtual bool reset(CoreProcData &processInfo)=0
double audioOutput[STEREO_CHANNELS]
array of audio output samples
Definition: synthbase.h:917
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2462
const double * dTable
table of 64-bit doubles
Definition: synthbase.h:1396
uint32_t moduleIndex
index of this core
Definition: synthbase.h:1724
double doHardSyncXFade(double inA, double inB)
Perform the crossfade on the two oscillator signals to smear over the discontinuity.
Definition: synthbase.cpp:567
virtual void setStandAloneMode(bool b)
Sets the stand-alone mode flag on all cores.
Definition: synthbase.cpp:1532
This super-structure holds a set of SynthLabTableSet called a "bank" and used in the morphing wavetab...
Definition: synthbase.h:1333
void setInterpolate(bool b)
Definition: synthbase.h:1972
double state[4]
state registers
Definition: synthbase.h:2145
SynthLabTableSet ** tablePtrs
set of table-sets
Definition: synthbase.h:1341
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:145
IWavetableDatabase * getIWavetableDatabase()
Definition: synthbase.h:1476
void pushMidiEvent(midiEvent event)
Add a MIDI event to the queue.
Definition: synthbase.cpp:848
This is a very specialized object that performs the hard-sync operation using two SynthClocks...
Definition: synthbase.h:563
Interface for PCM sample databases.
Definition: synthbase.h:1020
float ** inputBuffer
array of input buffer pointers
Definition: synthbase.h:309
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:646
void setExpireMilliSec(double timeMSec, double sampleRate)
set target value
Definition: synthbase.h:404
double modStart
ramp mod start value
Definition: synthbase.h:634
void setAlpha(double _alpha)
Definition: synthbase.h:2178
Implements a first order HPF with fc = 2.0Hz.
Definition: synthbase.h:2264
void setDelayInSamples(double _delaySamples)
set delay time in samples; used to access the delay when reading
Definition: synthbase.h:2029
virtual uint32_t getGlobalMIDIData(uint32_t index)
get a global MIDI data value
Definition: synthbase.cpp:1119
This is a tiny modulator object that produces an output that ramps up or down linearly between two va...
Definition: synthbase.h:610
double state[NUM_VARS]
for state save
Definition: synthbase.h:375
double hardSyncFrequency
reset oscillator rate
Definition: synthbase.h:588
double unisonStartPhase
unison start phase value for this core
Definition: synthbase.h:1254
uint32_t * tableLengths
pointers to lengths of each of the hex encoded tables
Definition: synthbase.h:1301
double processAudioSample(double xn, double loss=1.0)
run the filter
Definition: synthbase.h:2620
Definition: synthbase.h:1999
const uint64_t * uTable
table of 64-bit HEX values
Definition: synthbase.h:1395
XFadeType
Definition: synthconstants.h:70
uint32_t samplesInBlock
the number of samples to process in the block (in case of partial blocks)
Definition: synthbase.h:314
virtual bool removeTableSource(const char *uniqueTableName) override
remove a table source from the database
Definition: synthbase.cpp:959
double mcounter
modulo counter [0.0, +1.0], this is the value you use
Definition: synthbase.h:368
double unisonDetuneCents
detuning value for this core
Definition: synthbase.h:1253
double state[4]
state variables
Definition: synthbase.h:2309
uint32_t startMIDINote
starting MIDI note for the glide
Definition: synthstructures.h:210
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:2662
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:195
void setGlobalMIDIData(uint32_t index, uint32_t value)
set the global MIDI value
Definition: synthbase.cpp:1185
void reset(double _sampleRate)
Definition: synthbase.h:2505
void createCircularBuffer(uint32_t _bufferLength)
Definition: synthbase.h:1894
double doWhiteNoise()
Function generate white noise.
Definition: synthbase.cpp:789
bool holding
state variable for holding
Definition: synthbase.h:506
virtual IPCMSampleSource * getSampleSource(const char *uniqueSampleSetName) override
selects a PCM sample source based on the unique table name
Definition: synthbase.cpp:1002
ModuleCoreData & getModuleData()
provides access to the core data:
Definition: synthbase.h:1717
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2514
double BPM
beats per minute, aka "tempo"
Definition: synthbase.h:1554
DelayLine combDelay
for pluck position
Definition: synthbase.h:3092
double doGaussianWhiteNoise(double mean=0.0, double variance=1.0)
Function generate gaussian white noise.
Definition: synthbase.cpp:779
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2869
double bN[3]
Definition: synthbase.h:709
virtual bool getModKnobStrings(std::vector< std::string > &modKnobStrings)
Gets a std::vector of Mod Knob label strings for the selected core.
Definition: synthbase.cpp:1413
Implementation of a low shelving filter.
Definition: synthbase.h:2654
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:418
This structure defines a set of wavetables that are usually found in .h files and compiled into the s...
Definition: synthbase.h:1288
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:2741
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:698
virtual ~SynthModule()
Removes cores, if any.
Definition: synthbase.cpp:1327
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:417
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:1155
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:219
double readDelay()
read a delayed value at the location specified in the call to setDelayInSamples() ...
Definition: synthbase.h:2052
void flushBuffers()
clear out the audio; used often
Definition: synthbase.cpp:83
void advanceTimer(uint32_t ticks=1)
advance by 1
Definition: synthbase.h:413
void flushBuffer()
Definition: synthbase.h:1890
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:2374
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:52
Information about a MIDI event.
Definition: synthstructures.h:155
virtual const char * getWaveformName()=0
void reset()
Definition: synthbase.h:2171
This structure holds all of the information needed to call functions on a ModuleCore object...
Definition: synthbase.h:1233
ModuleCore()
Constructs a ModuleCore.
Definition: synthbase.h:1679
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2957
Comnination of three filters in one; note that the figure in the book does not show the variety of co...
Definition: synthbase.h:3000
Contains the two sets of strings unique to each core: the module strings (waveforms for oscillators) ...
Definition: synthstructures.h:253
double timerInc
timer incrementer value
Definition: synthbase.h:676
bool isActive()
checks to see if the modulator is running, or completed
Definition: synthbase.h:672
double glideTime_mSec
glide time to cover the range of notes
Definition: synthstructures.h:212
virtual bool getModuleStrings(std::vector< std::string > &moduleStrings, std::string ignoreStr="")
Gets a std::vector of Module Strings.
Definition: synthbase.cpp:1343
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2430
const uint32_t kNumMIDICCs
Definition: synthconstants.h:548
virtual void setModValue(uint32_t index, double value)
set a value into a slot in the modulation array
Definition: synthbase.cpp:1297
void * moduleHandle
used for dynamically loading cores from DLLs
Definition: synthbase.h:1723
const char * moduleName
module name must be set in derived constructor
Definition: synthbase.h:1722
bool setModTime(double modTime_mSec, double sampleRate)
Change the modulation time; this is optional.
Definition: synthbase.cpp:632
Abstract base class that encapsulates functionality of a module core; used with the Module-Core parad...
Definition: synthbase.h:1671
const uint32_t MAX_MODULATION_CHANNELS
Definition: synthconstants.h:28
IMidiInputData * getIMIDIInputData()
Definition: synthbase.h:1597
virtual void deleteSamples()=0
Delete the samples, part of destruction process.
SynthClock crossFadeClock
crossfading timer
Definition: synthbase.h:586
float * getInputBuffer(uint32_t channel)
Get a naked pointer to an audio INPUT buffer by channel.
Definition: synthbase.cpp:104
void setParameters(double _fc, double _Q)
Definition: synthbase.h:2348
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:589
LP1PFilter bridgeIntegrator
for bridge LPF
Definition: synthbase.h:3093
Information about a MIDI note event (note on or note off).
Definition: synthstructures.h:228
uint32_t holdTime_Counter
hold timer counter
Definition: synthbase.h:505
midiEvent * getMidiEvent(uint32_t index)
gets a MIDI event within the event queue
Definition: synthbase.cpp:879
double fc
hardcoded fc value
Definition: synthbase.h:2312
double processAudioSample(double xn)
run the filter
Definition: synthbase.h:2238
double auxData[kNumMIDIAuxes]
the aux values, specific to SynthLab
Definition: synthbase.h:1603
uint32_t holdTime_Samples
target hold time
Definition: synthbase.h:504