Skip to content

Commit

Permalink
good working tTString
Browse files Browse the repository at this point in the history
  • Loading branch information
spiricom committed Jan 10, 2024
1 parent c749203 commit 350c624
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 54 deletions.
2 changes: 2 additions & 0 deletions leaf/Inc/leaf-filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ void tCookOnePole_setSampleRate (tCookOnePole* const, Lfloat sr);
Lfloat g,k,a1,a2,a3,cH,cB,cL,cBK;
Lfloat sampleRate;
Lfloat invSampleRate;
Lfloat phaseComp;
const Lfloat *table;
} _tSVF;

Expand All @@ -837,6 +838,7 @@ void tCookOnePole_setSampleRate (tCookOnePole* const, Lfloat sr);
void tSVF_setFreqAndQ (tSVF* const svff, Lfloat freq, Lfloat Q);
void tSVF_setFilterType (tSVF* const svff, SVFType type);
void tSVF_setSampleRate (tSVF* const svff, Lfloat sr);
Lfloat tSVF_getPhaseAtFrequency (tSVF* const svff, Lfloat freq);

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

Expand Down
48 changes: 30 additions & 18 deletions leaf/Inc/leaf-physical.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ extern "C" {
#include "leaf-oscillators.h"
#include "leaf-envelopes.h"
#include "leaf-dynamics.h"

/*!
* @internal
* Header.
* @include basic-oscillators.h
* @example basic-oscillators.c
* An example.
*/



typedef struct _tPickupNonLinearity
{

tMempool mempool;
Lfloat prev;
} _tPickupNonLinearity;

typedef _tPickupNonLinearity* tPickupNonLinearity;

void tPickupNonLinearity_init (tPickupNonLinearity* const p, LEAF* const leaf);
void tPickupNonLinearity_initToPool (tPickupNonLinearity* const p, tMempool* const mp);
void tPickupNonLinearity_free (tPickupNonLinearity* const p);
Lfloat tPickupNonLinearity_tick (tPickupNonLinearity* const p, Lfloat in);
//==============================================================================

/*!
Expand Down Expand Up @@ -410,6 +416,7 @@ typedef struct _tSimpleLivingString3
Lfloat sampleRate;
Lfloat rippleGain;
Lfloat rippleDelay;
Lfloat invOnePlusr;
} _tSimpleLivingString3;

typedef _tSimpleLivingString3* tSimpleLivingString3;
Expand Down Expand Up @@ -1026,7 +1033,7 @@ typedef struct _tTString
Lfloat freq;
tSVF lowpassP;
tSVF highpassP;

Lfloat filterFreq;
Lfloat decayCoeff;
Lfloat muteCoeff;
Lfloat r;
Expand All @@ -1046,7 +1053,7 @@ typedef struct _tTString
Lfloat pickupModOscFreq;
Lfloat pickupModOscAmp;
tSVF pickupFilter;

tSVF pickupFilter2;
Lfloat slideAmount;
Lfloat absSlideAmount;
Lfloat smoothedSlideAmount;
Expand All @@ -1058,7 +1065,6 @@ typedef struct _tTString
Lfloat barPulseInc;
uint32_t barPulsePhasor;
tSVF barResonator;
tSVF barLowpass;
Lfloat barPosition;
Lfloat prevBarPosition;
Lfloat openStringLength;
Expand All @@ -1085,11 +1091,7 @@ typedef struct _tTString
uint32_t inharmonic;
Lfloat inharmonicMult;
uint32_t maxDelay;
uint32_t barJumps;
uint32_t pitchJumps;
uint32_t tensionJumps;
Lfloat prevBaseDelay;
Lfloat coupling;
tFeedbackLeveler feedback;
tFeedbackLeveler feedbackP;
Lfloat feedbackNoise;
Expand All @@ -1102,6 +1104,9 @@ typedef struct _tTString
tExpSmooth pickNoise;
tNoise pickNoiseSource;
Lfloat pluckPoint_forInput;
tSVF peakFilt;
Lfloat pickupAmount;
tPickupNonLinearity p;
} _tTString;

typedef _tTString* tTString;
Expand Down Expand Up @@ -1135,8 +1140,15 @@ void tTString_setBarDrive (tTString* const bw, Lfloat drive);
void tTString_setFeedbackStrength (tTString* const bw, Lfloat strength);
void tTString_setFeedbackReactionSpeed (tTString* const bw, Lfloat speed);
void tTString_setInharmonic (tTString* const bw, uint32_t onOrOff);

/*!
void tTString_setWoundOrUnwound (tTString* const bw, uint32_t wound);
void tTString_setWindingsPerInch (tTString* const bw, uint32_t windings);
void tTString_setPickupFilterFreq (tTString* const bw, Lfloat cutoff);
void tTString_setPickupFilterQ (tTString* const bw, Lfloat Q);
void tTString_setFilterFreqDirectly (tTString* const bw, Lfloat freq);
void tTString_setDecayInSeconds (tTString* const bw, Lfloat decay);
void tTString_setPickupAmount (tTString* const bw, Lfloat amount);
/*!
* *
@defgroup treedtable tReedTable
@ingroup physical
@brief Reed Table - borrowed from STK
Expand Down
2 changes: 1 addition & 1 deletion leaf/Src/leaf-distortion.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../Inc/leaf-math.h"
#include "../Inc/leaf-filters.h"
#ifdef ARM_MATH_CM7
#include "../../Drivers/CMSIS/DSP/Include/arm_math.h"
#include "arm_math.h"
#endif
#endif

Expand Down
16 changes: 15 additions & 1 deletion leaf/Src/leaf-filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#endif

#ifdef ARM_MATH_CM7
#include "arm_math.h"
#include <arm_math.h>
#endif

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
Expand Down Expand Up @@ -1295,6 +1295,20 @@ void tSVF_setSampleRate (tSVF* const svff, Lfloat sr)
svf->invSampleRate = 1.0f/svf->sampleRate;
}

//only works for lowpass right now
//actually doesn't work at all yet!
Lfloat tSVF_getPhaseAtFrequency (tSVF* const svff, Lfloat freq)
{
_tSVF* svf = *svff;
Lfloat w = svf->invSampleRate *freq*TWO_PI;
Lfloat c = 0.0f;
Lfloat f = 0.0f;
Lfloat d = 0.0f;
Lfloat num = sinf(2.0f*w) * (c-f);
Lfloat den = (c + f) + (2.0f * d * cosf(w)) + ((c+f)*cosf(2.0f * w));
return atan2f(num, den);
}

#if LEAF_INCLUDE_FILTERTAN_TABLE
// Efficient version of tSVF where frequency is set based on 12-bit integer input for lookup in tanh wavetable.
void tEfficientSVF_init(tEfficientSVF* const svff, SVFType type, uint16_t input, Lfloat Q, LEAF* const leaf)
Expand Down
Loading

0 comments on commit 350c624

Please sign in to comment.