History

clear physical model delay lines on init

Matthew Wang committed 6 years ago

Commit 44c8a751 parent 2313a7d1 file · +16 −123Browse files

Unified · Split

LEAF/Src/leaf-physical.c+16−123
@@ -19,31 +19,12 @@ · 18 unmodified lines
1919 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tPluck ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
2020 void tPluck_init (tPluck* const pl, float lowestFrequency)
2121 {
22− _tPluck* p = *pl = (_tPluck*) leaf_alloc(sizeof(_tPluck));
23−
24− if ( lowestFrequency <= 0.0f ) lowestFrequency = 10.0f;
25−
26− tNoise_init(&p->noise, WhiteNoise);
27−
28− tOnePole_init(&p->pickFilter, 0.0f);
29−
30− tOneZero_init(&p->loopFilter, 0.0f);
31−
32− tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2);
33−
34− tPluck_setFrequency(pl, 220.0f);
22+ tPluck_initToPool(pl, lowestFrequency, &leaf_mempool);
3523 }
3624
3725 void tPluck_free (tPluck* const pl)
3826 {
39− _tPluck* p = *pl;
40−
41− tNoise_free(&p->noise);
42− tOnePole_free(&p->pickFilter);
43− tOneZero_free(&p->loopFilter);
44− tAllpassDelay_free(&p->delayLine);
45−
46− leaf_free(p);
27+ tPluck_freeFromPool(pl, &leaf_mempool);
4728 }
4829
4930 void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* const mp)
@@ -60,6 +41,7 @@ void tPluck_initToPool (tPluck* const pl, float lowestFrequency, tMempool* · 10 unmodified lines
6041 tOneZero_initToPool(&p->loopFilter, 0.0f, mp);
6142
6243 tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp);
44+ tAllpassDelay_clear(&p->delayLine);
6345
6446 tPluck_setFrequency(pl, 220.0f);
6547 }
@@ -157,48 +139,12 @@ void tPluckSampleRateChanged(tPluck* const pl) · 91 unmodified lines
157139 /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ tKarplusStrong ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
158140 void tKarplusStrong_init (tKarplusStrong* const pl, float lowestFrequency)
159141 {
160− _tKarplusStrong* p = *pl = (_tKarplusStrong*) leaf_alloc(sizeof(_tKarplusStrong));
161−
162− if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f;
163−
164− tAllpassDelay_init(&p->delayLine, 0.0f, leaf.sampleRate * 2);
165−
166− tLinearDelay_init(&p->combDelay, 0.0f, leaf.sampleRate * 2);
167−
168− tOneZero_init(&p->filter, 0.0f);
169−
170− tNoise_init(&p->noise, WhiteNoise);
171−
172− for (int i = 0; i < 4; i++)
173− {
174− tBiQuad_init(&p->biquad[i]);
175− }
176−
177− p->pluckAmplitude = 0.3f;
178− p->pickupPosition = 0.4f;
179−
180− p->stretching = 0.9999f;
181− p->baseLoopGain = 0.995f;
182− p->loopGain = 0.999f;
183−
184− tKarplusStrong_setFrequency( pl, 220.0f );
142+ tKarplusStrong_initToPool(pl, lowestFrequency, &leaf_mempool);
185143 }
186144
187145 void tKarplusStrong_free (tKarplusStrong* const pl)
188146 {
189− _tKarplusStrong* p = *pl;
190−
191− tAllpassDelay_free(&p->delayLine);
192− tLinearDelay_free(&p->combDelay);
193− tOneZero_free(&p->filter);
194− tNoise_free(&p->noise);
195−
196− for (int i = 0; i < 4; i++)
197− {
198− tBiQuad_free(&p->biquad[i]);
199− }
200−
201− leaf_free(p);
147+ tKarplusStrong_freeFromPool(pl, &leaf_mempool);
202148 }
203149
204150 void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequency, tMempool* const mp)
@@ -209,8 +155,10 @@ void tKarplusStrong_initToPool (tKarplusStrong* const pl, float lowestFrequ · 4 unmodified lines
209155 if ( lowestFrequency <= 0.0f ) lowestFrequency = 8.0f;
210156
211157 tAllpassDelay_initToPool(&p->delayLine, 0.0f, leaf.sampleRate * 2, mp);
158+ tAllpassDelay_clear(&p->delayLine);
212159
213160 tLinearDelay_initToPool(&p->combDelay, 0.0f, leaf.sampleRate * 2, mp);
161+ tLinearDelay_clear(&p->combDelay);
214162
215163 tOneZero_initToPool(&p->filter, 0.0f, mp);
216164
@@ -410,30 +358,12 @@ void tSimpleLivingString_init(tSimpleLivingString* const pl, float freq, floa · 193 unmodified lines
410358 float decay, float targetLev, float levSmoothFactor,
411359 float levStrength, int levMode)
412360 {
413− _tSimpleLivingString* p = *pl = (_tSimpleLivingString*) leaf_alloc(sizeof(_tSimpleLivingString));
414−
415− p->curr=0.0f;
416− tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions)
417− tSimpleLivingString_setFreq(pl, freq);
418− tLinearDelay_init(&p->delayLine,p->waveLengthInSamples, 2400);
419− tOnePole_init(&p->bridgeFilter, dampFreq);
420− tHighpass_init(&p->DCblocker,13);
421− p->decay=decay;
422− tFeedbackLeveler_init(&p->fbLev, targetLev, levSmoothFactor, levStrength, levMode);
423− p->levMode=levMode;
361+ tSimpleLivingString_initToPool(pl, freq, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf_mempool);
424362 }
425363
426364 void tSimpleLivingString_free(tSimpleLivingString* const pl)
427365 {
428− _tSimpleLivingString* p = *pl;
429−
430− tExpSmooth_free(&p->wlSmooth);
431− tLinearDelay_free(&p->delayLine);
432− tOnePole_free(&p->bridgeFilter);
433− tHighpass_free(&p->DCblocker);
434− tFeedbackLeveler_free(&p->fbLev);
435−
436− leaf_free(p);
366+ tSimpleLivingString_freeFromPool(pl, &leaf_mempool);
437367 }
438368
439369 void tSimpleLivingString_initToPool (tSimpleLivingString* const pl, float freq, float dampFreq,
@@ -447,6 +377,7 @@ void tSimpleLivingString_initToPool (tSimpleLivingString* const pl, float fr · 7 unmodified lines
447377 tExpSmooth_initToPool(&p->wlSmooth, leaf.sampleRate/freq, 0.01, mp); // smoother for string wavelength (not freq, to avoid expensive divisions)
448378 tSimpleLivingString_setFreq(pl, freq);
449379 tLinearDelay_initToPool(&p->delayLine,p->waveLengthInSamples, 2400, mp);
380+ tLinearDelay_clear(&p->delayLine);
450381 tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp);
451382 tHighpass_initToPool(&p->DCblocker,13, mp);
452383 p->decay=decay;
@@ -549,53 +480,11 @@ void tLivingString_init(tLivingString* const pl, float freq, float pickPos, f · 96 unmodified lines
549480 float dampFreq, float decay, float targetLev, float levSmoothFactor,
550481 float levStrength, int levMode)
551482 {
552− _tLivingString* p = *pl = (_tLivingString*) leaf_alloc(sizeof(_tLivingString));
553−
554− p->curr=0.0f;
555− tExpSmooth_init(&p->wlSmooth, leaf.sampleRate/freq, 0.01); // smoother for string wavelength (not freq, to avoid expensive divisions)
556− tLivingString_setFreq(pl, freq);
557− p->freq = freq;
558− tExpSmooth_init(&p->ppSmooth, pickPos, 0.01); // smoother for pick position
559− tLivingString_setPickPos(pl, pickPos);
560− p->prepIndex=prepIndex;
561− tLinearDelay_init(&p->delLF,p->waveLengthInSamples, 2400);
562− tLinearDelay_init(&p->delUF,p->waveLengthInSamples, 2400);
563− tLinearDelay_init(&p->delUB,p->waveLengthInSamples, 2400);
564− tLinearDelay_init(&p->delLB,p->waveLengthInSamples, 2400);
565− p->dampFreq = dampFreq;
566− tOnePole_init(&p->bridgeFilter, dampFreq);
567− tOnePole_init(&p->nutFilter, dampFreq);
568− tOnePole_init(&p->prepFilterU, dampFreq);
569− tOnePole_init(&p->prepFilterL, dampFreq);
570− tHighpass_init(&p->DCblockerU,13);
571− tHighpass_init(&p->DCblockerL,13);
572− p->decay=decay;
573− p->prepIndex = prepIndex;
574− tFeedbackLeveler_init(&p->fbLevU, targetLev, levSmoothFactor, levStrength, levMode);
575− tFeedbackLeveler_init(&p->fbLevL, targetLev, levSmoothFactor, levStrength, levMode);
576− p->levMode=levMode;
577−}
483+ tLivingString_initToPool(pl, fre, pickPos, prepIndex, dampFreq, decay, targetLev, levSmoothFactor, levStrength, levMode, &leaf_mempool);
578484
579485 void tLivingString_free(tLivingString* const pl)
580486 {
581− _tLivingString* p = *pl;
582−
583− tExpSmooth_free(&p->wlSmooth);
584− tExpSmooth_free(&p->ppSmooth);
585− tLinearDelay_free(&p->delLF);
586− tLinearDelay_free(&p->delUF);
587− tLinearDelay_free(&p->delUB);
588− tLinearDelay_free(&p->delLB);
589− tOnePole_free(&p->bridgeFilter);
590− tOnePole_free(&p->nutFilter);
591− tOnePole_free(&p->prepFilterU);
592− tOnePole_free(&p->prepFilterL);
593− tHighpass_free(&p->DCblockerU);
594− tHighpass_free(&p->DCblockerL);
595− tFeedbackLeveler_free(&p->fbLevU);
596− tFeedbackLeveler_free(&p->fbLevL);
597−
598− leaf_free(p);
487+ tLivingString_freeFromPool(pl, &leaf_mempool);
599488 }
600489
601490 void tLivingString_initToPool (tLivingString* const pl, float freq, float pickPos, float prepIndex,
@@ -616,6 +505,10 @@ void tLivingString_initToPool (tLivingString* const pl, float freq, float · 14 unmodified lines
616505 tLinearDelay_initToPool(&p->delUF,p->waveLengthInSamples, 2400, mp);
617506 tLinearDelay_initToPool(&p->delUB,p->waveLengthInSamples, 2400, mp);
618507 tLinearDelay_initToPool(&p->delLB,p->waveLengthInSamples, 2400, mp);
508+ tLinearDelay_clear(&p->delLF);
509+ tLinearDelay_clear(&p->delUF);
510+ tLinearDelay_clear(&p->delUB);
511+ tLinearDelay_clear(&p->delLB);
619512 p->dampFreq = dampFreq;
620513 tOnePole_initToPool(&p->bridgeFilter, dampFreq, mp);
621514 tOnePole_initToPool(&p->nutFilter, dampFreq, mp);

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