History

Merge branch 'master' of github.com:spiricom/LEAF

Davis Polito committed 4 years ago

Commit df300322 parents 80fdd36 8acb64c5 files · +29 −55Browse files

Unified · Split

5 files
  1. leaf/Inc/leaf-oscillators.h +1 −3
  2. leaf/Src/leaf-analysis.c +1 −0
  3. leaf/Src/leaf-envelopes.c +5 −5
  4. leaf/Src/leaf-oscillators.c +20 −45
  5. leaf/Src/leaf-sampling.c +2 −2
leaf/Inc/leaf-oscillators.h+1−3
@@ -1472,10 +1472,8 @@ extern "C" { · 1471 unmodified lines
1472 tMempool mempool;1472 tMempool mempool;
1473 int32_t phase;1473 int32_t phase;
1474 int32_t inc;1474 int32_t inc;
1475 int32_t prevPhase;
1476 float freq;1475 float freq;
1477 uint8_t phaseDidReset;1476 float invSampleRate;
1478 uint32_t invSampleRate;
1479 float invSampleRateTimesTwoTo32;1477 float invSampleRateTimesTwoTo32;
1480 } _tTriLFO;1478 } _tTriLFO;
1481 1479
leaf/Src/leaf-analysis.c+1−0
@@ -1822,6 +1822,7 @@ static inline void sub_collector_init(_sub_collector* collector, tZeroCrossingCo · 1821 unmodified lines
1822 collector->_fundamental._period = -1;1822 collector->_fundamental._period = -1;
1823 collector->_fundamental._periodicity = 0.0f;1823 collector->_fundamental._periodicity = 0.0f;
1824 collector->_fundamental._harmonic = 0;1824 collector->_fundamental._harmonic = 0;
1825 collector->_first_period = 0.01f;
1825}1826}
1826 1827
1827static inline float sub_collector_period_of(_sub_collector* collector, _auto_correlation_info info)1828static inline float sub_collector_period_of(_sub_collector* collector, _auto_correlation_info info)
leaf/Src/leaf-envelopes.c+5−5
@@ -1316,8 +1316,8 @@ void tExpSmooth_initToPool (tExpSmooth* const expsmooth, float val, float f · 1315 unmodified lines
1316 1316
1317 smooth->curr = val;1317 smooth->curr = val;
1318 smooth->dest = val;1318 smooth->dest = val;
1319 if (factor < 0) factor = 0;1319 if (factor < 0.0f) factor = 0.0f;
1320 if (factor > 1) factor = 1;1320 if (factor > 1.0f) factor = 1.0f;
1321 smooth->baseFactor = factor;1321 smooth->baseFactor = factor;
1322 smooth->factor = factor;1322 smooth->factor = factor;
1323 smooth->oneminusfactor = 1.0f - factor;1323 smooth->oneminusfactor = 1.0f - factor;
@@ -1334,9 +1334,9 @@ void tExpSmooth_setFactor(tExpSmooth* const expsmooth, float factor) · 10 unmodified lines
1334{ // factor is usually a value between 0 and 0.1. Lower value is slower. 0.01 for example gives you a smoothing time of about 10ms1334{ // factor is usually a value between 0 and 0.1. Lower value is slower. 0.01 for example gives you a smoothing time of about 10ms
1335 _tExpSmooth* smooth = *expsmooth;1335 _tExpSmooth* smooth = *expsmooth;
1336 1336
1337 if (factor < 0)1337 if (factor < 0.0f)
1338 factor = 0;1338 factor = 0.0f;
1339 else if (factor > 1) factor = 1;1339 else if (factor > 1.0f) factor = 1.0f;
1340 smooth->baseFactor = factor;1340 smooth->baseFactor = factor;
1341 smooth->factor = powf(factor, 44100.f * smooth->invSampleRate);1341 smooth->factor = powf(factor, 44100.f * smooth->invSampleRate);
1342 smooth->oneminusfactor = 1.0f - factor;1342 smooth->oneminusfactor = 1.0f - factor;
leaf/Src/leaf-oscillators.c+20−45
@@ -1269,7 +1269,6 @@ float tMBTriangle_tick(tMBTriangle* const osc) · 1268 unmodified lines
1269 1269
1270 sync = c->sync;1270 sync = c->sync;
1271 1271
1272
1273 p = c->_p; /* phase [0, 1) */1272 p = c->_p; /* phase [0, 1) */
1274 w = c->_w; /* phase increment */1273 w = c->_w; /* phase increment */
1275 b = c->_b; /* duty cycle (0, 1) */1274 b = c->_b; /* duty cycle (0, 1) */
@@ -1482,6 +1481,7 @@ void tMBTriangle_setFreq(tMBTriangle* const osc, float f) · 206 unmodified lines
1482void tMBTriangle_setWidth(tMBTriangle* const osc, float w)1481void tMBTriangle_setWidth(tMBTriangle* const osc, float w)
1483{1482{
1484 _tMBTriangle* c = *osc;1483 _tMBTriangle* c = *osc;
1484 w = LEAF_clip(0.0f, w, 0.99f);
1485 c->waveform = w;1485 c->waveform = w;
1486}1486}
1487 1487
@@ -1846,10 +1846,13 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 358 unmodified lines
1846 }1846 }
1847 1847
1848 1848
1849 /* now place reset DD for pulse */1849
1850 if (sw > 0)1850 if (sw > 0)
1851 {1851 {
1852 if (k) {1852 /* now place reset DD for saw*/
1853 place_step_dd(c->_f, j, p, sw, p_at_reset * sawShape);
1854 /* now place reset DD for pulse */
1855 if (k) {
1853 place_step_dd(c->_f, j, p, sw, 1.0f * shape);1856 place_step_dd(c->_f, j, p, sw, 1.0f * shape);
1854 k = 0;1857 k = 0;
1855 x = 0.5f;1858 x = 0.5f;
@@ -1862,6 +1865,9 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 6 unmodified lines
1862 }1865 }
1863 else if (sw < 0)1866 else if (sw < 0)
1864 {1867 {
1868 /* now place reset DD for saw*/
1869 place_step_dd(c->_f, j, 1.0f - p, -sw, -p_at_reset * sawShape);
1870 /* now place reset DD for pulse */
1865 if (!k) {1871 if (!k) {
1866 place_step_dd(c->_f, j, 1.0f - p, -sw, -1.0f * shape);1872 place_step_dd(c->_f, j, 1.0f - p, -sw, -1.0f * shape);
1867 k = 1;1873 k = 1;
@@ -1873,11 +1879,7 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 5 unmodified lines
1873 x = 0.5f;1879 x = 0.5f;
1874 }1880 }
1875 }1881 }
1876 /* now place reset DD for saw*/1882
1877 if (sw > 0)
1878 place_step_dd(c->_f, j, p, sw, p_at_reset * sawShape);
1879 else if (sw < 0)
1880 place_step_dd(c->_f, j, 1.0f - p, -sw, -p_at_reset * sawShape);
1881 1883
1882 }1884 }
1883 1885
@@ -2835,7 +2837,6 @@ void tIntPhasor_initToPool (tIntPhasor* const cy, tMempool* const mp) · 951 unmodified lines
2835 2837
2836 c->phase = 0;2838 c->phase = 0;
2837 c->invSampleRateTimesTwoTo32 = (leaf->invSampleRate * TWO_TO_32);2839 c->invSampleRateTimesTwoTo32 = (leaf->invSampleRate * TWO_TO_32);
2838 c->mask = 0x7FFFFFFF;
2839}2840}
2840 2841
2841void tIntPhasor_free (tIntPhasor* const cy)2842void tIntPhasor_free (tIntPhasor* const cy)
@@ -2850,7 +2851,7 @@ float tIntPhasor_tick(tIntPhasor* const cy) · 8 unmodified lines
2850{2851{
2851 _tIntPhasor* c = *cy;2852 _tIntPhasor* c = *cy;
2852 // Phasor increment2853 // Phasor increment
2853 c->phase = (c->phase + c->inc);//& c->mask;2854 c->phase = (c->phase + c->inc);
2854 2855
2855 return c->phase * INV_TWO_TO_32; 2856 return c->phase * INV_TWO_TO_32;
2856}2857}
@@ -2891,10 +2892,9 @@ void tSquareLFO_initToPool (tSquareLFO* const cy, tMempool* const mp) · 34 unmodified lines
2891 _tMempool* m = *mp;2892 _tMempool* m = *mp;
2892 _tSquareLFO* c = *cy = (_tSquareLFO*) mpool_alloc(sizeof(_tSquareLFO), m);2893 _tSquareLFO* c = *cy = (_tSquareLFO*) mpool_alloc(sizeof(_tSquareLFO), m);
2893 c->mempool = m;2894 c->mempool = m;
2894 LEAF* leaf = c->mempool->leaf;
2895 tIntPhasor_initToPool(&c->phasor,mp);2895 tIntPhasor_initToPool(&c->phasor,mp);
2896 tIntPhasor_initToPool(&c->invPhasor,mp); 2896 tIntPhasor_initToPool(&c->invPhasor,mp);
2897 tSquareLFO_setPulseWidth(cy, 0.5);2897 tSquareLFO_setPulseWidth(cy, 0.5f);
2898}2898}
2899 2899
2900void tSquareLFO_free (tSquareLFO* const cy)2900void tSquareLFO_free (tSquareLFO* const cy)
@@ -2937,7 +2937,6 @@ void tSquareLFO_setPulseWidth(tSquareLFO* const cy, float pw) · 36 unmodified lines
2937 _tSquareLFO *c = *cy;2937 _tSquareLFO *c = *cy;
2938 2938
2939 c->pulsewidth = pw;2939 c->pulsewidth = pw;
2940 //c->delay = c->pulsewidth * INV_TWO_TO_32;
2941 tIntPhasor_setPhase(&c->invPhasor, c->pulsewidth + (c->phasor->phase * INV_TWO_TO_32));2940 tIntPhasor_setPhase(&c->invPhasor, c->pulsewidth + (c->phasor->phase * INV_TWO_TO_32));
2942}2941}
2943 2942
@@ -2951,7 +2950,7 @@ void tSquareLFO_setPhase(tSquareLFO* const cy, float phase) · 7 unmodified lines
2951void tSawSquareLFO_init (tSawSquareLFO* const cy, LEAF* const leaf)2950void tSawSquareLFO_init (tSawSquareLFO* const cy, LEAF* const leaf)
2952{2951{
2953 tSawSquareLFO_initToPool(cy, &leaf->mempool);2952 tSawSquareLFO_initToPool(cy, &leaf->mempool);
2954 _tSawSquareLFO* c = *cy; 2953
2955}2954}
2956 2955
2957void tSawSquareLFO_initToPool (tSawSquareLFO* const cy, tMempool* const mp)2956void tSawSquareLFO_initToPool (tSawSquareLFO* const cy, tMempool* const mp)
@@ -2959,7 +2958,6 @@ void tSawSquareLFO_initToPool (tSawSquareLFO* const cy, tMempool* const mp) · 1 unmodified line
2959 _tMempool* m = *mp;2958 _tMempool* m = *mp;
2960 _tSawSquareLFO* c = *cy = (_tSawSquareLFO*) mpool_alloc(sizeof(_tSawSquareLFO), m);2959 _tSawSquareLFO* c = *cy = (_tSawSquareLFO*) mpool_alloc(sizeof(_tSawSquareLFO), m);
2961 c->mempool = m;2960 c->mempool = m;
2962 LEAF* leaf = c->mempool->leaf;
2963 tSquareLFO_initToPool(&c->square,mp);2961 tSquareLFO_initToPool(&c->square,mp);
2964 tIntPhasor_initToPool(&c->saw,mp); 2962 tIntPhasor_initToPool(&c->saw,mp);
2965}2963}
@@ -3024,8 +3022,7 @@ void tTriLFO_initToPool (tTriLFO* const cy, tMempool* const mp) · 58 unmodified lines
3024 c->phase = 0;3022 c->phase = 0;
3025 c->invSampleRate = leaf->invSampleRate;3023 c->invSampleRate = leaf->invSampleRate;
3026 c->invSampleRateTimesTwoTo32 = (c->invSampleRate * TWO_TO_32);3024 c->invSampleRateTimesTwoTo32 = (c->invSampleRate * TWO_TO_32);
3027 //c->mask = TRI_TABLE_SIZE - 1;3025 tTriLFO_setFreq(cy, 220.0f);
3028 tTriLFO_setFreq(cy, 220);
3029}3026}
3030 3027
3031void tTriLFO_free (tTriLFO* const cy)3028void tTriLFO_free (tTriLFO* const cy)
@@ -3039,35 +3036,16 @@ void tTriLFO_free (tTriLFO* const cy) · 7 unmodified lines
3039float tTriLFO_tick(tTriLFO* const cy)3036float tTriLFO_tick(tTriLFO* const cy)
3040{3037{
3041 _tTriLFO* c = *cy;3038 _tTriLFO* c = *cy;
3042 //uint32_t idx;
3043 //float frac, samp0, samp1;
3044 // Phasor increment
3045 c->phase += c->inc;3039 c->phase += c->inc;
3046 3040
3047 //bitmask fun3041 //bitmask fun
3048 //
3049 int32_t shiftedPhase = c->phase + 1073741824; // offset by 1/4" wave by adding 2^30 to get things in phase with the other LFO oscillators3042 int32_t shiftedPhase = c->phase + 1073741824; // offset by 1/4" wave by adding 2^30 to get things in phase with the other LFO oscillators
3050 uint32_t mask = shiftedPhase >> 31;3043 uint32_t mask = shiftedPhase >> 31; //get the sign bit
3051 int32_t val2 = shiftedPhase + mask;3044 shiftedPhase = shiftedPhase + mask; // add 1 if negative, zero if positive, to balance
3052 int32_t test = val2 ^ mask;3045 shiftedPhase = shiftedPhase ^ mask; //invert the value to get absolute value of integer
3053 float output =( ((float)test * INV_TWO_TO_31)-0.5f) * 2.0f;3046 float output = (((float)shiftedPhase * INV_TWO_TO_31) - 0.5f) * 2.0f; //scale it to -1.0f to 1.0f float
3054 return output;3047 return output;
3055 3048
3056 /*
3057 // Wavetable synthesis
3058 idx = c->phase >> 21;
3059 uint32_t idx2 = (idx + 1) & c->mask;
3060 uint32_t tempFrac = (c->phase & 2097151);
3061 frac = (float)tempFrac * 0.000000476837386f;// 1/2097151 (2097151 is the 21 bits after the 11 bits that represent the main index)
3062
3063 samp0 = __leaf_table_triangle[0][idx];
3064 samp1 = __leaf_table_triangle[0][idx2];
3065 float oct0 = (samp0 + (samp1 - samp0) * frac);
3066
3067
3068 return oct0;
3069 */
3070
3071}3049}
3072 3050
3073void tTriLFO_setFreq(tTriLFO* const cy, float freq)3051void tTriLFO_setFreq(tTriLFO* const cy, float freq)
@@ -3081,7 +3059,6 @@ void tTriLFO_setFreq(tTriLFO* const cy, float freq) · 7 unmodified lines
3081void tTriLFO_setPhase(tTriLFO* const cy, float phase)3059void tTriLFO_setPhase(tTriLFO* const cy, float phase)
3082{3060{
3083 _tTriLFO* c = *cy;3061 _tTriLFO* c = *cy;
3084 phase = (phase + 0.5f);
3085 int i = phase;3062 int i = phase;
3086 phase -= i;3063 phase -= i;
3087 c->phase = phase * TWO_TO_32_INT;3064 c->phase = phase * TWO_TO_32_INT;
@@ -3090,8 +3067,8 @@ void tTriLFO_setPhase(tTriLFO* const cy, float phase) · 2 unmodified lines
3090void tTriLFO_setSampleRate (tTriLFO* const cy, float sr)3067void tTriLFO_setSampleRate (tTriLFO* const cy, float sr)
3091{3068{
3092 _tTriLFO* c = *cy;3069 _tTriLFO* c = *cy;
3093 3070 c->invSampleRate = (1.0f/sr);
3094 c->invSampleRateTimesTwoTo32 = (1.0f/sr) * TWO_TO_32;3071 c->invSampleRateTimesTwoTo32 = c->invSampleRate * TWO_TO_32;
3095 tTriLFO_setFreq(cy, c->freq);3072 tTriLFO_setFreq(cy, c->freq);
3096}3073}
3097///sinetri3074///sinetri
@@ -3099,7 +3076,6 @@ void tTriLFO_setSampleRate (tTriLFO* const cy, float sr) · 1 unmodified line
3099void tSineTriLFO_init (tSineTriLFO* const cy, LEAF* const leaf)3076void tSineTriLFO_init (tSineTriLFO* const cy, LEAF* const leaf)
3100{3077{
3101 tSineTriLFO_initToPool(cy, &leaf->mempool);3078 tSineTriLFO_initToPool(cy, &leaf->mempool);
3102 _tSineTriLFO* c = *cy;
3103}3079}
3104 3080
3105void tSineTriLFO_initToPool (tSineTriLFO* const cy, tMempool* const mp)3081void tSineTriLFO_initToPool (tSineTriLFO* const cy, tMempool* const mp)
@@ -3107,7 +3083,6 @@ void tSineTriLFO_initToPool (tSineTriLFO* const cy, tMempool* const mp) · 1 unmodified line
3107 _tMempool* m = *mp;3083 _tMempool* m = *mp;
3108 _tSineTriLFO* c = *cy = (_tSineTriLFO*) mpool_alloc(sizeof(_tSineTriLFO), m);3084 _tSineTriLFO* c = *cy = (_tSineTriLFO*) mpool_alloc(sizeof(_tSineTriLFO), m);
3109 c->mempool = m;3085 c->mempool = m;
3110 LEAF* leaf = c->mempool->leaf;
3111 tTriLFO_initToPool(&c->tri,mp);3086 tTriLFO_initToPool(&c->tri,mp);
3112 tCycle_initToPool(&c->sine,mp); 3087 tCycle_initToPool(&c->sine,mp);
3113 3088
leaf/Src/leaf-sampling.c+2−2
@@ -1281,9 +1281,9 @@ float tMBSampler_tick (tMBSampler* const sp) · 1280 unmodified lines
1281 int start, end, length;1281 int start, end, length;
1282 float* buff;1282 float* buff;
1283 int j;1283 int j;
1284 float syncin;1284 //float syncin;
1285 float a, p, w, z;1285 float a, p, w, z;
1286 syncin = c->syncin;1286 // syncin = c->syncin;
1287 1287
1288 start = c->start;1288 start = c->start;
1289 end = c->end;1289 end = c->end;

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