History

factor sample rate into tick based env factors and neuron timestep

Matthew Wang committed 5 years ago

Commit 3eaa22b1 parent 8b254657 files · +101 −40Browse files

Unified · Split

7 files
  1. leaf/Inc/leaf-envelopes.h +15 −6
  2. leaf/Inc/leaf-math.h +3 −0
  3. leaf/Inc/leaf-oscillators.h +2 −1
  4. leaf/Inc/leaf-reverb.h +0 −2
  5. leaf/Src/leaf-envelopes.c +65 −21
  6. leaf/Src/leaf-oscillators.c +12 −3
  7. leaf/Src/leaf-reverb.c +4 −7
leaf/Inc/leaf-envelopes.h+15−6
@@ -164,8 +164,9 @@ extern "C" { · 163 unmodified lines
164 {164 {
165 165
166 tMempool mempool;166 tMempool mempool;
167 float factor, oneminusfactor;167 float baseFactor, factor, oneminusfactor;
168 float curr,dest;168 float curr,dest;
169 float invSampleRate;
169 } _tExpSmooth;170 } _tExpSmooth;
170 171
171 typedef _tExpSmooth* tExpSmooth;172 typedef _tExpSmooth* tExpSmooth;
@@ -179,7 +180,8 @@ extern "C" { · 7 unmodified lines
179 void tExpSmooth_setFactor (tExpSmooth* const, float factor);180 void tExpSmooth_setFactor (tExpSmooth* const, float factor);
180 void tExpSmooth_setDest (tExpSmooth* const, float dest);181 void tExpSmooth_setDest (tExpSmooth* const, float dest);
181 void tExpSmooth_setVal (tExpSmooth* const, float val);182 void tExpSmooth_setVal (tExpSmooth* const, float val);
182 void tExpSmooth_setValAndDest(tExpSmooth* const expsmooth, float val);183 void tExpSmooth_setValAndDest(tExpSmooth* const, float val);
184 void tExpSmooth_setSampleRate(tExpSmooth* const, float sr);
183 185
184 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~186 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
185 187
@@ -252,6 +254,8 @@ extern "C" { · 66 unmodified lines
252 254
253 float next;255 float next;
254 256
257 float attack, decay, release;
258
255 float attackInc, decayInc, releaseInc, rampInc;259 float attackInc, decayInc, releaseInc, rampInc;
256 260
257 int inAttack, inDecay, inSustain, inRelease, inRamp;261 int inAttack, inDecay, inSustain, inRelease, inRamp;
@@ -260,7 +264,9 @@ extern "C" { · 2 unmodified lines
260 264
261 float attackPhase, decayPhase, releasePhase, rampPhase;265 float attackPhase, decayPhase, releasePhase, rampPhase;
262 266
263 float leakFactor;267 float baseLeakFactor, leakFactor;
268
269 float invSampleRate;
264 } _tADSR;270 } _tADSR;
265 271
266 typedef _tADSR* tADSR;272 typedef _tADSR* tADSR;
@@ -277,6 +283,7 @@ extern "C" { · 10 unmodified lines
277 void tADSR_setLeakFactor (tADSR* const, float leakFactor);283 void tADSR_setLeakFactor (tADSR* const, float leakFactor);
278 void tADSR_on (tADSR* const, float velocity);284 void tADSR_on (tADSR* const, float velocity);
279 void tADSR_off (tADSR* const);285 void tADSR_off (tADSR* const);
286 void tADSR_setSampleRate (tADSR* const, float sr);
280 287
281 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~288 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
282 289
@@ -358,7 +365,9 @@ extern "C" { · 75 unmodified lines
358 365
359 float attackPhase, decayPhase, releasePhase, rampPhase;366 float attackPhase, decayPhase, releasePhase, rampPhase;
360 367
361 float leakFactor;368 float baseLeakFactor, leakFactor;
369
370 float invSampleRate;
362 } _tADSRT;371 } _tADSRT;
363 372
364 typedef _tADSRT* tADSRT;373 typedef _tADSRT* tADSRT;
@@ -466,12 +475,12 @@ extern "C" { · 101 unmodified lines
466 float attackBase;475 float attackBase;
467 float decayBase;476 float decayBase;
468 float releaseBase;477 float releaseBase;
469 float leakFactor;478 float baseLeakFactor, leakFactor;
470 float targetGainSquared;479 float targetGainSquared;
471 float factor;480 float factor;
472 float oneMinusFactor;481 float oneMinusFactor;
473 float gain;482 float gain;
474 483 float invSampleRate;
475 } _tADSRS;484 } _tADSRS;
476 485
477 typedef _tADSRS* tADSRS;486 typedef _tADSRS* tADSRS;
leaf/Inc/leaf-math.h+3−0
@@ -58,6 +58,9 @@ extern "C" { · 57 unmodified lines
58#define INV_10240 0.00009765625f58#define INV_10240 0.00009765625f
59#define INV_20480 0.000048828125f59#define INV_20480 0.000048828125f
60 60
61#define INV_44100 0.00002267573f
62#define INV_48000 0.00002083333f
63
61 64
62#define INV_TWELVE 0.0833333333f65#define INV_TWELVE 0.0833333333f
63#define INV_440 0.0022727273f66#define INV_440 0.0022727273f
leaf/Inc/leaf-oscillators.h+2−1
@@ -630,7 +630,7 @@ extern "C" { · 629 unmodified lines
630 630
631 float voltage, current;631 float voltage, current;
632 float timeStep;632 float timeStep;
633 633 float invSampleRate;
634 float alpha[3];634 float alpha[3];
635 float beta[3];635 float beta[3];
636 float rate[3];636 float rate[3];
@@ -657,6 +657,7 @@ extern "C" { · 20 unmodified lines
657 void tNeuron_setV2 (tNeuron* const neuron, float V2);657 void tNeuron_setV2 (tNeuron* const neuron, float V2);
658 void tNeuron_setV3 (tNeuron* const neuron, float V3);658 void tNeuron_setV3 (tNeuron* const neuron, float V3);
659 void tNeuron_setTimeStep (tNeuron* const neuron, float timestep);659 void tNeuron_setTimeStep (tNeuron* const neuron, float timestep);
660 void tNeuron_setSampleRate(tNeuron* const neuron, float sr);
660 661
661 //==============================================================================662 //==============================================================================
662 663
leaf/Inc/leaf-reverb.h+0−2
@@ -77,7 +77,6 @@ extern "C" { · 76 unmodified lines
77 77
78 float mix, t60;78 float mix, t60;
79 79
80 float inv_441;
81 float sampleRate;80 float sampleRate;
82 float invSampleRate;81 float invSampleRate;
83 82
@@ -152,7 +151,6 @@ extern "C" { · 68 unmodified lines
152 151
153 float mix, t60;152 float mix, t60;
154 153
155 float inv_441;
156 float sampleRate;154 float sampleRate;
157 float invSampleRate;155 float invSampleRate;
158 156
leaf/Src/leaf-envelopes.c+65−21
@@ -234,11 +234,13 @@ void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, fl · 233 unmodified lines
234 attack = 8192.0f;234 attack = 8192.0f;
235 if (attack < 0.0f)235 if (attack < 0.0f)
236 attack = 0.0f;236 attack = 0.0f;
237 adsr->attack = attack;
237 238
238 if (decay > 8192.0f)239 if (decay > 8192.0f)
239 decay = 8192.0f;240 decay = 8192.0f;
240 if (decay < 0.0f)241 if (decay < 0.0f)
241 decay = 0.0f;242 decay = 0.0f;
243 adsr->decay = decay;
242 244
243 if (sustain > 1.0f)245 if (sustain > 1.0f)
244 sustain = 1.0f;246 sustain = 1.0f;
@@ -249,6 +251,7 @@ void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, fl · 4 unmodified lines
249 release = 8192.0f;251 release = 8192.0f;
250 if (release < 0.0f)252 if (release < 0.0f)
251 release = 0.0f;253 release = 0.0f;
254 adsr->release = release;
252 255
253 int16_t attackIndex = ((int16_t)(attack * 8.0f))-1;256 int16_t attackIndex = ((int16_t)(attack * 8.0f))-1;
254 int16_t decayIndex = ((int16_t)(decay * 8.0f))-1;257 int16_t decayIndex = ((int16_t)(decay * 8.0f))-1;
@@ -279,7 +282,9 @@ void tADSR_initToPool (tADSR* const adsrenv, float attack, float decay, fl · 24 unmodified lines
279 adsr->releaseInc = adsr->inc_buff[releaseIndex];282 adsr->releaseInc = adsr->inc_buff[releaseIndex];
280 adsr->rampInc = adsr->inc_buff[rampIndex];283 adsr->rampInc = adsr->inc_buff[rampIndex];
281 284
285 adsr->baseLeakFactor = 1.0f;
282 adsr->leakFactor = 1.0f;286 adsr->leakFactor = 1.0f;
287 adsr->invSampleRate = adsr->mempool->leaf->invSampleRate;
283}288}
284 289
285void tADSR_free (tADSR* const adsrenv)290void tADSR_free (tADSR* const adsrenv)
@@ -293,6 +298,8 @@ void tADSR_setAttack(tADSR* const adsrenv, float attack) · 7 unmodified lines
293 _tADSR* adsr = *adsrenv;298 _tADSR* adsr = *adsrenv;
294 299
295 int32_t attackIndex;300 int32_t attackIndex;
301
302 adsr->attack = attack;
296 303
297 if (attack < 0.0f) {304 if (attack < 0.0f) {
298 attackIndex = 0.0f;305 attackIndex = 0.0f;
@@ -302,7 +309,7 @@ void tADSR_setAttack(tADSR* const adsrenv, float attack) · 3 unmodified lines
302 attackIndex = ((int32_t)(8192.0f * 8.0f))-1;309 attackIndex = ((int32_t)(8192.0f * 8.0f))-1;
303 }310 }
304 311
305 adsr->attackInc = adsr->inc_buff[attackIndex];312 adsr->attackInc = adsr->inc_buff[attackIndex] * (44100.f * adsr->invSampleRate);
306}313}
307 314
308void tADSR_setDecay(tADSR* const adsrenv, float decay)315void tADSR_setDecay(tADSR* const adsrenv, float decay)
@@ -310,6 +317,8 @@ void tADSR_setDecay(tADSR* const adsrenv, float decay) · 1 unmodified line
310 _tADSR* adsr = *adsrenv;317 _tADSR* adsr = *adsrenv;
311 318
312 int32_t decayIndex;319 int32_t decayIndex;
320
321 adsr->decay = decay;
313 322
314 if (decay < 0.0f) {323 if (decay < 0.0f) {
315 decayIndex = 0.0f;324 decayIndex = 0.0f;
@@ -319,7 +328,7 @@ void tADSR_setDecay(tADSR* const adsrenv, float decay) · 3 unmodified lines
319 decayIndex = ((int32_t)(8192.0f * 8.0f)) - 1;328 decayIndex = ((int32_t)(8192.0f * 8.0f)) - 1;
320 }329 }
321 330
322 adsr->decayInc = adsr->inc_buff[decayIndex];331 adsr->decayInc = adsr->inc_buff[decayIndex] * (44100.f * adsr->invSampleRate);
323}332}
324 333
325void tADSR_setSustain(tADSR* const adsrenv, float sustain)334void tADSR_setSustain(tADSR* const adsrenv, float sustain)
@@ -336,6 +345,8 @@ void tADSR_setRelease(tADSR* const adsrenv, float release) · 10 unmodified lines
336 _tADSR* adsr = *adsrenv;345 _tADSR* adsr = *adsrenv;
337 346
338 int32_t releaseIndex;347 int32_t releaseIndex;
348
349 adsr->release = release;
339 350
340 if (release < 0.0f) {351 if (release < 0.0f) {
341 releaseIndex = 0.0f;352 releaseIndex = 0.0f;
@@ -345,16 +356,15 @@ void tADSR_setRelease(tADSR* const adsrenv, float release) · 3 unmodified lines
345 releaseIndex = ((int32_t)(8192.0f * 8.0f)) - 1;356 releaseIndex = ((int32_t)(8192.0f * 8.0f)) - 1;
346 }357 }
347 358
348 adsr->releaseInc = adsr->inc_buff[releaseIndex];359 adsr->releaseInc = adsr->inc_buff[releaseIndex] * (44100.f * adsr->invSampleRate);
349}360}
350 361
351// 0.999999 is slow leak, 0.9 is fast leak362// 0.999999 is slow leak, 0.9 is fast leak
352void tADSR_setLeakFactor(tADSR* const adsrenv, float leakFactor)363void tADSR_setLeakFactor(tADSR* const adsrenv, float leakFactor)
353{364{
354 _tADSR* adsr = *adsrenv;365 _tADSR* adsr = *adsrenv;
355 366 adsr->baseLeakFactor = leakFactor;
356 367 adsr->leakFactor = powf(leakFactor, 44100.0f * adsr->invSampleRate);
357 adsr->leakFactor = leakFactor;
358}368}
359 369
360void tADSR_on(tADSR* const adsrenv, float velocity)370void tADSR_on(tADSR* const adsrenv, float velocity)
@@ -482,6 +492,19 @@ float tADSR_tick(tADSR* const adsrenv) · 121 unmodified lines
482 492
483 return adsr->next;493 return adsr->next;
484}494}
495
496void tADSR_setSampleRate(tADSR* const adsrenv, float sr)
497{
498 _tADSR* adsr = *adsrenv;
499
500 adsr->invSampleRate = 1.0f/sr;
501
502 tADSR_setAttack(adsrenv, adsr->attack);
503 tADSR_setDecay(adsrenv, adsr->decay);
504 tADSR_setRelease(adsrenv, adsr->release);
505 tADSR_setLeakFactor(adsrenv, adsr->baseLeakFactor);
506}
507
485#endif // LEAF_INCLUDE_ADSR_TABLES508#endif // LEAF_INCLUDE_ADSR_TABLES
486 509
487 510
@@ -535,7 +558,11 @@ void tADSRS_initToPool (tADSRS* const adsrenv, float attack, float decay, · 47 unmodified lines
535 adsr->factor = 0.01f;558 adsr->factor = 0.01f;
536 adsr->oneMinusFactor = 0.99f;559 adsr->oneMinusFactor = 0.99f;
537 adsr->output = 0.0f;560 adsr->output = 0.0f;
561
562 adsr->baseLeakFactor = 1.0f;
538 adsr->leakFactor = 1.0f;563 adsr->leakFactor = 1.0f;
564
565 adsr->invSampleRate = leaf->invSampleRate;
539}566}
540 567
541void tADSRS_free (tADSRS* const adsrenv)568void tADSRS_free (tADSRS* const adsrenv)
@@ -586,7 +613,8 @@ void tADSRS_setRelease(tADSRS* const adsrenv, float release) · 44 unmodified lines
586void tADSRS_setLeakFactor(tADSRS* const adsrenv, float leakFactor)613void tADSRS_setLeakFactor(tADSRS* const adsrenv, float leakFactor)
587{614{
588 _tADSRS* adsr = *adsrenv;615 _tADSRS* adsr = *adsrenv;
589 adsr->leakFactor = leakFactor;616 adsr->baseLeakFactor = leakFactor;
617 adsr->leakFactor = powf(leakFactor, 44100.0f * adsr->invSampleRate);
590}618}
591 619
592void tADSRS_on(tADSRS* const adsrenv, float velocity)620void tADSRS_on(tADSRS* const adsrenv, float velocity)
@@ -650,10 +678,12 @@ void tADSRS_setSampleRate(tADSRS* const adsrenv, float sr) · 57 unmodified lines
650 678
651 adsr->sampleRate = sr;679 adsr->sampleRate = sr;
652 adsr->sampleRateInMs = adsr->sampleRate * 0.001f;680 adsr->sampleRateInMs = adsr->sampleRate * 0.001f;
681 adsr->invSampleRate = 1.0f/sr;
653 682
654 tADSRS_setAttack(adsrenv, adsr->attack);683 tADSRS_setAttack(adsrenv, adsr->attack);
655 tADSRS_setDecay(adsrenv, adsr->decay);684 tADSRS_setDecay(adsrenv, adsr->decay);
656 tADSRS_setRelease(adsrenv, adsr->release);685 tADSRS_setRelease(adsrenv, adsr->release);
686 tADSRS_setLeakFactor(adsrenv, adsr->baseLeakFactor);
657}687}
658 688
659//================================================================================689//================================================================================
@@ -710,7 +740,9 @@ void tADSRT_initToPool (tADSRT* const adsrenv, float attack, float decay, · 50 unmodified lines
710 adsr->releaseInc = adsr->bufferSizeDividedBySampleRateInMs / release;740 adsr->releaseInc = adsr->bufferSizeDividedBySampleRateInMs / release;
711 adsr->rampInc = adsr->bufferSizeDividedBySampleRateInMs / 8.0f;741 adsr->rampInc = adsr->bufferSizeDividedBySampleRateInMs / 8.0f;
712 742
743 adsr->baseLeakFactor = 1.0f;
713 adsr->leakFactor = 1.0f;744 adsr->leakFactor = 1.0f;
745 adsr->invSampleRate = leaf->invSampleRate;
714}746}
715 747
716void tADSRT_free (tADSRT* const adsrenv)748void tADSRT_free (tADSRT* const adsrenv)
@@ -768,7 +800,8 @@ void tADSRT_setRelease(tADSRT* const adsrenv, float release) · 51 unmodified lines
768void tADSRT_setLeakFactor(tADSRT* const adsrenv, float leakFactor)800void tADSRT_setLeakFactor(tADSRT* const adsrenv, float leakFactor)
769{801{
770 _tADSRT* adsr = *adsrenv;802 _tADSRT* adsr = *adsrenv;
771 adsr->leakFactor = leakFactor;803 adsr->baseLeakFactor = leakFactor;
804 adsr->leakFactor = powf(leakFactor, 44100.0f * adsr->invSampleRate);;
772}805}
773 806
774void tADSRT_on(tADSRT* const adsrenv, float velocity)807void tADSRT_on(tADSRT* const adsrenv, float velocity)
@@ -1010,16 +1043,18 @@ float tADSRT_tickNoInterp(tADSRT* const adsrenv) · 235 unmodified lines
1010 return adsr->next;1043 return adsr->next;
1011}1044}
1012 1045
1013void tADSRT_setSampleRate (tADSRT* const adsrenv, float sr)1046void tADSRT_setSampleRate(tADSRT* const adsrenv, float sr)
1014{1047{
1015 _tADSRT* adsr = *adsrenv;1048 _tADSRT* adsr = *adsrenv;
1016 1049
1017 adsr->sampleRate = sr;1050 adsr->sampleRate = sr;
1051 adsr->invSampleRate = 1.0f/sr;
1018 adsr->bufferSizeDividedBySampleRateInMs = adsr->buff_size / (adsr->sampleRate * 0.001f);1052 adsr->bufferSizeDividedBySampleRateInMs = adsr->buff_size / (adsr->sampleRate * 0.001f);
1019 adsr->attackInc = adsr->bufferSizeDividedBySampleRateInMs / adsr->attack;1053 adsr->attackInc = adsr->bufferSizeDividedBySampleRateInMs / adsr->attack;
1020 adsr->decayInc = adsr->bufferSizeDividedBySampleRateInMs / adsr->decay;1054 adsr->decayInc = adsr->bufferSizeDividedBySampleRateInMs / adsr->decay;
1021 adsr->releaseInc = adsr->bufferSizeDividedBySampleRateInMs / adsr->release;1055 adsr->releaseInc = adsr->bufferSizeDividedBySampleRateInMs / adsr->release;
1022 adsr->rampInc = adsr->bufferSizeDividedBySampleRateInMs / 8.0f;1056 adsr->rampInc = adsr->bufferSizeDividedBySampleRateInMs / 8.0f;
1057 adsr->leakFactor = powf(adsr->baseLeakFactor, 44100.0f * adsr->invSampleRate);
1023}1058}
1024 1059
1025/////-----------------1060/////-----------------
@@ -1279,12 +1314,13 @@ void tExpSmooth_initToPool (tExpSmooth* const expsmooth, float val, float f · 253 unmodified lines
1279 _tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), m);1314 _tExpSmooth* smooth = *expsmooth = (_tExpSmooth*) mpool_alloc(sizeof(_tExpSmooth), m);
1280 smooth->mempool = m;1315 smooth->mempool = m;
1281 1316
1282 smooth->curr=val;1317 smooth->curr = val;
1283 smooth->dest=val;1318 smooth->dest = val;
1284 if (factor<0) factor=0;1319 if (factor < 0) factor = 0;
1285 if (factor>1) factor=1;1320 if (factor > 1) factor = 1;
1286 smooth->factor=factor;1321 smooth->factor = factor;
1287 smooth->oneminusfactor=1.0f-factor;1322 smooth->oneminusfactor = 1.0f - factor;
1323 smooth->invSampleRate = smooth->mempool->leaf->invSampleRate;
1288}1324}
1289 1325
1290void tExpSmooth_free (tExpSmooth* const expsmooth)1326void tExpSmooth_free (tExpSmooth* const expsmooth)
@@ -1297,12 +1333,12 @@ void tExpSmooth_setFactor(tExpSmooth* const expsmooth, float factor) · 6 unmodified lines
1297{ // 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 10ms1333{ // 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
1298 _tExpSmooth* smooth = *expsmooth;1334 _tExpSmooth* smooth = *expsmooth;
1299 1335
1300 if (factor<0)1336 if (factor < 0)
1301 factor=0;1337 factor = 0;
1302 else1338 else if (factor > 1) factor = 1;
1303 if (factor>1) factor=1;1339 smooth->baseFactor = factor;
1304 smooth->factor=factor;1340 smooth->factor = powf(factor, 44100.f * smooth->invSampleRate);
1305 smooth->oneminusfactor=1.0f-factor;1341 smooth->oneminusfactor = 1.0f - factor;
1306}1342}
1307 1343
1308void tExpSmooth_setDest(tExpSmooth* const expsmooth, float dest)1344void tExpSmooth_setDest(tExpSmooth* const expsmooth, float dest)
@@ -1337,6 +1373,14 @@ float tExpSmooth_sample(tExpSmooth* const expsmooth) · 28 unmodified lines
1337 return smooth->curr;1373 return smooth->curr;
1338}1374}
1339 1375
1376void tExpSmooth_setSampleRate(tExpSmooth* const expsmooth, float sr)
1377{
1378 _tExpSmooth* smooth = *expsmooth;
1379 smooth->invSampleRate = 1.0f/sr;
1380 smooth->factor = powf(smooth->baseFactor, 44100.f * smooth->invSampleRate);
1381 smooth->oneminusfactor = 1.0f - smooth->factor;
1382}
1383
1340//tSlide is based on the max/msp slide~ object1384//tSlide is based on the max/msp slide~ object
1341////1385////
1342 1386
leaf/Src/leaf-oscillators.c+12−3
@@ -700,12 +700,14 @@ void tNeuron_initToPool (tNeuron* const nr, tMempool* const mp) · 699 unmodified lines
700 _tMempool* m = *mp;700 _tMempool* m = *mp;
701 _tNeuron* n = *nr = (_tNeuron*) mpool_alloc(sizeof(_tNeuron), m);701 _tNeuron* n = *nr = (_tNeuron*) mpool_alloc(sizeof(_tNeuron), m);
702 n->mempool = m;702 n->mempool = m;
703 LEAF* leaf = n->mempool->leaf;
703 704
704 tPoleZero_initToPool(&n->f, mp);705 tPoleZero_initToPool(&n->f, mp);
705 706
706 tPoleZero_setBlockZero(&n->f, 0.99f);707 tPoleZero_setBlockZero(&n->f, 0.99f);
707 708
708 n->timeStep = 1.0f / 50.0f;709 n->invSampleRate = leaf->invSampleRate;
710 n->timeStep = (44100.0f * n->invSampleRate) / 50.0f;
709 711
710 n->current = 0.0f; // 100.0f for sound712 n->current = 0.0f; // 100.0f for sound
711 n->voltage = 0.0f;713 n->voltage = 0.0f;
@@ -742,7 +744,7 @@ void tNeuron_reset(tNeuron* const nr) · 30 unmodified lines
742 744
743 tPoleZero_setBlockZero(&n->f, 0.99f);745 tPoleZero_setBlockZero(&n->f, 0.99f);
744 746
745 n->timeStep = 1.0f / 50.0f;747 n->timeStep = (44100.0f * n->invSampleRate) / 50.0f;
746 748
747 n->current = 0.0f; // 100.0f for sound749 n->current = 0.0f; // 100.0f for sound
748 n->voltage = 0.0f;750 n->voltage = 0.0f;
@@ -786,7 +788,7 @@ void tNeuron_setV3(tNeuron* const nr, float V3) · 37 unmodified lines
786void tNeuron_setTimeStep(tNeuron* const nr, float timeStep)788void tNeuron_setTimeStep(tNeuron* const nr, float timeStep)
787{789{
788 _tNeuron* n = *nr;790 _tNeuron* n = *nr;
789 n->timeStep = timeStep;791 n->timeStep = (44100.0f * n->invSampleRate) * timeStep;
790}792}
791 793
792void tNeuron_setK(tNeuron* const nr, float K)794void tNeuron_setK(tNeuron* const nr, float K)
@@ -903,6 +905,13 @@ void tNeuron_setCurrent (tNeuron* const nr, float current) · 110 unmodified lines
903 n->current = current;905 n->current = current;
904}906}
905 907
908void tNeuron_setSampleRate (tNeuron* const nr, float sr)
909{
910 _tNeuron* n = *nr;
911 n->invSampleRate = 1.0f/sr;
912 n->timeStep = (44100.0f * n->invSampleRate) / 50.0f;
913}
914
906//----------------------------------------------------------------------------------------------------------915//----------------------------------------------------------------------------------------------------------
907 916
908void tMBPulse_init(tMBPulse* const osc, LEAF* const leaf)917void tMBPulse_init(tMBPulse* const osc, LEAF* const leaf)
leaf/Src/leaf-reverb.c+4−7
@@ -33,13 +33,11 @@ void tPRCReverb_initToPool (tPRCReverb* const rev, float t60, tMempool* con · 32 unmodified lines
33 33
34 if (t60 <= 0.0f) t60 = 0.001f;34 if (t60 <= 0.0f) t60 = 0.001f;
35 35
36 r->inv_441 = 1.0f/44100.0f;
37
38 r->sampleRate = leaf->sampleRate;36 r->sampleRate = leaf->sampleRate;
39 r->invSampleRate = leaf->invSampleRate;37 r->invSampleRate = leaf->invSampleRate;
40 38
41 int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate.39 int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate.
42 double scaler = r->sampleRate * r->inv_441;40 double scaler = r->sampleRate * INV_44100;
43 41
44 int delay, i;42 int delay, i;
45 if (scaler != 1.0f)43 if (scaler != 1.0f)
@@ -144,7 +142,7 @@ void tPRCReverb_setSampleRate (tPRCReverb* const rev, float sr) · 98 unmodified lines
144 r->invSampleRate = 1.0f/r->sampleRate;142 r->invSampleRate = 1.0f/r->sampleRate;
145 143
146 int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate.144 int lengths[4] = { 341, 613, 1557, 2137 }; // Delay lengths for 44100 Hz sample rate.
147 double scaler = r->sampleRate * r->inv_441;145 double scaler = r->sampleRate * INV_44100;
148 146
149 int delay, i;147 int delay, i;
150 if (scaler != 1.0f)148 if (scaler != 1.0f)
@@ -187,12 +185,11 @@ void tNReverb_initToPool (tNReverb* const rev, float t60, tMempool* const · 36 unmodified lines
187 185
188 if (t60 <= 0.0f) t60 = 0.001f;186 if (t60 <= 0.0f) t60 = 0.001f;
189 187
190 r->inv_441 = 1.0f/44100.0f;
191 r->sampleRate = leaf->sampleRate;188 r->sampleRate = leaf->sampleRate;
192 r->invSampleRate = leaf->invSampleRate;189 r->invSampleRate = leaf->invSampleRate;
193 190
194 int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate.191 int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate.
195 double scaler = r->sampleRate * r->inv_441;// / 25641.0f;192 double scaler = r->sampleRate * INV_44100;// / 25641.0f;
196 193
197 int delay, i;194 int delay, i;
198 195
@@ -389,7 +386,7 @@ void tNReverb_setSampleRate (tNReverb* const rev, float sr) · 190 unmodified lines
389 r->invSampleRate = 1.0f/r->sampleRate;386 r->invSampleRate = 1.0f/r->sampleRate;
390 387
391 int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate.388 int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19}; // Delay lengths for 44100 Hz sample rate.
392 double scaler = r->sampleRate * r->inv_441;// / 25641.0f;389 double scaler = r->sampleRate * INV_44100;// / 25641.0f;
393 390
394 int delay, i;391 int delay, i;
395 392

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