SynthLab SDK
synthfunctions.h File Reference

hard-coded arrays of FIR filter coefficients for the sample rate conversion objects (Interpolator and Decimator) More...

#include "synthbase.h"
#include "bleptables.h"

Go to the source code of this file.

Classes

struct  SynthLab::VectorXFadeData
 Holds mixing coefficient multipliers for the Sequential/Korg vector joystick. More...
 

Macros

#define __synthfunctions_h__
 
#define enumToInt(ENUM)   static_cast<int>(ENUM)
 macro helper to cast a typed enum to an int More...
 
#define compareEnumToInt(ENUM, INT)   (static_cast<int>(ENUM) == (INT))
 compare a typed enum value to an int More...
 
#define compareIntToEnum(INT, ENUM)   ((INT) == static_cast<int>(ENUM))
 compare a typed enum value to an int More...
 
#define convertIntToEnum(INT, ENUM)   static_cast<ENUM>(INT)
 convert an int to an enum, e.g. for passing to functions More...
 

Enumerations

enum  SynthLab::NoteDuration {
  k32ndTriplet, k32nd, k16thTriplet, kDot32nd,
  k16th, k8thTriplet, kDot16th, k8th,
  kQuarterTriplet, kDot8th, kQuarter, kHalfTriplet,
  kDotQuarter, kHalf, kWholeTriplet, kDotHalf,
  kWhole, kDotWhole, kOff, kNumNoteDurations
}
 emumearation of musical durations, shortest to longest More...
 

Functions

void SynthLab::copyOutputToInput (std::shared_ptr< AudioBuffer > source, std::shared_ptr< AudioBuffer > destination, uint32_t channel, uint32_t samplesToCopy)
 copies an output audio buffer to an input audio buffer More...
 
void SynthLab::copyOutputToOutput (std::shared_ptr< AudioBuffer > source, std::shared_ptr< AudioBuffer > destination, uint32_t channel, uint32_t samplesToCopy)
 copies an output audio buffer to another output audio buffer More...
 
void SynthLab::copyOutputToOutput (std::shared_ptr< AudioBuffer > source, SynthProcessInfo &destination, uint32_t channel, uint32_t samplesToCopy)
 copies an output audio buffer to the SynthProcessInfo audio output buffer More...
 
void SynthLab::copyBufferToInput (std::shared_ptr< AudioBuffer > source, std::shared_ptr< AudioBuffer > destination, uint32_t channel, uint32_t samplesToCopy)
 copies an output audio buffer to an input audio buffer More...
 
void SynthLab::copyAudioBufferOutputToSynthOutput (std::shared_ptr< AudioBuffer > source, SynthProcessInfo &destination, uint32_t channel, uint32_t samplesToCopy)
 copies an output audio buffer to the SynthProcessInfo audio output buffer More...
 
void SynthLab::copySynthOutputToAudioBufferInput (SynthProcessInfo &source, std::shared_ptr< AudioBuffer > destination, uint32_t channel, uint32_t samplesToCopy)
 Complementary function that moves audio from the SynthProcessInfo output into an audio buffer. More...
 
double SynthLab::normToLogNorm (double normalizedValue)
 normalized to Log-normalized version More...
 
double SynthLab::logNormToNorm (double logNormalizedValue)
 log-normalized to normalized version More...
 
double SynthLab::normToAntiLogNorm (double normalizedValue)
 normalized to anti-log normalized version More...
 
double SynthLab::antiLogNormToNorm (double aLogNormalizedValue)
 anti-log normalized to normalized version More...
 
double SynthLab::getModKnobValueLinear (double normalizedValue, double min, double max)
 maps a mod-knob value on the range of [0.0, 1.0] to a number on the range [min, max] More...
 
double SynthLab::getModKnobValueLog (double normalizedValue, double min, double max)
 maps a mod-knob value on the range of [0.0, 1.0] to a number on the range [min, max] logarithmically More...
 
double SynthLab::getModKnobValueAntiLog (double normalizedValue, double min, double max)
 maps a mod-knob value on the range of [0.0, 1.0] to a number on the range [min, max] anti-logarithmically More...
 
double SynthLab::msecToSamples (double sampleRate, double timeMSec)
 convert a time in milliseconds to a floating point sample count More...
 
void SynthLab::clampMaxValue (double &value, double maxValue)
 Bound a value to max limits. More...
 
void SynthLab::clampMinValue (double &value, double minValue)
 Bound a value to min limits. More...
 
void SynthLab::boundValue (double &value, double minValue, double maxValue)
 Bound a value to min and max limits. More...
 
void SynthLab::boundUIntValue (uint32_t &value, uint32_t minValue, uint32_t maxValue)
 Bound a uint32_t value to min and max limits. More...
 
void SynthLab::boundIntValue (int32_t &value, int32_t minValue, int32_t maxValue)
 Bound an int32_t value to min and max limits. More...
 
void SynthLab::boundValueUnipolar (double &value)
 Bound a value to [0, +1]. More...
 
void SynthLab::boundValueBipolar (double &value)
 Bound a value to [-1, +1]. More...
 
void SynthLab::boundMIDIValueByte (uint32_t &value)
 Bound a value to 0 and 127 limits. More...
 
void SynthLab::boundMIDIValueDoubleByte (uint32_t &value)
 Bound a value to min and max limits. More...
 
void SynthLab::mapDoubleValue (double &value, double min, double max, double minMap, double maxMap)
 map double on a range of (min, max) to the same double on the range of (minMap, maxMap) More...
 
void SynthLab::mapDoubleValue (double &value, double min, double minMap, double slope)
 map double on a range of (min, max) to the same double on the range of (minMap, maxMap) using a pre-calculated slope variable where: More...
 
void SynthLab::mapIntValue (int &value, int min, int max, int minMap, int maxMap, bool roundValue=true)
 map int on a range of (min, max) to the same int on the range of (minMap, maxMap) More...
 
void SynthLab::mapUintValue (uint32_t &value, uint32_t min, uint32_t max, uint32_t minMap, uint32_t maxMap, bool roundValue=true)
 map unsigned int on a range of (min, max) to the same unsigned int on the range of (minMap, maxMap) More...
 
uint32_t SynthLab::mapDoubleToUINT (double value, double min, double max, uint32_t minMap, uint32_t maxMap, bool roundValue=false)
 map double on a range of (min, max) to a uint32_t on the range of (minMap, maxMap) More...
 
double SynthLab::mapUINTToDouble (uint32_t value, uint32_t min, uint32_t max, double minMap, double maxMap)
 map uint32_t on a range of (min, max) to a double on the range of (minMap, maxMap) More...
 
double SynthLab::midi14_bitToBipolar (uint32_t midiDataLSB, uint32_t midiDataMSB)
 Converts MIDI data bytes 1 and 2 (14-bit) into a bipolar [-1, +1] value. More...
 
uint32_t SynthLab::midi14_bitToUnipolarInt (uint32_t midiDataLSB, uint32_t midiDataMSB)
 Converts MIDI data bytes 1 and 2 (14-bit) into a unipolar value 0 -> 16383. More...
 
double SynthLab::midi14_bitToUnipolarDouble (uint32_t midiDataLSB, uint32_t midiDataMSB)
 Converts MIDI data bytes 1 and 2 (14-bit) into a unipolar double value 0.0 -> 1.0. More...
 
double SynthLab::midi14_bitToDouble (uint32_t midiDataLSB, uint32_t midiDataMSB, double minValue, double maxValue)
 Converts MIDI data bytes 1 and 2 (14-bit) into a double value on the range [minValue, maxValue]. More...
 
void SynthLab::unipolarIntToMIDI14_bit (uint32_t unipolarValue, uint32_t &midiDataLSB, uint32_t &midiDataMSB)
 Converts value from 0 -> 16383 into 14-bit MIDI bytes, pass by reference. More...
 
void SynthLab::bipolarIntToMIDI14_bit (int32_t biPolarValue, int32_t minValue, int32_t maxValue, uint32_t &midiDataLSB, uint32_t &midiDataMSB)
 Converts int value on the range [minValue, maxValue] into 14-bit MIDI bytes, pass by reference. More...
 
void SynthLab::unipolarDoubleToMIDI14_bit (double unipolarValue, uint32_t &midiDataLSB, uint32_t &midiDataMSB)
 Converts double value on the range [0, 1] into 14-bit MIDI bytes, pass by reference. More...
 
double SynthLab::midiPitchBendToBipolar (uint32_t midiData1, uint32_t midiData2)
 Converts MIDI data bytes 1 and 2 into a bipolar [-1, +1] value. More...
 
double SynthLab::doUnipolarModulationFromMin (double unipolarModulatorValue, double minValue, double maxValue)
 Perform unipolar modulation from a min value up to a max value using a unipolar modulator value. More...
 
double SynthLab::doUnipolarModulationFromMax (double unipolarModulatorValue, double minValue, double maxValue)
 Perform unipolar modulation from a max value down to a min value using a unipolar modulator value. More...
 
double SynthLab::doBipolarModulation (double bipolarModulatorValue, double minValue, double maxValue)
 Perform bipolar modulation about a center that his halfway between the min and max values. More...
 
double SynthLab::splitBipolar (double value)
 maps a unipolar value across two unipolar values, from middle More...
 
double SynthLab::bipolar (double value)
 calculates the bipolar [-1.0, +1.0] value FROM a unipolar [0.0, +1.0] value More...
 
void SynthLab::bipolarXForm (double &value)
 identical to bipolar( ) but returns value with pass-by-reference argument More...
 
double SynthLab::unipolar (double value)
 calculates the unipolar [0.0, +1.0] value FROM a bipolar [-1.0, +1.0] value More...
 
void SynthLab::unipolarXForm (double &value)
 identical to unipolar( ) but returns value with pass-by-reference argument More...
 
double SynthLab::raw2dB (double raw)
 calculates dB for given input More...
 
double SynthLab::dB2Raw (double dB)
 converts dB to raw value More...
 
double SynthLab::peakGainFor_Q (double Q)
 calculates the peak magnitude for a given Q More...
 
double SynthLab::dBPeakGainFor_Q (double Q)
 calculates the peak magnitude in dB for a given Q More...
 
double SynthLab::applyPhaseDistortion (double mcounter, double x_break, double y_break=0.5)
 
double SynthLab::sgn (double xn)
 calculates sgn( ) of input More...
 
double SynthLab::calcWSGain (double xn, double saturation, double asymmetry)
 calculates gain of a waveshaper More...
 
double SynthLab::atanWaveShaper (double xn, double saturation)
 calculates arctangent waveshaper More...
 
double SynthLab::tanhWaveShaper (double xn, double saturation)
 calculates hyptan waveshaper More...
 
double SynthLab::softClipWaveShaper (double xn, double saturation)
 calculates hyptan waveshaper More...
 
double SynthLab::fuzzExp1WaveShaper (double xn, double saturation, double asymmetry)
 calculates fuzz exp1 waveshaper More...
 
void SynthLab::copyStingList (std::vector< std::string > &source, std::vector< std::string > &destination)
 Copies one vector of strings to another. More...
 
std::string SynthLab::concatStrings (std::string s1, std::string s2)
 Concatenate two strings. More...
 
void SynthLab::ReplaceSubStrWithStr (std::string &str, const std::string &from, const std::string &to)
 Helper to relace strings within a std::string object. More...
 
void SynthLab::stripLastFolderFromPath (std::string &str)
 Helper to strip the last folder path from a given path. More...
 
void SynthLab::getPluginContainerFolder (std::string &str)
 Helper to get the outer plugin folder with the inner folder path. More...
 
double SynthLab::doLinearInterpolation (double x1, double x2, double y1, double y2, double x)
 performs linear interpolation of x distance between two (x,y) points; returns interpolated value More...
 
double SynthLab::doLinearInterpolation (double y1, double y2, double fractional_X)
 performs linear interpolation of fractional x distance between two adjacent (x,y) points; returns interpolated value More...
 
double SynthLab::doLagrangeInterpolation (double *x, double *y, int n, double xbar)
 implements n-order Lagrange Interpolation More...
 
uint32_t SynthLab::midiNoteNumberFromOscFrequency (double oscillatorFrequency, double frequencyA440=440.0)
 use lookup table to find pitch shift multipliers, uses linear interpolation More...
 
double SynthLab::midiNoteNumberToOscFrequency (uint32_t midiNoteNumber, double frequencyA440=440.0)
 converts a MIDI note number into a corresponding oscillator frequency in Hz More...
 
double SynthLab::calculateWaveTablePhaseInc (double oscFrequency, double sampleRate, uint32_t wavetableLength)
 calculates the phase-increment for a wavetable for a target oscillator frequency More...
 
bool SynthLab::checkAndWrapWaveTableIndex (double &index, uint32_t tableLength)
 check and do modulo (fmod) wrap of a wavetable index value More...
 
int SynthLab::countTrailingZero (int x)
 count trailing zeros in a binary number More...
 
uint64_t SynthLab::countTrailingZeros_x64 (uint64_t x)
 count trailing zeros in a binary number, return in unsigned int More...
 
double SynthLab::doSimpleSineLUT (double angle)
 
double SynthLab::doSimpleCosineLUT (double angle)
 
void SynthLab::calculatePanValues (double bipolarModulator, double &leftPanValue, double &rightPanValue)
 calculates the left and right pan values from a bipolar (-1 -> 1) value More...
 
void SynthLab::calculateConstPwrMixValues (double bipolarModulator, double &mixValueA, double &mixValueB)
 converts bipolar (-1 -> 1) value into a pair of constant power mixing coefficients More...
 
double SynthLab::crossfade (XFadeType xfadeType, double inputA, double inputB, double xFrac)
 crossfade two values And B together by some fractional amount More...
 
double SynthLab::semitonesBetweenFrequencies (double startFrequency, double endFrequency)
 calculates the number of semitones between a start and end frequency More...
 
double SynthLab::getTimeFromTempo (double BPM, NoteDuration duration, bool returnMilliseconds=false)
 converts a BPM value and a NoteDuration into a time More...
 
double SynthLab::getTimeFromTempo (double BPM, double normalizedNoteMult)
 converts a BPM value and a normalized note multiplier on the range [0, 1] to a note duration multiplier More...
 
double SynthLab::quantizeBipolarValue (double d, uint32_t qLevels)
 Quantizes a double value into some number of quantization levels. More...
 
uint64_t SynthLab::doubleToUint64 (double d)
 maps a double value into a uint64 value without casting or mangling bits More...
 
double SynthLab::uint64ToDouble (uint64_t u)
 maps a uint64 value to a double value without casting or mangling bits More...
 
uint32_t SynthLab::floatToUint32 (float f)
 maps a float value to a uint32_t value without casting or mangling bits More...
 
float SynthLab::uint32ToFloat (uint32_t u)
 maps a uint32_t value to a float value without casting or mangling bits More...
 
bool SynthLab::inRange (double low, double high, double x)
 tests a number to see if it is withing a certain range More...
 
double SynthLab::wrapMax (double x, double max)
 wraps a value around a maximum value enough times that it falls within the maximum boundary More...
 
double SynthLab::wrapMinMax (double x, double min, double max)
 wraps a value around a maximum value enough times that it falls within the maximum boundary More...
 
std::vector< std::string > SynthLab::charArrayToStringVector (const char **charArray, uint32_t size, std::string ignoreString="")
 Converts an old fasioned array of char* strings to a vector of std::strings. More...
 
bool SynthLab::appendCharArrayToStringVector (const char **charArray, uint32_t size, std::vector< std::string > &outputVector, std::string ignoreString)
 Appends an old fasioned array of char* strings to a vector of std::strings. More...
 
double SynthLab::mmaMIDItoAtten (uint32_t midiValue)
 calculates the raw attenuation according to MMA DLS spec midiValue = the MIDI (0 -> 127) value to convert More...
 
VectorXFadeData SynthLab::calculateVectorMix (double joystick_X, double joystick_Y, double origin_X=0.0, double origin_Y=0.0)
 converts a joystick (x,y) position into the four mixing coefficients plus the X/Y axis shaodows More...
 
double SynthLab::quadraticSine (double angle)
 produces the quadratic sine approximation More...
 
double SynthLab::BhaskaraISine (double angle)
 produces the Bhaskara's sine approximation More...
 
double SynthLab::parabolicSine (double angle)
 highest accurace sinudoid approximation function More...
 
double SynthLab::calculatePitchBend (std::shared_ptr< MidiInputData > midiInputData)
 Calculate a pitch bend multiplier value based on the global MIDI input values: More...
 
double SynthLab::calculatePitchBend (IMidiInputData *midiInputData)
 Second method to calculate a pitch bend multiplier value based on the global MIDI input values: More...
 
double SynthLab::calculateMasterTuning (IMidiInputData *midiInputData)
 Method to calculate a tuning (pitch bend) multiplier value based on the global MIDI input values: More...
 
uint32_t SynthLab::calculateNumTables (uint32_t seedMIDINote, uint32_t tableIntervalSemitones)
 Calculates the number of wavetables needed to cover the MIDI keyboard starting from a seed note, and them progressing up the keyboard by some number of semitones between each table. More...
 
double SynthLab::readHexLUT (uint64_t *table, double xn)
 Read a table that has been encoded as uint64_t HEX values. More...
 
double SynthLab::concaveXForm (double xn, bool useLUT=false)
 Perform the MMA concave tranform on a unipolar value. More...
 
double SynthLab::bipolarConcaveXForm (double xn, bool useLUT=false)
 Perform the MMA concave tranform on a bipolar value. More...
 
double SynthLab::reverseConcaveXForm (double xn, bool useLUT=false)
 Perform the MMA reverse concave tranform on a unipolar value. More...
 
double SynthLab::bipolarReverseConcaveXForm (double xn, bool useLUT=false)
 Perform the MMA reverse concave tranform on a bipolar value. More...
 
double SynthLab::convexXForm (double xn, bool useLUT=false)
 Perform the MMA convex tranform on a unipolar value. More...
 
double SynthLab::bipolarConvexXForm (double xn, bool useLUT=false)
 Perform the MMA convex tranform on a bipolar value. More...
 
double SynthLab::reverseConvexXForm (double xn, bool useLUT=false)
 Perform the MMA reverse convex tranform on a unipolar value. More...
 
double SynthLab::bipolarReverseConvexXForm (double xn, bool useLUT=false)
 Perform the MMA reverse convex tranform on a bipolar value. More...
 
double SynthLab::doPolyBLEP_2 (double mcounter, double phaseInc, double height, bool risingEdge)
 Calculates the 2nd order polynomial BLEP correction factor. More...
 
double SynthLab::doBLEP_N (uint32_t tableLength, double modCounter, double phaseInc, double height, bool risingEdge, uint32_t pointsPerSide, bool interpolate=false)
 Calculates the BLEP correction factor for 1, 2, 3 or 4 points of correction on each side of the waveform discontinuity. More...
 
void SynthLab::initDMConfig (std::shared_ptr< MidiInputData > midiInputData, DMConfig *config)
 Initializes the MIDI aux data with configuration information; for DM only. More...
 
void SynthLab::initMIDIInputData (std::shared_ptr< MidiInputData > midiInputData)
 Initializes the MIDI input data arrays with values that prevent the synth from appearing to be malfunctioning. This includes bringing volume controls up to unity gain (max output) and pan to the center as well as setting pitch bend range and overall tuning (known as master volume and master tuning in the MMA documentation) More...
 

Variables

const double SynthLab::kCTCoefficient = 5.0 / 12.0
 concave and/or convex transform correction factor More...
 
const double SynthLab::kCTCorrFactorZero = pow(10.0, (-1.0 / kCTCoefficient))
 concave/convex transform correction factor at x = 0 More...
 
const double SynthLab::kCTCorrFactorAnitZero = 1.0 / (1.0 - kCTCorrFactorZero)
 inverse concave/convex transform factor at x = 0 More...
 
const double SynthLab::kCTCorrFactorUnity = 1.0 / (1.0 + kCTCoefficient*log10(1.0 + kCTCorrFactorZero))
 concave/convex transform correction factor at x = 1 More...
 
const double SynthLab::kCTCorrFactorAntiUnity = 1.0 / (1.0 + (-pow(10.0, (-1.0 / kCTCoefficient))))
 inverse concave/convex transform correction factor at x = 1 More...
 
const double SynthLab::kCTCorrFactorAntiLog = kCTCoefficient*log10(1.0 + kCTCorrFactorZero)
 concave/convex transform correction factor More...
 
const double SynthLab::kCTCorrFactorAntiLogScale = 1.0 / (-kCTCoefficient*log10(kCTCorrFactorZero) + kCTCorrFactorAntiLog)
 concave/convex transform scaling factor More...
 
const double SynthLab::pdSlope = (0.9 - 0.1) / (1.0 - 0.0)
 
const double SynthLab::D = 5.0*kPiSqared
 
const double SynthLab::B = 4.0 / kPi
 
const double SynthLab::C = -4.0 / (kPiSqared)
 
const double SynthLab::P = 0.225
 

Detailed Description

hard-coded arrays of FIR filter coefficients for the sample rate conversion objects (Interpolator and Decimator)

See also Designing Software Synthesizers in C++ 2nd Ed. by Will Pirkle.

Author
Will Pirkle
Date
20-April-2021
Author
Will Pirkle
Date
20-April-2021