Skip to content

Commit

Permalink
added tString
Browse files Browse the repository at this point in the history
  • Loading branch information
spiricom committed Dec 24, 2023
1 parent 8a600df commit 1de209a
Show file tree
Hide file tree
Showing 8 changed files with 974 additions and 300 deletions.
3 changes: 2 additions & 1 deletion leaf/Inc/leaf-delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ extern "C" {
Lfloat tLinearDelay_getDelay (tLinearDelay* const);
void tLinearDelay_tapIn (tLinearDelay* const, Lfloat in, uint32_t tapDelay);
Lfloat tLinearDelay_tapOut (tLinearDelay* const, uint32_t tapDelay);
Lfloat tLinearDelay_tapOutInterpolated (tLinearDelay* const dl, Lfloat tapDelay);
Lfloat tLinearDelay_addTo (tLinearDelay* const, Lfloat value, uint32_t tapDelay);
Lfloat tLinearDelay_tick (tLinearDelay* const, Lfloat sample);
void tLinearDelay_tickIn (tLinearDelay* const, Lfloat input);
Expand Down Expand Up @@ -513,7 +514,7 @@ extern "C" {
uint32_t maxDelay;
Lfloat delay;

//coefficients for lagrange interpolation (calculated when delay length changes
//coefficients for lagrange interpolation (calculated when delay length changes)
Lfloat h0;
Lfloat h1;
Lfloat h2;
Expand Down
163 changes: 163 additions & 0 deletions leaf/Inc/leaf-filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,100 @@ extern "C" {
void tAllpass_setGain (tAllpass* const, Lfloat gain);
void tAllpass_setDelay (tAllpass* const, Lfloat delay);

//==============================================================================

/*!
@defgroup tallpass tAllpassSO
@ingroup filters
@brief Schroeder allpass. Comb-filter with feedforward and feedback.
@{
@fn void tAllpassSO_init (tAllpassSO* const, Lfloat initDelay, uint32_t maxDelay, LEAF* const leaf)
@brief Initialize a tAllpassSO to the default mempool of a LEAF instance.
@param filter A pointer to the tAllpassSO to initialize.
@param leaf A pointer to the leaf instance.
@fn void tAllpassSO_initToPool (tAllpassSO* const, Lfloat initDelay, uint32_t maxDelay, tMempool* const)
@brief Initialize a tAllpassSO to a specified mempool.
@param filter A pointer to the tAllpassSO to initialize.
@param mempool A pointer to the tMempool to use.
@fn void tAllpassSO_free (tAllpassSO* const)
@brief Free a tAllpassSO from its mempool.
@param filter A pointer to the tAllpassSO to free.
@fn Lfloat tAllpassSO_tick (tAllpassSO* const, Lfloat input)
@brief
@param filter A pointer to the relevant tAllpassSO.
@fn void tAllpassSO_setGain (tAllpassSO* const, Lfloat gain)
@brief
@param filter A pointer to the relevant tAllpassSO.
@fn void tAllpassSO_setDelay (tAllpassSO* const, Lfloat delay)
@brief
@param filter A pointer to the relevant tAllpassSO.

@} */

typedef struct _tAllpassSO
{

tMempool mempool;

Lfloat prevSamp;
Lfloat prevPrevSamp;
Lfloat a1;
Lfloat a2;
Lfloat D;

} _tAllpassSO;

typedef _tAllpassSO* tAllpassSO;

void tAllpassSO_init (tAllpassSO* const, LEAF* const leaf);
void tAllpassSO_initToPool (tAllpassSO* const, tMempool* const);
void tAllpassSO_free (tAllpassSO* const);

Lfloat tAllpassSO_tick (tAllpassSO* const, Lfloat input);
void tAllpassSO_setCoeff (tAllpassSO* const ft, Lfloat a1, Lfloat a2);
//==============================================================================


typedef struct _tThiranAllpassSOCascade
{

tMempool mempool;

int numFilts;
tAllpassSO* filters;
Lfloat B;
Lfloat iKey;
Lfloat a[3];

Lfloat k1[2];
Lfloat k2[2];
Lfloat k3[2];
Lfloat C1[2];
Lfloat C2[2];
int numActiveFilters;
int numFiltsMap[2];
int isHigh;
Lfloat D;
} _tThiranAllpassSOCascade;

typedef _tThiranAllpassSOCascade* tThiranAllpassSOCascade;

void tThiranAllpassSOCascade_init (tThiranAllpassSOCascade* const, int order, LEAF* const leaf);
void tThiranAllpassSOCascade_initToPool (tThiranAllpassSOCascade* const, int order, tMempool* const);
void tThiranAllpassSOCascade_free (tThiranAllpassSOCascade* const);

Lfloat tThiranAllpassSOCascade_tick (tThiranAllpassSOCascade* const, Lfloat input);
Lfloat tThiranAllpassSOCascade_setCoeff (tThiranAllpassSOCascade* const ft, Lfloat a1, Lfloat a2);
void tThiranAllpassSOCascade_clear (tThiranAllpassSOCascade* const ft);
//==============================================================================



/*!
@defgroup tonepole tOnePole
Expand Down Expand Up @@ -167,7 +259,78 @@ extern "C" {
void tOnePole_setSampleRate (tOnePole* const, Lfloat sr);

//==============================================================================
//==============================================================================

/*!
@defgroup tonepole tOnePole
@ingroup filters
@brief OnePole filter, reimplemented from STK (Cook and Scavone).
@{
@fn void tOnePole_init (tOnePole* const, Lfloat thePole, LEAF* const leaf)
@brief Initialize a tOnePole to the default mempool of a LEAF instance.
@param filter A pointer to the tOnePole to initialize.
@param leaf A pointer to the leaf instance.
@fn void tOnePole_initToPool (tOnePole* const, Lfloat thePole, tMempool* const)
@brief Initialize a tOnePole to a specified mempool.
@param filter A pointer to the tOnePole to initialize.
@param mempool A pointer to the tMempool to use.
@fn void tOnePole_free (tOnePole* const)
@brief Free a tOnePole from its mempool.
@param filter A pointer to the tOnePole to free.
@fn Lfloat tOnePole_tick (tOnePole* const, Lfloat input)
@brief
@param filter A pointer to the relevant tOnePole.
@fn void tOnePole_setB0 (tOnePole* const, Lfloat b0)
@brief
@param filter A pointer to the relevant tOnePole.
@fn void tOnePole_setA1 (tOnePole* const, Lfloat a1)
@brief
@param filter A pointer to the relevant tOnePole.
@fn void tOnePole_setPole (tOnePole* const, Lfloat thePole)
@brief
@param filter A pointer to the relevant tOnePole.
@fn void tOnePole_setFreq (tOnePole* const, Lfloat freq)
@brief
@param filter A pointer to the relevant tOnePole.
@fn void tOnePole_setCoefficients(tOnePole* const, Lfloat b0, Lfloat a1)
@brief
@param filter A pointer to the relevant tOnePole.
@fn void tOnePole_setGain (tOnePole* const, Lfloat gain)
@brief
@param filter A pointer to the relevant tOnePole.

@} */

typedef struct _tCookOnePole
{

tMempool mempool;
Lfloat poleCoeff, gain, sgain, output, lastOutput;
Lfloat twoPiTimesInvSampleRate;
} _tCookOnePole;

typedef _tCookOnePole* tCookOnePole;

void tCookOnePole_init (tCookOnePole* const, LEAF* const leaf);
void tCookOnePole_initToPool (tCookOnePole* const, tMempool* const);
void tCookOnePole_free (tCookOnePole* const);
Lfloat tCookOnePole_tick (tCookOnePole* const, Lfloat input);
void tCookOnePole_setPole (tCookOnePole* const, Lfloat thePole);
void tCookOnePole_setGain (tCookOnePole* const, Lfloat gain);
void tCookOnePole_setGainAndPole(tCookOnePole* const ft, Lfloat gain, Lfloat pole);
void tCookOnePole_setSampleRate (tCookOnePole* const, Lfloat sr);

//==============================================================================
/*!
@defgroup ttwopole tTwoPole
@ingroup filters
Expand Down
117 changes: 106 additions & 11 deletions leaf/Inc/leaf-physical.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ typedef struct _tSimpleLivingString5
int maxLength;
Lfloat prepIndex;
Lfloat prepPos;
tLinearDelay delLF,delUF,delUB,delLB; // delay for lower/upper/forward/backward part of the waveguide model
tLagrangeDelay delLF,delUF,delUB,delLB; // delay for lower/upper/forward/backward part of the waveguide model
tOnePole bridgeFilter, nutFilter, prepFilterU, prepFilterL;
Lfloat temp1;
Lfloat temp2;
Expand All @@ -522,19 +522,14 @@ typedef struct _tSimpleLivingString5
tHighpass DCblocker2;
tFeedbackLeveler fbLev;
tFeedbackLeveler fbLev2;
tWavefolder wf1;
tWavefolder wf2;
tWavefolder wf3;
tWavefolder wf4;
tExpSmooth wlSmooth, prepPosSmooth, prepIndexSmooth, pluckPosSmooth;

tExpSmooth wlSmooth, prepPosSmooth, prepIndexSmooth, pluckPosSmooth, pickupPointSmooth;
int oversampling;
Lfloat sampleRate;
Lfloat rippleGain;
Lfloat rippleDelay;
Lfloat ff;
Lfloat fb;
Lfloat fbSample1;
Lfloat fbSample2;
} _tSimpleLivingString5;

typedef _tSimpleLivingString5* tSimpleLivingString5;
Expand Down Expand Up @@ -564,9 +559,8 @@ void tSimpleLivingString5_setLevSmoothFactor (tSimpleLivingString5* const, L
void tSimpleLivingString5_setLevStrength (tSimpleLivingString5* const, Lfloat levStrength);
void tSimpleLivingString5_setLevMode (tSimpleLivingString5* const, int levMode);
void tSimpleLivingString5_setSampleRate (tSimpleLivingString5* const, Lfloat sr);
void tSimpleLivingString5_setFBAmount(tSimpleLivingString5* const pl, Lfloat fb);
void tSimpleLivingString5_setFFAmount(tSimpleLivingString5* const pl, Lfloat ff);
void tSimpleLivingString5_setFoldDepth(tSimpleLivingString5* const pl, Lfloat depth);


// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

Expand Down Expand Up @@ -938,8 +932,109 @@ void tSimpleLivingString5_setFoldDepth(tSimpleLivingString5* const pl, Lfloat
void tComplexLivingString_setSampleRate (tComplexLivingString* const, Lfloat sr);

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//Bow Table
typedef struct _tBowTable {
tMempool mempool;
Lfloat offSet;
Lfloat slope;
Lfloat lastOutput;
} _tBowTable;

typedef _tBowTable* tBowTable;

void tBowTable_init (tBowTable* const bt, LEAF* const leaf);
void tBowTable_initToPool (tBowTable* const bt, tMempool* const mp);
void tBowTable_free (tBowTable* const bt);
Lfloat tBowTable_lookup (tBowTable* const bt, Lfloat sample);

typedef struct _tBowed
{
tMempool mempool;
int oversampling;
// user controlled vars
Lfloat x_bp; // bow pressure
Lfloat x_bpos; // bow position
Lfloat x_bv; // bow velocity
Lfloat x_fr; // frequency

Lfloat fr_save;

// delay lines
tLinearDelay neckDelay;
tLinearDelay bridgeDelay;

// one pole filter
tCookOnePole reflFilt;

tBowTable bowTabl;

// stuff
Lfloat maxVelocity, baseDelay, betaRatio;
Lfloat sampleRate;
Lfloat invSampleRate;
tSVF lowpass;
Lfloat output;
} _tBowed;

typedef _tBowed* tBowed;

void tBowed_init (tBowed* const, int oversampling, LEAF* const leaf);
void tBowed_initToPool (tBowed* const, int oversampling, tMempool* const);
void tBowed_free (tBowed* const);

Lfloat tBowed_tick (tBowed* const);

void tBowed_setFreq (tBowed* const, Lfloat freq);
void tBowed_setWaveLength (tBowed* const, Lfloat waveLength); // in samples
void tBowed_setSampleRate (tBowed* const, Lfloat sr);



// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//from Plucked-string synthesis algorithms with tension modulation nonlinearity
//by Vesa Valimaki
typedef struct _tTString
{
tMempool mempool;
int oversampling;
Lfloat invOversampling;
// delay lines
tLagrangeDelay delay;
Lfloat power;
Lfloat M;


// one pole filter
tCookOnePole reflFilt;
Lfloat baseDelay;
uint32_t halfBaseDelay;
Lfloat sampleRate;
Lfloat invSampleRate;
Lfloat output;
Lfloat prevTension;
Lfloat tensionGain;
Lfloat a;
tSlide slide;
tHighpass dcBlock;
tThiranAllpassSOCascade allpass;
Lfloat allpassDelay;
int stop;
} _tTString;

typedef _tTString* tTString;

void tTString_init (tTString* const, int oversampling, LEAF* const leaf);
void tTString_initToPool (tTString* const, int oversampling, tMempool* const);
void tTString_free (tTString* const);

Lfloat tTString_tick (tTString* const);

void tTString_setFreq (tTString* const, Lfloat freq);
void tTString_pluck (tTString* const bw, Lfloat position, Lfloat amplitude);
void tTString_setWaveLength (tTString* const, Lfloat waveLength); // in samples
void tTString_setSampleRate (tTString* const, Lfloat sr);
void tTString_setHarmonicity (tTString* const, Lfloat B, Lfloat freq);

/*!
@defgroup treedtable tReedTable
@ingroup physical
Expand Down
Loading

0 comments on commit 1de209a

Please sign in to comment.