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
130 130
131 float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const);131 float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const);
132 132
133 float tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const, float freq);133 void tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const, float freq);
134 134
135 float tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const, float openLength);135 void tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const, float openLength);
136 136
137 float tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const, float pulseLength);137 void tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const, float pulseLength);
138 138
139 //==============================================================================139 //==============================================================================
140 140
LEAF/Inc/leaf-oscillators.h+220−2
@@ -902,9 +902,9 @@ extern "C" { · 901 unmodified lines
902 902
903 typedef _tMinBLEP* tMinBLEP;903 typedef _tMinBLEP* tMinBLEP;
904 904
905 void tMinBLEP_init (tMinBLEP* const minblep);905 void tMinBLEP_init (tMinBLEP* const minblep, int zeroCrossings, int oversamplerRatio);
906 void tMinBLEP_free (tMinBLEP* const minblep);906 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);
908 void tMinBLEP_freeFromPool (tMinBLEP* const minblep, tMempool* const pool);908 void tMinBLEP_freeFromPool (tMinBLEP* const minblep, tMempool* const pool);
909 909
910 // pass in audio, identify discontinuities and return the audio with minbleps inserted910 // pass in audio, identify discontinuities and return the audio with minbleps inserted
@@ -915,6 +915,224 @@ extern "C" { · 4 unmodified lines
915 void tMinBLEP_setOversamplingRatio (tMinBLEP* const minblep, float ratio);915 void tMinBLEP_setOversamplingRatio (tMinBLEP* const minblep, float ratio);
916 void tMinBLEP_setNumZeroCrossings (tMinBLEP* const minblep, int numCrossings);916 void tMinBLEP_setNumZeroCrossings (tMinBLEP* const minblep, int numCrossings);
917 917
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
918#ifdef __cplusplus1136#ifdef __cplusplus
919}1137}
920#endif1138#endif
LEAF/Inc/leaf-sampling.h+1−3
@@ -139,9 +139,7 @@ extern "C" { · 138 unmodified lines
139 void tSampler_setEnd (tSampler* const, int32_t end);139 void tSampler_setEnd (tSampler* const, int32_t end);
140 void tSampler_setLength (tSampler* const, int32_t length);140 void tSampler_setLength (tSampler* const, int32_t length);
141 141
142 static void handleStartEndChange (tSampler* const sp);142 void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length);
143
144 void tSampler_setCrossfadeLength (tSampler* const sp, uint32_t length);
145 143
146 void tSampler_setRate (tSampler* const, float rate);144 void tSampler_setRate (tSampler* const, float rate);
147 145
LEAF/Src/leaf-effects.c+3−3
@@ -622,20 +622,20 @@ float tRosenbergGlottalPulse_tick (tRosenbergGlottalPulse* const gp) · 621 unmodified lines
622 return output;622 return output;
623}623}
624 624
625float tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const gp, float freq)625void tRosenbergGlottalPulse_setFreq (tRosenbergGlottalPulse* const gp, float freq)
626{626{
627 _tRosenbergGlottalPulse* g = *gp;627 _tRosenbergGlottalPulse* g = *gp;
628 g->freq = freq;628 g->freq = freq;
629 g->inc = freq * leaf.invSampleRate;629 g->inc = freq * leaf.invSampleRate;
630}630}
631 631
632float tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const gp, float openLength)632void tRosenbergGlottalPulse_setOpenLength (tRosenbergGlottalPulse* const gp, float openLength)
633{633{
634 _tRosenbergGlottalPulse* g = *gp;634 _tRosenbergGlottalPulse* g = *gp;
635 g->openLength = openLength;635 g->openLength = openLength;
636}636}
637 637
638float tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const gp, float pulseLength)638void tRosenbergGlottalPulse_setPulseLength (tRosenbergGlottalPulse* const gp, float pulseLength)
639{639{
640 _tRosenbergGlottalPulse* g = *gp;640 _tRosenbergGlottalPulse* g = *gp;
641 g->pulseLength = pulseLength;641 g->pulseLength = pulseLength;
LEAF/Src/leaf-filters.c+22−22
@@ -17,7 +17,7 @@ · 16 unmodified lines
17#include "../Inc/leaf-filters.h"17#include "../Inc/leaf-filters.h"
18#include "../Inc/leaf-tables.h"18#include "../Inc/leaf-tables.h"
19#include "../leaf.h"19#include "../leaf.h"
20#include "tim.h"20//#include "tim.h"
21#endif21#endif
22 22
23// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //23// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ OnePole Filter ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
@@ -1728,24 +1728,24 @@ float tDiodeFilter_tick (tDiodeFilter* const vf, float in) · 1704 unmodified lines
1728 1728
1729 // This formula gives the result for y3 thanks to MATLAB1729 // This formula gives the result for y3 thanks to MATLAB
1730 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);1730 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))1731// if (isnan(y3))
1732 {1732// {
1733 __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);1733// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1734 }1734// }
1735 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;1735 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))1736// if (isnan(tempy3denom))
1737 {1737// {
1738 __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);1738// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1739 }1739// }
1740 if (tempy3denom == 0.0f)1740 if (tempy3denom == 0.0f)
1741 {1741 {
1742 tempy3denom = 0.000001f;1742 tempy3denom = 0.000001f;
1743 }1743 }
1744 y3 = y3 / tempy3denom;1744 y3 = y3 / tempy3denom;
1745 if (isnan(y3))1745// if (isnan(y3))
1746 {1746// {
1747 __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);1747// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1748 }1748// }
1749 if (t1 == 0.0f)1749 if (t1 == 0.0f)
1750 {1750 {
1751 t1 = 0.000001f;1751 t1 = 0.000001f;
@@ -1766,15 +1766,15 @@ float tDiodeFilter_tick (tDiodeFilter* const vf, float in) · 14 unmodified lines
1766 1766
1767 // update state1767 // update state
1768 f->s0 += 2.0f * (t0*xx + t1*(y1-y0));1768 f->s0 += 2.0f * (t0*xx + t1*(y1-y0));
1769 if (isnan(f->s0))1769// if (isnan(f->s0))
1770 {1770// {
1771 __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);1771// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1772 }1772// }
1773 1773
1774 if (isinf(f->s0))1774// if (isinf(f->s0))
1775 {1775// {
1776 __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);1776// __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 400);
1777 }1777// }
1778 f->s1 += 2.0f * (t2*(y2-y1) - t1*(y1-y0));1778 f->s1 += 2.0f * (t2*(y2-y1) - t1*(y1-y0));
1779 f->s2 += 2.0f * (t3*(y3-y2) - t2*(y2-y1));1779 f->s2 += 2.0f * (t3*(y3-y2) - t2*(y2-y1));
1780 f->s3 += 2.0f * (-t4*(y3) - t3*(y3-y2));1780 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
925 925
926 926
927 927
928void tMinBLEP_init (tMinBLEP* const minblep)928void tMinBLEP_init (tMinBLEP* const minblep, int zeroCrossings, int oversamplerRatio)
929{929{
930 tMinBLEP_initToPool(minblep, &leaf.mempool);930 tMinBLEP_initToPool(minblep, zeroCrossings, oversamplerRatio, &leaf.mempool);
931}931}
932 932
933void tMinBLEP_free (tMinBLEP* const minblep)933void tMinBLEP_free (tMinBLEP* const minblep)
@@ -935,15 +935,15 @@ void tMinBLEP_free (tMinBLEP* const minblep) · 1 unmodified line
935 tMinBLEP_freeFromPool(minblep, &leaf.mempool);935 tMinBLEP_freeFromPool(minblep, &leaf.mempool);
936}936}
937 937
938void tMinBLEP_initToPool (tMinBLEP* const minblep, tMempool* const mp)938void tMinBLEP_initToPool (tMinBLEP* const minblep, int zeroCrossings, int oversamplerRatio, tMempool* const mp)
939{939{
940 _tMempool* m = *mp;940 _tMempool* m = *mp;
941 _tMinBLEP* mb = *minblep = (_tMinBLEP*) mpool_alloc(sizeof(_tMinBLEP), m);941 _tMinBLEP* mb = *minblep = (_tMinBLEP*) mpool_alloc(sizeof(_tMinBLEP), m);
942 942
943 mb->overSamplingRatio = 64;943 mb->overSamplingRatio = zeroCrossings;
944 mb->zeroCrossings = 32;944 mb->zeroCrossings = oversamplerRatio;
945 mb->returnDerivative = 0;945 mb->returnDerivative = 0;
946 mb->proportionalBlepFreq = 0.5; // defaults to NyQuist ....946 mb->proportionalBlepFreq = (float) mb->zeroCrossings / (float) mb->overSamplingRatio; // defaults to NyQuist ....
947 947
948 mb->lastValue = 0;948 mb->lastValue = 0;
949 mb->lastDelta = 0;949 mb->lastDelta = 0;
@@ -963,8 +963,10 @@ void tMinBLEP_initToPool (tMinBLEP* const minblep, tMempool* const mp) · 13 unmodified lines
963 mb->blepIndex = 0;963 mb->blepIndex = 0;
964 mb->numActiveBleps = 0;964 mb->numActiveBleps = 0;
965 //currentActiveBlepOffsets;965 //currentActiveBlepOffsets;
966
967 // These probably don't need to be this large
966 mb->offset = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);968 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);
968 mb->pos_change_magnitude = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);970 mb->pos_change_magnitude = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);
969 mb->vel_change_magnitude = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);971 mb->vel_change_magnitude = (float*) mpool_alloc(sizeof(float) * mb->minBlepSize, m);
970 972
@@ -979,6 +981,13 @@ void tMinBLEP_freeFromPool (tMinBLEP* const minblep, tMempool* const mp) · 8 unmodified lines
979 _tMempool* m = *mp;981 _tMempool* m = *mp;
980 _tMinBLEP* mb = *minblep;982 _tMinBLEP* mb = *minblep;
981 983
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);
982 991
983 mpool_free(mb, m);992 mpool_free(mb, m);
984}993}
@@ -1236,7 +1245,7 @@ void tMinBLEP_addBLEP (tMinBLEP* const minblep, float offset, float po · 251 unmodified lines
1236 int n = m->minBlepSize;1245 int n = m->minBlepSize;
1237 1246
1238 m->offset[m->blepIndex] = offset;1247 m->offset[m->blepIndex] = offset;
1239 m->freqMultiple[m->blepIndex] = m->overSamplingRatio*m->proportionalBlepFreq;1248// m->freqMultiple[m->blepIndex] = m->overSamplingRatio*m->proportionalBlepFreq;
1240 m->pos_change_magnitude[m->blepIndex] = posChange;1249 m->pos_change_magnitude[m->blepIndex] = posChange;
1241 m->vel_change_magnitude[m->blepIndex] = velChange;1250 m->vel_change_magnitude[m->blepIndex] = velChange;
1242 1251
@@ -1259,7 +1268,7 @@ float tMinBLEP_tick (tMinBLEP* const minblep, float input) · 16 unmodified lines
1259 for (int blep = 1; blep <= m->numActiveBleps; blep++)1268 for (int blep = 1; blep <= m->numActiveBleps; blep++)
1260 {1269 {
1261 int i = (m->blepIndex - blep + n) % n;1270 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];
1263 float exactPosition = m->offset[i];1272 float exactPosition = m->offset[i];
1264 1273
1265 double blepPosExact = adjusted_Freq*(exactPosition + 1); // +1 because this needs to trigger on the LOW SAMPLE1274 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
1337 }1346 }
1338 return sample;1347 return sample;
1339}1348}
1349
1350//==============================================================================
1351
1352/* tMBTriangle: Anti-aliased Triangle waveform. */
1353void tMBTriangle_init (tMBTriangle* const osc)
1354{
1355 tMBTriangle_initToPool(osc, &leaf.mempool);
1356}
1357
1358void tMBTriangle_free (tMBTriangle* const osc)
1359{
1360 tMBTriangle_freeFromPool(osc, &leaf.mempool);
1361}
1362
1363void 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
1377void 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
1388float 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
1426void 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
1436void tMBTriangle_setSkew (tMBTriangle* const osc, float skew)
1437{
1438 _tMBTriangle* c = *osc;
1439 c->skew = (skew + 1.0f) * 0.5f;
1440}
1441
1442void 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. */
1466void tMBPulse_init (tMBPulse* const osc)
1467{
1468 tMBPulse_initToPool(osc, &leaf.mempool);
1469}
1470
1471void tMBPulse_free (tMBPulse* const osc)
1472{
1473 tMBPulse_freeFromPool(osc, &leaf.mempool);
1474}
1475
1476void 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
1489void 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
1500float 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
1530void 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
1538void tMBPulse_setWidth (tMBPulse* const osc, float width)
1539{
1540 _tMBPulse* c = *osc;
1541 c->width = width;
1542}
1543
1544void 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. */
1567void tMBSaw_init (tMBSaw* const osc)
1568{
1569 tMBSaw_initToPool(osc, &leaf.mempool);
1570}
1571
1572void tMBSaw_free (tMBSaw* const osc)
1573{
1574 tMBSaw_freeFromPool(osc, &leaf.mempool);
1575}
1576
1577void 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
1589void 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
1600float 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
1619void 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
1628void 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
609 if (start > p->idx)// start given is after current index or we're in a crossfade609 if (start > p->idx)// start given is after current index or we're in a crossfade
610 {610 {
611 p->targetstart = start;611 p->targetstart = start;
612 float tempLen = fabs(p->end - start) * 0.25f;612 float tempLen = abs(p->end - start) * 0.25f;
613 if (cfxlen > tempLen)613 if (cfxlen > tempLen)
614 {614 {
615 p->cfxlen = tempLen;615 p->cfxlen = tempLen;
@@ -622,7 +622,7 @@ void tSampler_setStart (tSampler* const sp, int32_t start) · 6 unmodified lines
622 if (start < p->idx)// start given is before current index or we're in a crossfade622 if (start < p->idx)// start given is before current index or we're in a crossfade
623 {623 {
624 p->targetstart = start;624 p->targetstart = start;
625 float tempLen = fabs(p->end - start) * 0.25f;625 float tempLen = abs(p->end - start) * 0.25f;
626 if (cfxlen > tempLen)626 if (cfxlen > tempLen)
627 {627 {
628 p->cfxlen = tempLen;628 p->cfxlen = tempLen;
@@ -680,7 +680,7 @@ void tSampler_setEnd (tSampler* const sp, int32_t end) · 51 unmodified lines
680 if (end < p->idx) // end given is before current index or we're in a crossfade680 if (end < p->idx) // end given is before current index or we're in a crossfade
681 {681 {
682 p->targetend = end;682 p->targetend = end;
683 float tempLen = fabs(end - p->start) * 0.25f;683 float tempLen = abs(end - p->start) * 0.25f;
684 if (cfxlen > tempLen)684 if (cfxlen > tempLen)
685 {685 {
686 p->cfxlen = tempLen;686 p->cfxlen = tempLen;
@@ -693,7 +693,7 @@ void tSampler_setEnd (tSampler* const sp, int32_t end) · 6 unmodified lines
693 if (end > p->idx) // end given is after current index or we're in a crossfade693 if (end > p->idx) // end given is after current index or we're in a crossfade
694 {694 {
695 p->targetend = end;695 p->targetend = end;
696 float tempLen = fabs(end - p->start) * 0.25f;696 float tempLen = abs(end - p->start) * 0.25f;
697 if (cfxlen > tempLen)697 if (cfxlen > tempLen)
698 {698 {
699 p->cfxlen = tempLen;699 p->cfxlen = tempLen;
LEAF_JUCEPlugin/Source/MyTest.cpp+19−42
@@ -25,12 +25,17 @@ tEnvelope env; · 24 unmodified lines
25 25
26tAutotune at;26tAutotune at;
27 27
28tTriangle tri;
29 28
30tMinBLEP minblep;29tMinBLEP minblep;
31 30
32tPhasor phasor;31tPhasor phasor;
33 32
33tHighpass hipass;
34
35tMBSaw saw;
36tMBPulse pulse;
37tMBTriangle tri;
38
34float gain;39float gain;
35float freq;40float freq;
36float dtime;41float dtime;
@@ -47,28 +52,15 @@ void LEAFTest_init (float sampleRate, int blockSize) · 10 unmodified lines
47{52{
48 LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat);53 LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
49 54
50 tTriangle_init(&tri);55 tMBSaw_init(&saw);
51 56
52 tMinBLEP_init(&minblep);57 tMBPulse_init(&pulse);
58
59 tMBTriangle_init(&tri);
53 60
54 tPhasor_init(&phasor);61 tPhasor_init(&phasor);
55 // tNoise_init(&noise, WhiteNoise);
56 //
57 // tAutotune_init(&at, 1, 1024, 512);
58 62
59 // tSVF_init(&bp1, SVFTypeBandpass, 100, 4.0f);63 tPhasor_setFreq(&phasor, 2000);
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
72}64}
73 65
74inline double getSawFall(double angle) {66inline double getSawFall(double angle) {
@@ -82,33 +74,18 @@ inline double getSawFall(double angle) { · 7 unmodified lines
82 74
83float LEAFTest_tick (float input)75float LEAFTest_tick (float input)
84{76{
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];
99 77
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);
101 83
84 tPhasor_tick(&phasor);
102 85
103 float sample = tPhasor_tick(&phasor) * 2.0f - 1.0f;86// if (phasor->phaseDidReset) tMBSaw_sync(&saw, 0.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 }
110 87
111 return tMinBLEP_tick(&minblep, sample) - phasor->inc * 2.0f;88 return tMBSaw_tick(&saw);// - phasor->inc * 2.0f;
112}89}
113 90
114int firstFrame = 1;91int 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