History

minblep oscillators and start to hard sync

Matthew Wang committed 6 years ago

Commit 482f07c1 parent a98552b8 files · +579 −88Browse files

Unified · Split

8 files
  1. LEAF/Inc/leaf-effects.h +3 −3
  2. LEAF/Inc/leaf-oscillators.h +220 −2
  3. LEAF/Inc/leaf-sampling.h +1 −3
  4. LEAF/Src/leaf-effects.c +3 −3
  5. LEAF/Src/leaf-filters.c +22 −22
  6. LEAF/Src/leaf-oscillators.c +307 −9
  7. LEAF/Src/leaf-sampling.c +4 −4
  8. LEAF_JUCEPlugin/Source/MyTest.cpp +19 −42
LEAF/Inc/leaf-effects.h+3−3
@@ -130,11 +130,11 @@ extern "C" { · 129 unmodified lines
130130
131131 float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const);
132132
133− float tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const, float freq);
133+ void tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const, float freq);
134134
135− float tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const, float openLength);
135+ void tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const, float openLength);
136136
137− float tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const, float pulseLength);
137+ void tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const, float pulseLength);
138138
139139 //==============================================================================
140140
LEAF/Inc/leaf-oscillators.h+220−2
@@ -902,9 +902,9 @@ extern "C" { · 901 unmodified lines
902902
903903 typedef _tMinBLEP* tMinBLEP;
904904
905− void tMinBLEP_init (tMinBLEP* const minblep);
905+ void tMinBLEP_init (tMinBLEP* const minblep, int zeroCrossings, int oversamplerRatio);
906906 void tMinBLEP_free (tMinBLEP* const minblep);
907− void tMinBLEP_initToPool (tMinBLEP* const minblep, tMempool* const pool);
907+ void tMinBLEP_initToPool (tMinBLEP* const minblep, int zeroCrossings, int oversamplerRatio, tMempool* const pool);
908908 void tMinBLEP_freeFromPool (tMinBLEP* const minblep, tMempool* const pool);
909909
910910 // pass in audio, identify discontinuities and return the audio with minbleps inserted
@@ -915,6 +915,224 @@ extern "C" { · 4 unmodified lines
915915 void tMinBLEP_setOversamplingRatio (tMinBLEP* const minblep, float ratio);
916916 void tMinBLEP_setNumZeroCrossings (tMinBLEP* const minblep, int numCrossings);
917917
918+ //==============================================================================
919+
920+ /* tMBTriangle: Anti-aliased Triangle waveform using wavetable interpolation. */
921+ typedef struct _tMBTriangle
922+ {
923+ float phase;
924+ float inc,freq;
925+ float skew;
926+ float lastOut;
927+
928+ tMinBLEP minBlep;
929+ tHighpass dcBlock;
930+ } _tMBTriangle;
931+
932+ typedef _tMBTriangle* tMBTriangle;
933+
934+ /*!
935+ * @defgroup tMBTriangle tMBTriangle
936+ * @ingroup oscillators
937+ * @brief An anti-aliased triangle waveform oscillator.
938+ * @{
939+ */
940+
941+ //! Initialize a tMBTriangle to the default LEAF mempool.
942+ /*!
943+ @param osc A pointer to the tMBTriangle to be initialized.
944+ */
945+ void tMBTriangle_init (tMBTriangle* const osc);
946+
947+
948+ //! Free a tMBTriangle from the default LEAF mempool.
949+ /*!
950+ @param osc A pointer to the tMBTriangle to be freed.
951+ */
952+ void tMBTriangle_free (tMBTriangle* const osc);
953+
954+
955+ //! Initialize a tMBTriangle to a specified mempool.
956+ /*!
957+ @param osc A pointer to the tMBTriangle to be initialized.
958+ @param pool A pointer to the tMempool to which the tMBTriangle should be initialized.
959+ */
960+ void tMBTriangle_initToPool (tMBTriangle* const osc, tMempool* const pool);
961+
962+
963+ //! Free a tMBTriangle from a specified mempool.
964+ /*!
965+ @param osc A pointer to the tMBTriangle to be freed.
966+ @param pool A pointer to the tMempool from which the tMBTriangle should be freed.
967+ */
968+ void tMBTriangle_freeFromPool (tMBTriangle* const osc, tMempool* const pool);
969+
970+
971+ //! Tick a tMBTriangle oscillator.
972+ /*!
973+ @param osc A pointer to the relevant tMBTriangle.
974+ @return The ticked sample as a float from -1 to 1.
975+ */
976+ float tMBTriangle_tick (tMBTriangle* const osc);
977+
978+
979+ //! Set the frequency of a tMBTriangle oscillator.
980+ /*!
981+ @param osc A pointer to the relevant tMBTriangleangle.
982+ @param freq The frequency to set the oscillator to.
983+ */
984+ void tMBTriangle_setFreq (tMBTriangle* const osc, float freq);
985+
986+ void tMBTriangle_setSkew (tMBTriangle* const osc, float skew);
987+
988+ void tMBTriangle_sync (tMBTriangle* const osc, float phase);
989+
990+ /*! @} */
991+
992+ //==============================================================================
993+
994+ /* tMBPulse: Anti-aliased Square waveform. */
995+ typedef struct _tMBPulse
996+ {
997+ float phase;
998+ float inc,freq;
999+ float width;
1000+
1001+ tMinBLEP minBlep;
1002+ tHighpass dcBlock;
1003+ } _tMBPulse;
1004+
1005+ typedef _tMBPulse* tMBPulse;
1006+
1007+ /*!
1008+ * @defgroup tMBPulse tMBPulse
1009+ * @ingroup oscillators
1010+ * @brief An anti-aliased pulse waveform oscillator with changeable pulse width.
1011+ * @{
1012+ */
1013+
1014+ //! Initialize a tMBPulse to the default LEAF mempool.
1015+ /*!
1016+ @param osc A pointer to the tMBPulse to be initialized.
1017+ */
1018+ void tMBPulse_init (tMBPulse* const osc);
1019+
1020+
1021+ //! Free a tMBPulse from the default LEAF mempool.
1022+ /*!
1023+ @param osc A pointer to the tMBPulse to be freed.
1024+ */
1025+ void tMBPulse_free (tMBPulse* const osc);
1026+
1027+
1028+ //! Initialize a tMBPulse to a specified mempool.
1029+ /*!
1030+ @param osc A pointer to the tMBPulse to be initialized.
1031+ @param pool A pointer to the tMempool to which the tMBPulse should be initialized.
1032+ */
1033+ void tMBPulse_initToPool (tMBPulse* const osc, tMempool* const);
1034+
1035+
1036+ //! Free a tMBPulse from a specified mempool.
1037+ /*!
1038+ @param osc A pointer to the tMBPulse to be freed.
1039+ @param pool A pointer to the tMempool from which the tMBPulse should be freed.
1040+ */
1041+ void tMBPulse_freeFromPool(tMBPulse* const osc, tMempool* const);
1042+
1043+
1044+ //! Tick a tMBPulse oscillator.
1045+ /*!
1046+ @param osc A pointer to the relevant tMBPulse.
1047+ @return The ticked sample as a float from -1 to 1.
1048+ */
1049+ float tMBPulse_tick (tMBPulse* const osc);
1050+
1051+
1052+ //! Set the frequency of a tMBPulse oscillator.
1053+ /*!
1054+ @param osc A pointer to the relevant tMBPulse.
1055+ @param freq The frequency to set the oscillator to.
1056+ */
1057+ void tMBPulse_setFreq (tMBPulse* const osc, float freq);
1058+
1059+ void tMBPulse_setWidth (tMBPulse* const osc, float width);
1060+
1061+ void tMBPulse_sync (tMBPulse* const osc, float phase);
1062+
1063+
1064+ /*! @} */
1065+
1066+ //==============================================================================
1067+
1068+ /* tMBSawtooth: Anti-aliased Sawtooth waveform. */
1069+ typedef struct _tMBSaw
1070+ {
1071+ float phase;
1072+ float inc,freq;
1073+
1074+ tMinBLEP minBlep;
1075+ tHighpass dcBlock;
1076+ } _tMBSaw;
1077+
1078+ typedef _tMBSaw* tMBSaw;
1079+
1080+ /*!
1081+ * @defgroup tMBSaw tMBSaw
1082+ * @ingroup oscillators
1083+ * @brief An anti-aliased sawtooth waveform oscillator. Uses wavetable synthesis.
1084+ * @{
1085+ */
1086+
1087+ //! Initialize a tMBSaw to the default LEAF mempool.
1088+ /*!
1089+ @param osc A pointer to the tMBSaw to be initialized.
1090+ */
1091+ void tMBSaw_init (tMBSaw* const osc);
1092+
1093+
1094+ //! Free a tMBSaw from the default LEAF mempool.
1095+ /*!
1096+ @param osc A pointer to the tMBSaw to be freed.
1097+ */
1098+ void tMBSaw_free (tMBSaw* const osc);
1099+
1100+
1101+ //! Initialize a tMBSaw to a specified mempool.
1102+ /*!
1103+ @param osc A pointer to the tMBSaw to be initialized.
1104+ @param pool A pointer to the tMempool to which the tMBSaw should be initialized.
1105+ */
1106+ void tMBSaw_initToPool (tMBSaw* const osc, tMempool* const pool);
1107+
1108+
1109+ //! Free a tMBSaw from a specified mempool.
1110+ /*!
1111+ @param osc A pointer to the tMBSaw to be freed.
1112+ @param pool A pointer to the tMempool from which the tMBSaw should be freed.
1113+ */
1114+ void tMBSaw_freeFromPool (tMBSaw* const osc, tMempool* const pool);
1115+
1116+
1117+ //! Tick a tMBSaw oscillator.
1118+ /*!
1119+ @param osc A pointer to the relevant tMBSaw.
1120+ @return The ticked sample as a float from -1 to 1.
1121+ */
1122+ float tMBSaw_tick (tMBSaw* const osc);
1123+
1124+
1125+ //! Set the frequency of a tMBSaw oscillator.
1126+ /*!
1127+ @param osc A pointer to the relevant tMBSaw.
1128+ @param freq The frequency to set the oscillator to.
1129+ */
1130+ void tMBSaw_setFreq (tMBSaw* const osc, float freq);
1131+
1132+ void tMBSaw_sync (tMBSaw* const osc, float phase);
1133+
1134+ /*! @} */
1135+
9181136 #ifdef __cplusplus
9191137 }
9201138 #endif
LEAF/Inc/leaf-sampling.h+1−3
@@ -139,9 +139,7 @@ extern "C" { · 138 unmodified lines
139139 void tSampler_setEnd (tSampler* const, int32_t end);
140140 void tSampler_setLength (tSampler* const, int32_t length);
141141
142− static void handleStartEndChange (tSampler* const sp);
143−
144− void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length);
142+ void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length);
145143
146144 void tSampler_setRate (tSampler* const, float rate);
147145
LEAF/Src/leaf-effects.c+3−3
@@ -622,20 +622,20 @@ float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const gp) · 621 unmodified lines
622622 return output;
623623 }
624624
625−float tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const gp, float freq)
625+void tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const gp, float freq)
626626 {
627627 _tRosenbergGlottalPulse* g = *gp;
628628 g->freq = freq;
629629 g->inc = freq * leaf.invSampleRate;
630630 }
631631
632−float tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const gp, float openLength)
632+void tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const gp, float openLength)
633633 {
634634 _tRosenbergGlottalPulse* g = *gp;
635635 g->openLength = openLength;
636636 }
637637
638−float tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const gp, float pulseLength)
638+void tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const gp, float pulseLength)
639639 {
640640 _tRosenbergGlottalPulse* g = *gp;
641641 g->pulseLength = pulseLength;
LEAF/Src/leaf-filters.c+22−22
@@ -17,7 +17,7 @@ · 16 unmodified lines
1717 #include "../Inc/leaf-filters.h"
1818 #include "../Inc/leaf-tables.h"
1919 #include "../leaf.h"
20−#include "tim.h"
20+//#include "tim.h"
2121 #endif
2222
2323 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
@@ -1728,24 +1728,24 @@ float tDiodeFilter_tick (tDiodeFilter* const vf, float in) · 1704 unmodified lines
17281728
17291729 // This formula gives the result for y3 thanks to MATLAB
17301730 float y3 = (f->s2 + f->s3 + t2*(f->s1 + f->s2 + f->s3 + t1*(f->s0 + f->s1 + f->s2 + f->s3 + t0*in)) + t1*(2.0f*f->s2 + 2.0f*f->s3))*t3 + f->s3 + 2.0f*f->s3*t1 + t2*(2.0f*f->s3 + 3.0f*f->s3*t1);
1731− if (isnan(y3))
1732− {
1733− __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1734− }
1731+// if (isnan(y3))
1732+// {
1733+// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1734+// }
17351735 float tempy3denom = (t4 + t1*(2.0f*t4 + 4.0f) + t2*(t4 + t1*(t4 + f->r*t0 + 4.0f) + 3.0f) + 2.0f)*t3 + t4 + t1*(2.0f*t4 + 2.0f) + t2*(2.0f*t4 + t1*(3.0f*t4 + 3.0f) + 2.0f) + 1.0f;
1736− if (isnan(tempy3denom))
1737− {
1738− __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1739− }
1736+// if (isnan(tempy3denom))
1737+// {
1738+// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1739+// }
17401740 if (tempy3denom == 0.0f)
17411741 {
17421742 tempy3denom = 0.000001f;
17431743 }
17441744 y3 = y3 / tempy3denom;
1745− if (isnan(y3))
1746− {
1747− __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1748− }
1745+// if (isnan(y3))
1746+// {
1747+// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1748+// }
17491749 if (t1 == 0.0f)
17501750 {
17511751 t1 = 0.000001f;
@@ -1766,15 +1766,15 @@ float tDiodeFilter_tick (tDiodeFilter* const vf, float in) · 14 unmodified lines
17661766
17671767 // update state
17681768 f->s0 += 2.0f * (t0*xx + t1*(y1-y0));
1769− if (isnan(f->s0))
1770− {
1771− __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1772− }
1773−
1774− if (isinf(f->s0))
1775− {
1776− __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1777− }
1769+// if (isnan(f->s0))
1770+// {
1771+// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1772+// }
1773+
1774+// if (isinf(f->s0))
1775+// {
1776+// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1777+// }
17781778 f->s1 += 2.0f * (t2*(y2-y1) - t1*(y1-y0));
17791779 f->s2 += 2.0f * (t3*(y3-y2) - t2*(y2-y1));
17801780 f->s3 += 2.0f * (-t4*(y3) - t3*(y3-y2));
LEAF/Src/leaf-oscillators.c+307−9
@@ -925,9 +925,9 @@ void tNeuron_setCurrent (tNeuron* const nr, float current) · 924 unmodified lines
925925
926926
927927
928−void tMinBLEP_init (tMinBLEP* const minblep)
928+void tMinBLEP_init (tMinBLEP* const minblep, int zeroCrossings, int oversamplerRatio)
929929 {
930− tMinBLEP_initToPool(minblep, &leaf.mempool);
930+ tMinBLEP_initToPool(minblep, zeroCrossings, oversamplerRatio, &leaf.mempool);
931931 }
932932
933933 void tMinBLEP_free (tMinBLEP* const minblep)
@@ -935,15 +935,15 @@ void tMinBLEP_free (tMinBLEP* const minblep) · 1 unmodified line
935935 tMinBLEP_freeFromPool(minblep, &leaf.mempool);
936936 }
937937
938−void tMinBLEP_initToPool (tMinBLEP* const minblep, tMempool* const mp)
938+void tMinBLEP_initToPool (tMinBLEP* const minblep, int zeroCrossings, int oversamplerRatio, tMempool* const mp)
939939 {
940940 _tMempool* m = *mp;
941941 _tMinBLEP* mb = *minblep = (_tMinBLEP*) mpool_alloc(sizeof(_tMinBLEP), m);
942942
943− mb->overSamplingRatio = 64;
944− mb->zeroCrossings = 32;
943+ mb->overSamplingRatio = zeroCrossings;
944+ mb->zeroCrossings = oversamplerRatio;
945945 mb->returnDerivative = 0;
946− mb->proportionalBlepFreq = 0.5; // defaults to NyQuist ....
946+ mb->proportionalBlepFreq = (float) mb->zeroCrossings / (float) mb->overSamplingRatio; // defaults to NyQuist ....
947947
948948 mb->lastValue = 0;
949949 mb->lastDelta = 0;
@@ -963,8 +963,10 @@ void tMinBLEP_initToPool (tMinBLEP* const minblep, tMempool* const mp) · 13 unmodified lines
963963 mb->blepIndex = 0;
964964 mb->numActiveBleps = 0;
965965 //currentActiveBlepOffsets;
966+
967+ // These probably don't need to be this large
966968 mb->offset = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);
967− mb->freqMultiple = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);
969+// mb->freqMultiple = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);
968970 mb->pos_change_magnitude = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);
969971 mb->vel_change_magnitude = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);
970972
@@ -979,6 +981,13 @@ void tMinBLEP_freeFromPool (tMinBLEP* const minblep, tMempool* const mp) · 8 unmodified lines
979981 _tMempool* m = *mp;
980982 _tMinBLEP* mb = *minblep;
981983
984+ mpool_free(mb->offset, m);
985+// mpool_free(mb->freqMultiple, m);
986+ mpool_free(mb->pos_change_magnitude, m);
987+ mpool_free(mb->vel_change_magnitude, m);
988+
989+ mpool_free(mb->minBlepArray, m);
990+ mpool_free(mb->minBlepDerivArray, m);
982991
983992 mpool_free(mb, m);
984993 }
@@ -1236,7 +1245,7 @@ void tMinBLEP_addBLEP (tMinBLEP* const minblep, float offset, float po · 251 unmodified lines
12361245 int n = m->minBlepSize;
12371246
12381247 m->offset[m->blepIndex] = offset;
1239− m->freqMultiple[m->blepIndex] = m->overSamplingRatio*m->proportionalBlepFreq;
1248+// m->freqMultiple[m->blepIndex] = m->overSamplingRatio*m->proportionalBlepFreq;
12401249 m->pos_change_magnitude[m->blepIndex] = posChange;
12411250 m->vel_change_magnitude[m->blepIndex] = velChange;
12421251
@@ -1259,7 +1268,7 @@ float tMinBLEP_tick (tMinBLEP* const minblep, float input) · 16 unmodified lines
12591268 for (int blep = 1; blep <= m->numActiveBleps; blep++)
12601269 {
12611270 int i = (m->blepIndex - blep + n) % n;
1262− float adjusted_Freq = m->freqMultiple[i];
1271+ float adjusted_Freq = m->overSamplingRatio*m->proportionalBlepFreq;//m->freqMultiple[i];
12631272 float exactPosition = m->offset[i];
12641273
12651274 double blepPosExact = adjusted_Freq*(exactPosition + 1); // +1 because this needs to trigger on the LOW SAMPLE
@@ -1337,3 +1346,292 @@ float tMinBLEP_tick (tMinBLEP* const minblep, float input) · 71 unmodified lines
13371346 }
13381347 return sample;
13391348 }
1349+
1350+//==============================================================================
1351+
1352+/* tMBTriangle: Anti-aliased Triangle waveform. */
1353+void tMBTriangle_init (tMBTriangle* const osc)
1354+{
1355+ tMBTriangle_initToPool(osc, &leaf.mempool);
1356+}
1357+
1358+void tMBTriangle_free (tMBTriangle* const osc)
1359+{
1360+ tMBTriangle_freeFromPool(osc, &leaf.mempool);
1361+}
1362+
1363+void tMBTriangle_initToPool (tMBTriangle* const osc, tMempool* const mp)
1364+{
1365+ _tMempool* m = *mp;
1366+ _tMBTriangle* c = *osc = (_tMBTriangle*) mpool_alloc(sizeof(_tMBTriangle), m);
1367+
1368+ c->inc = 0.0f;
1369+ c->phase = 0.0f;
1370+ c->skew = 0.5f;
1371+ c->lastOut = 0.0f;
1372+
1373+ tMinBLEP_initToPool(&c->minBlep, 16, 32, mp);
1374+ tHighpass_initToPool(&c->dcBlock, 10.0f, mp);
1375+}
1376+
1377+void tMBTriangle_freeFromPool (tMBTriangle* const cy, tMempool* const mp)
1378+{
1379+ _tMempool* m = *mp;
1380+ _tMBTriangle* c = *cy;
1381+
1382+ tMinBLEP_freeFromPool(&c->minBlep, mp);
1383+ tHighpass_freeFromPool(&c->dcBlock, mp);
1384+
1385+ mpool_free(c, m);
1386+}
1387+
1388+float tMBTriangle_tick (tMBTriangle* const osc)
1389+{
1390+ _tMBTriangle* c = *osc;
1391+
1392+ float out;
1393+
1394+ c->phase += c->inc;
1395+ if (c->phase >= 1.0f)
1396+ {
1397+ c->phase -= 1.0f;
1398+ float offset = 1.0f - ((c->inc - c->phase) / c->inc);
1399+ tMinBLEP_addBLEP(&c->minBlep, offset, -2, 0.0f);
1400+ }
1401+ if (c->skew <= c->phase && c->phase < c->skew + c->inc)
1402+ {
1403+ float offset = 1.0f - ((c->inc - c->phase + c->skew) / c->inc);
1404+ tMinBLEP_addBLEP(&c->minBlep, offset, 2, 0.0f);
1405+ }
1406+
1407+ if (c->phase < c->skew)
1408+ {
1409+ out = (1.0f - c->skew) * 2.0f;
1410+ }
1411+ else
1412+ {
1413+ out = -c->skew * 2.0f;
1414+ }
1415+
1416+ out = tHighpass_tick(&c->dcBlock, tMinBLEP_tick(&c->minBlep, out));// - phasor->inc * 2.0f;
1417+
1418+// out = tMinBLEP_tick(&c->minBlep, out) - c->inc * 2.0f;
1419+
1420+ out = (c->inc * out) + ((1 - c->inc) * c->lastOut);
1421+ c->lastOut = out;
1422+
1423+ return out;
1424+}
1425+
1426+void tMBTriangle_setFreq (tMBTriangle* const osc, float freq)
1427+{
1428+ _tMBTriangle* c = *osc;
1429+
1430+ c->freq = freq;
1431+ c->inc = freq * leaf.invSampleRate;
1432+
1433+// tHighpass_setFreq(&c->dcBlock, freq*0.5);
1434+}
1435+
1436+void tMBTriangle_setSkew (tMBTriangle* const osc, float skew)
1437+{
1438+ _tMBTriangle* c = *osc;
1439+ c->skew = (skew + 1.0f) * 0.5f;
1440+}
1441+
1442+void tMBTriangle_sync (tMBTriangle* const osc, float phase)
1443+{
1444+ _tMBTriangle* c = *osc;
1445+ LEAF_clip(0.0f, phase, 1.0f);
1446+
1447+ float last, next;
1448+
1449+ if (c->phase < c->skew) last = (1.0f - c->skew - c->phase) * 2.0f;
1450+ else last = -(c->phase - c->skew) * 2.0f;
1451+
1452+ if (phase < c->skew) next = (1.0f - c->skew - phase) * 2.0f;
1453+ else next = -(phase - c->skew) * 2.0f;
1454+
1455+ c->phase = phase;
1456+
1457+ float offset = 1.0f - ((c->inc - c->phase) / c->inc);
1458+ tMinBLEP_addBLEP(&c->minBlep, offset, last - next, 0.0f);
1459+
1460+// c->lastOut = 0.0f;
1461+}
1462+
1463+//==============================================================================
1464+
1465+/* tMBPulse: Anti-aliased pulse waveform. */
1466+void tMBPulse_init (tMBPulse* const osc)
1467+{
1468+ tMBPulse_initToPool(osc, &leaf.mempool);
1469+}
1470+
1471+void tMBPulse_free (tMBPulse* const osc)
1472+{
1473+ tMBPulse_freeFromPool(osc, &leaf.mempool);
1474+}
1475+
1476+void tMBPulse_initToPool (tMBPulse* const osc, tMempool* const mp)
1477+{
1478+ _tMempool* m = *mp;
1479+ _tMBPulse* c = *osc = (_tMBPulse*) mpool_alloc(sizeof(_tMBPulse), m);
1480+
1481+ c->inc = 0.0f;
1482+ c->phase = 0.0f;
1483+ c->width = 0.5f;
1484+
1485+ tMinBLEP_initToPool(&c->minBlep, 16, 32, mp);
1486+ tHighpass_initToPool(&c->dcBlock, 10.0f, mp);
1487+}
1488+
1489+void tMBPulse_freeFromPool(tMBPulse* const osc, tMempool* const mp)
1490+{
1491+ _tMempool* m = *mp;
1492+ _tMBPulse* c = *osc;
1493+
1494+ tMinBLEP_freeFromPool(&c->minBlep, mp);
1495+ tHighpass_freeFromPool(&c->dcBlock, mp);
1496+
1497+ mpool_free(c, m);
1498+}
1499+
1500+float tMBPulse_tick (tMBPulse* const osc)
1501+{
1502+ _tMBPulse* c = *osc;
1503+
1504+
1505+
1506+ c->phase += c->inc;
1507+ if (c->phase >= 1.0f)
1508+ {
1509+ c->phase -= 1.0f;
1510+ float offset = 1.0f - ((c->inc - c->phase) / c->inc);
1511+ tMinBLEP_addBLEP(&c->minBlep, offset, -2, 0.0f);
1512+ }
1513+ if (c->width <= c->phase && c->phase < c->width + c->inc)
1514+ {
1515+ float offset = 1.0f - ((c->inc - c->phase + c->width) / c->inc);
1516+ tMinBLEP_addBLEP(&c->minBlep, offset, 2, 0.0f);
1517+ }
1518+
1519+ float out;
1520+ if (c->phase < c->width) out = 1.0f;
1521+ else out = -1.0f;
1522+
1523+ return tHighpass_tick(&c->dcBlock, tMinBLEP_tick(&c->minBlep, out));// - phasor->inc * 2.0f;
1524+
1525+
1526+
1527+ return out;
1528+}
1529+
1530+void tMBPulse_setFreq (tMBPulse* const osc, float freq)
1531+{
1532+ _tMBPulse* c = *osc;
1533+
1534+ c->freq = freq;
1535+ c->inc = freq * leaf.invSampleRate;
1536+}
1537+
1538+void tMBPulse_setWidth (tMBPulse* const osc, float width)
1539+{
1540+ _tMBPulse* c = *osc;
1541+ c->width = width;
1542+}
1543+
1544+void tMBPulse_sync (tMBPulse* const osc, float phase)
1545+{
1546+ _tMBPulse* c = *osc;
1547+ LEAF_clip(0.0f, phase, 1.0f);
1548+
1549+ float last, next;
1550+
1551+ if (c->phase < c->width) last = 1.0f;
1552+ else last = -1.0f;
1553+
1554+ if (phase < c->width) next = 1.0;
1555+ else next = -1.0f;
1556+
1557+ c->phase = phase;
1558+
1559+ float offset = 1.0f - ((c->inc - c->phase) / c->inc);
1560+ tMinBLEP_addBLEP(&c->minBlep, offset, last - next, 0.0f);
1561+}
1562+
1563+
1564+//==============================================================================
1565+
1566+/* tMBSawtooth: Anti-aliased Sawtooth waveform. */
1567+void tMBSaw_init (tMBSaw* const osc)
1568+{
1569+ tMBSaw_initToPool(osc, &leaf.mempool);
1570+}
1571+
1572+void tMBSaw_free (tMBSaw* const osc)
1573+{
1574+ tMBSaw_freeFromPool(osc, &leaf.mempool);
1575+}
1576+
1577+void tMBSaw_initToPool (tMBSaw* const osc, tMempool* const mp)
1578+{
1579+ _tMempool* m = *mp;
1580+ _tMBSaw* c = *osc = (_tMBSaw*) mpool_alloc(sizeof(_tMBSaw), m);
1581+
1582+ c->inc = 0.0f;
1583+ c->phase = 0.0f;
1584+
1585+ tMinBLEP_initToPool(&c->minBlep, 16, 32, mp);
1586+ tHighpass_initToPool(&c->dcBlock, 10.0f, mp);
1587+}
1588+
1589+void tMBSaw_freeFromPool (tMBSaw* const osc, tMempool* const mp)
1590+{
1591+ _tMempool* m = *mp;
1592+ _tMBSaw* c = *osc;
1593+
1594+ tMinBLEP_freeFromPool(&c->minBlep, mp);
1595+ tHighpass_freeFromPool(&c->dcBlock, mp);
1596+
1597+ mpool_free(c, m);
1598+}
1599+
1600+float tMBSaw_tick (tMBSaw* const osc)
1601+{
1602+ _tMBSaw* c = *osc;
1603+
1604+ c->phase += c->inc;
1605+ if (c->phase >= 1.0f)
1606+ {
1607+ c->phase -= 1.0f;
1608+ float offset = 1.0f - ((c->inc - c->phase) / c->inc);
1609+ tMinBLEP_addBLEP(&c->minBlep, offset, 2, 0.0f);
1610+ }
1611+
1612+ float out = (c->phase * 2.0f) - 1.0f;
1613+
1614+ return tHighpass_tick(&c->dcBlock, tMinBLEP_tick(&c->minBlep, out));// - phasor->inc * 2.0f;
1615+
1616+// return tMinBLEP_tick(&c->minBlep, out) - c->inc * 2.0f;
1617+}
1618+
1619+void tMBSaw_setFreq (tMBSaw* const osc, float freq)
1620+{
1621+ _tMBSaw* c = *osc;
1622+
1623+ c->freq = freq;
1624+
1625+ c->inc = freq * leaf.invSampleRate;
1626+}
1627+
1628+void tMBSaw_sync (tMBSaw* const osc, float phase)
1629+{
1630+ _tMBSaw* c = *osc;
1631+ LEAF_clip(0.0f, phase, 1.0f);
1632+
1633+ float offset = 1.0f - ((c->inc - phase) / c->inc);
1634+ tMinBLEP_addBLEP(&c->minBlep, offset, c->phase * 2.0f, 0.0f);
1635+
1636+ c->phase = phase;
1637+}
LEAF/Src/leaf-sampling.c+4−4
@@ -609,7 +609,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 608 unmodified lines
609609 if (start > p->idx)// start given is after current index or we're in a crossfade
610610 {
611611 p->targetstart = start;
612− float tempLen = fabs(p->end - start) * 0.25f;
612+ float tempLen = abs(p->end - start) * 0.25f;
613613 if (cfxlen > tempLen)
614614 {
615615 p->cfxlen = tempLen;
@@ -622,7 +622,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 6 unmodified lines
622622 if (start < p->idx)// start given is before current index or we're in a crossfade
623623 {
624624 p->targetstart = start;
625− float tempLen = fabs(p->end - start) * 0.25f;
625+ float tempLen = abs(p->end - start) * 0.25f;
626626 if (cfxlen > tempLen)
627627 {
628628 p->cfxlen = tempLen;
@@ -680,7 +680,7 @@ void tSampler_setEnd (tSampler* const sp, int32_t end) · 51 unmodified lines
680680 if (end < p->idx) // end given is before current index or we're in a crossfade
681681 {
682682 p->targetend = end;
683− float tempLen = fabs(end - p->start) * 0.25f;
683+ float tempLen = abs(end - p->start) * 0.25f;
684684 if (cfxlen > tempLen)
685685 {
686686 p->cfxlen = tempLen;
@@ -693,7 +693,7 @@ void tSampler_setEnd (tSampler* const sp, int32_t end) · 6 unmodified lines
693693 if (end > p->idx) // end given is after current index or we're in a crossfade
694694 {
695695 p->targetend = end;
696− float tempLen = fabs(end - p->start) * 0.25f;
696+ float tempLen = abs(end - p->start) * 0.25f;
697697 if (cfxlen > tempLen)
698698 {
699699 p->cfxlen = tempLen;
LEAF_JUCEPlugin/Source/MyTest.cpp+19−42
@@ -25,12 +25,17 @@ tEnvelope env; · 24 unmodified lines
2525
2626 tAutotune at;
2727
28−tTriangle tri;
2928
3029 tMinBLEP minblep;
3130
3231 tPhasor phasor;
3332
33+tHighpass hipass;
34+
35+tMBSaw saw;
36+tMBPulse pulse;
37+tMBTriangle tri;
38+
3439 float gain;
3540 float freq;
3641 float dtime;
@@ -47,28 +52,15 @@ void LEAFTest_init (float sampleRate, int blockSize) · 10 unmodified lines
4752 {
4853 LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
4954
50− tTriangle_init(&tri);
55+ tMBSaw_init(&saw);
5156
52− tMinBLEP_init(&minblep);
57+ tMBPulse_init(&pulse);
58+
59+ tMBTriangle_init(&tri);
5360
5461 tPhasor_init(&phasor);
55− // tNoise_init(&noise, WhiteNoise);
56− //
57− // tAutotune_init(&at, 1, 1024, 512);
5862
59− // tSVF_init(&bp1, SVFTypeBandpass, 100, 4.0f);
60− // tSVF_init(&bp2, SVFTypeBandpass, 1000, 4.0f);
61− //
62− // tFormantShifter_init(&fs, 20);
63− //
64− // // Init and set record
65− // tBuffer_init (&buff, leaf.sampleRate); // init, 1 second buffer
66− // tBuffer_setRecordMode (&buff, RecordOneShot); // RecordOneShot records once through
67− //
68− // // Init and set play
69− // tSampler_init (&samp, &buff); // init, give address of record buffer
70− // tSampler_setMode (&samp, PlayLoop); //set in Loop Mode
71− // tSampler_setRate(&samp, 1.763f); // Rate of 1.0
63+ tPhasor_setFreq(&phasor, 2000);
7264 }
7365
7466 inline double getSawFall(double angle) {
@@ -82,33 +74,18 @@ inline double getSawFall(double angle) { · 7 unmodified lines
8274
8375 float LEAFTest_tick (float input)
8476 {
85− // float sample = tNoise_tick(&noise);
86− // sample *= 0.5f;
87− // float b = tSVF_tick(&bp1, sample);
88− // b += tSVF_tick(&bp2, sample);
89− //
90− // return (tFormantShifter_tick(&fs, input));
91− //
92− // tBuffer_tick(&buff, input);
93−
94− // return tSampler_tick(&samp);
95−
96− // tAutotune_setFreq(&at, 440.0f, 0);
97−
98− // return tAutotune_tick(&at, input)[0];
9977
100− tPhasor_setFreq(&phasor, y);
78+ tMBSaw_setFreq(&saw, y);
79+ tMBPulse_setWidth(&pulse, x);
80+ tMBPulse_setFreq(&pulse, y);
81+ tMBTriangle_setSkew(&tri, x*2.0f - 1.0f);
82+ tMBTriangle_setFreq(&tri, y);
10183
84+ tPhasor_tick(&phasor);
10285
103− float sample = tPhasor_tick(&phasor) * 2.0f - 1.0f;
104−
105− if (phasor->phaseDidReset)
106− {
107− float offset = 1.0f - ((phasor->inc - phasor->phase) / phasor->inc);
108− tMinBLEP_addBLEP(&minblep, offset, 2, 0.0f);
109− }
86+// if (phasor->phaseDidReset) tMBSaw_sync(&saw, 0.0f);
11087
111− return tMinBLEP_tick(&minblep, sample) - phasor->inc * 2.0f;
88+ return tMBSaw_tick(&saw);// - phasor->inc * 2.0f;
11289 }
11390
11491 int firstFrame = 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t