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
14721472 tMempool mempool;
14731473 int32_t phase;
14741474 int32_t inc;
1475− int32_t prevPhase;
14761475 float freq;
1477− uint8_t phaseDidReset;
1478− uint32_t invSampleRate;
1476+ float invSampleRate;
14791477 float invSampleRateTimesTwoTo32;
14801478 } _tTriLFO;
14811479
leaf/Src/leaf-analysis.c+1−0
@@ -1822,6 +1822,7 @@ static inline void sub_collector_init(_sub_collector* collector, tZeroCrossingCo · 1821 unmodified lines
18221822 collector->_fundamental._period = -1;
18231823 collector->_fundamental._periodicity = 0.0f;
18241824 collector->_fundamental._harmonic = 0;
1825+ collector->_first_period = 0.01f;
18251826 }
18261827
18271828 static 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
13161316
13171317 smooth->curr = val;
13181318 smooth->dest = val;
1319− if (factor < 0) factor = 0;
1320− if (factor > 1) factor = 1;
1319+ if (factor < 0.0f) factor = 0.0f;
1320+ if (factor > 1.0f) factor = 1.0f;
13211321 smooth->baseFactor = factor;
13221322 smooth->factor = factor;
13231323 smooth->oneminusfactor = 1.0f - factor;
@@ -1334,9 +1334,9 @@ void tExpSmooth_setFactor(tExpSmooth* const expsmooth, float factor) · 10 unmodified lines
13341334 { // 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
13351335 _tExpSmooth* smooth = *expsmooth;
13361336
1337− if (factor < 0)
1338− factor = 0;
1339− else if (factor > 1) factor = 1;
1337+ if (factor < 0.0f)
1338+ factor = 0.0f;
1339+ else if (factor > 1.0f) factor = 1.0f;
13401340 smooth->baseFactor = factor;
13411341 smooth->factor = powf(factor, 44100.f * smooth->invSampleRate);
13421342 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
12691269
12701270 sync = c->sync;
12711271
1272−
12731272 p = c->_p; /* phase [0, 1) */
12741273 w = c->_w; /* phase increment */
12751274 b = c->_b; /* duty cycle (0, 1) */
@@ -1482,6 +1481,7 @@ void tMBTriangle_setFreq(tMBTriangle* const osc, float f) · 206 unmodified lines
14821481 void tMBTriangle_setWidth(tMBTriangle* const osc, float w)
14831482 {
14841483 _tMBTriangle* c = *osc;
1484+ w = LEAF_clip(0.0f, w, 0.99f);
14851485 c->waveform = w;
14861486 }
14871487
@@ -1846,10 +1846,13 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 358 unmodified lines
18461846 }
18471847
18481848
1849− /* now place reset DD for pulse */
1849+
18501850 if (sw > 0)
18511851 {
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) {
18531856 place_step_dd(c->_f, j, p, sw, 1.0f * shape);
18541857 k = 0;
18551858 x = 0.5f;
@@ -1862,6 +1865,9 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 6 unmodified lines
18621865 }
18631866 else if (sw < 0)
18641867 {
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 */
18651871 if (!k) {
18661872 place_step_dd(c->_f, j, 1.0f - p, -sw, -1.0f * shape);
18671873 k = 1;
@@ -1873,11 +1879,7 @@ float tMBSawPulse_tick(tMBSawPulse* const osc) · 5 unmodified lines
18731879 x = 0.5f;
18741880 }
18751881 }
1876− /* now place reset DD for saw*/
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);
1882+
18811883
18821884 }
18831885
@@ -2835,7 +2837,6 @@ void tIntPhasor_initToPool (tIntPhasor* const cy, tMempool* const mp) · 951 unmodified lines
28352837
28362838 c->phase = 0;
28372839 c->invSampleRateTimesTwoTo32 = (leaf->invSampleRate * TWO_TO_32);
2838− c->mask = 0x7FFFFFFF;
28392840 }
28402841
28412842 void tIntPhasor_free (tIntPhasor* const cy)
@@ -2850,7 +2851,7 @@ float tIntPhasor_tick(tIntPhasor* const cy) · 8 unmodified lines
28502851 {
28512852 _tIntPhasor* c = *cy;
28522853 // Phasor increment
2853− c->phase = (c->phase + c->inc);//& c->mask;
2854+ c->phase = (c->phase + c->inc);
28542855
28552856 return c->phase * INV_TWO_TO_32;
28562857 }
@@ -2891,10 +2892,9 @@ void tSquareLFO_initToPool (tSquareLFO* const cy, tMempool* const mp) · 34 unmodified lines
28912892 _tMempool* m = *mp;
28922893 _tSquareLFO* c = *cy = (_tSquareLFO*) mpool_alloc(sizeof(_tSquareLFO), m);
28932894 c->mempool = m;
2894− LEAF* leaf = c->mempool->leaf;
28952895 tIntPhasor_initToPool(&c->phasor,mp);
28962896 tIntPhasor_initToPool(&c->invPhasor,mp);
2897− tSquareLFO_setPulseWidth(cy, 0.5);
2897+ tSquareLFO_setPulseWidth(cy, 0.5f);
28982898 }
28992899
29002900 void tSquareLFO_free (tSquareLFO* const cy)
@@ -2937,7 +2937,6 @@ void tSquareLFO_setPulseWidth(tSquareLFO* const cy, float pw) · 36 unmodified lines
29372937 _tSquareLFO *c = *cy;
29382938
29392939 c->pulsewidth = pw;
2940− //c->delay = c->pulsewidth * INV_TWO_TO_32;
29412940 tIntPhasor_setPhase(&c->invPhasor, c->pulsewidth + (c->phasor->phase * INV_TWO_TO_32));
29422941 }
29432942
@@ -2951,7 +2950,7 @@ void tSquareLFO_setPhase(tSquareLFO* const cy, float phase) · 7 unmodified lines
29512950 void tSawSquareLFO_init (tSawSquareLFO* const cy, LEAF* const leaf)
29522951 {
29532952 tSawSquareLFO_initToPool(cy, &leaf->mempool);
2954− _tSawSquareLFO* c = *cy;
2953+
29552954 }
29562955
29572956 void tSawSquareLFO_initToPool (tSawSquareLFO* const cy, tMempool* const mp)
@@ -2959,7 +2958,6 @@ void tSawSquareLFO_initToPool (tSawSquareLFO* const cy, tMempool* const mp) · 1 unmodified line
29592958 _tMempool* m = *mp;
29602959 _tSawSquareLFO* c = *cy = (_tSawSquareLFO*) mpool_alloc(sizeof(_tSawSquareLFO), m);
29612960 c->mempool = m;
2962− LEAF* leaf = c->mempool->leaf;
29632961 tSquareLFO_initToPool(&c->square,mp);
29642962 tIntPhasor_initToPool(&c->saw,mp);
29652963 }
@@ -3024,8 +3022,7 @@ void tTriLFO_initToPool (tTriLFO* const cy, tMempool* const mp) · 58 unmodified lines
30243022 c->phase = 0;
30253023 c->invSampleRate = leaf->invSampleRate;
30263024 c->invSampleRateTimesTwoTo32 = (c->invSampleRate * TWO_TO_32);
3027− //c->mask = TRI_TABLE_SIZE - 1;
3028− tTriLFO_setFreq(cy, 220);
3025+ tTriLFO_setFreq(cy, 220.0f);
30293026 }
30303027
30313028 void tTriLFO_free (tTriLFO* const cy)
@@ -3039,35 +3036,16 @@ void tTriLFO_free (tTriLFO* const cy) · 7 unmodified lines
30393036 float tTriLFO_tick(tTriLFO* const cy)
30403037 {
30413038 _tTriLFO* c = *cy;
3042− //uint32_t idx;
3043− //float frac, samp0, samp1;
3044− // Phasor increment
30453039 c->phase += c->inc;
30463040
30473041 //bitmask fun
3048− //
30493042 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;
3051− int32_t val2 = shiftedPhase + mask;
3052− int32_t test = val2 ^ mask;
3053− float output =( ((float)test * INV_TWO_TO_31)-0.5f) * 2.0f;
3043+ uint32_t mask = shiftedPhase >> 31; //get the sign bit
3044+ shiftedPhase = shiftedPhase + mask; // add 1 if negative, zero if positive, to balance
3045+ shiftedPhase = shiftedPhase ^ mask; //invert the value to get absolute value of integer
3046+ float output = (((float)shiftedPhase * INV_TWO_TO_31) - 0.5f) * 2.0f; //scale it to -1.0f to 1.0f float
30543047 return output;
30553048
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−
30713049 }
30723050
30733051 void tTriLFO_setFreq(tTriLFO* const cy, float freq)
@@ -3081,7 +3059,6 @@ void tTriLFO_setFreq(tTriLFO* const cy, float freq) · 7 unmodified lines
30813059 void tTriLFO_setPhase(tTriLFO* const cy, float phase)
30823060 {
30833061 _tTriLFO* c = *cy;
3084− phase = (phase + 0.5f);
30853062 int i = phase;
30863063 phase -= i;
30873064 c->phase = phase * TWO_TO_32_INT;
@@ -3090,8 +3067,8 @@ void tTriLFO_setPhase(tTriLFO* const cy, float phase) · 2 unmodified lines
30903067 void tTriLFO_setSampleRate (tTriLFO* const cy, float sr)
30913068 {
30923069 _tTriLFO* c = *cy;
3093−
3094− c->invSampleRateTimesTwoTo32 = (1.0f/sr) * TWO_TO_32;
3070+ c->invSampleRate = (1.0f/sr);
3071+ c->invSampleRateTimesTwoTo32 = c->invSampleRate * TWO_TO_32;
30953072 tTriLFO_setFreq(cy, c->freq);
30963073 }
30973074 ///sinetri
@@ -3099,7 +3076,6 @@ void tTriLFO_setSampleRate (tTriLFO* const cy, float sr) · 1 unmodified line
30993076 void tSineTriLFO_init (tSineTriLFO* const cy, LEAF* const leaf)
31003077 {
31013078 tSineTriLFO_initToPool(cy, &leaf->mempool);
3102− _tSineTriLFO* c = *cy;
31033079 }
31043080
31053081 void tSineTriLFO_initToPool (tSineTriLFO* const cy, tMempool* const mp)
@@ -3107,7 +3083,6 @@ void tSineTriLFO_initToPool (tSineTriLFO* const cy, tMempool* const mp) · 1 unmodified line
31073083 _tMempool* m = *mp;
31083084 _tSineTriLFO* c = *cy = (_tSineTriLFO*) mpool_alloc(sizeof(_tSineTriLFO), m);
31093085 c->mempool = m;
3110− LEAF* leaf = c->mempool->leaf;
31113086 tTriLFO_initToPool(&c->tri,mp);
31123087 tCycle_initToPool(&c->sine,mp);
31133088
leaf/Src/leaf-sampling.c+2−2
@@ -1281,9 +1281,9 @@ float tMBSampler_tick (tMBSampler* const sp) · 1280 unmodified lines
12811281 int start, end, length;
12821282 float* buff;
12831283 int j;
1284− float syncin;
1284+ //float syncin;
12851285 float a, p, w, z;
1286− syncin = c->syncin;
1286+ // syncin = c->syncin;
12871287
12881288 start = c->start;
12891289 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