History

leaf version used in vocodec that was sent to beta testers

spiricom committed 6 years ago

Commit 5c365ac1 parent 99c38dd5 files · +123 −108Browse files

Unified · Split

5 files
  1. leaf/Inc/leaf-filters.h +0 −1
  2. leaf/Src/leaf-delay.c +88 −88
  3. leaf/Src/leaf-effects.c +3 −1
  4. leaf/Src/leaf-envelopes.c +6 −0
  5. leaf/Src/leaf-sampling.c +26 −18
leaf/Inc/leaf-filters.h+0−1
@@ -415,7 +415,6 @@ extern "C" { · 414 unmodified lines
415415 float cL, cB, cH; // coefficients for low-, band-, and highpass signals
416416
417417 // parameters:
418− float fs; // sample-rate
419418 float fc; // characteristic frequency
420419 float G; // gain
421420 float invG; //1/gain
leaf/Src/leaf-delay.c+88−88
@@ -33,11 +33,11 @@ void tDelay_initToPool (tDelay* const dl, uint32_t delay, uint32_t maxDelay · 32 unmodified lines
3333 {
3434 _tMempool* m = *mp;
3535 _tDelay* d = *dl = (_tDelay*) mpool_alloc(sizeof(_tDelay), m);
36−
36+
3737 d->maxDelay = maxDelay;
38−
38+
3939 d->delay = delay;
40−
40+
4141 d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, m);
4242
4343 d->inPoint = 0;
@@ -72,49 +72,49 @@ void tDelay_clear(tDelay* const dl) · 28 unmodified lines
7272 float tDelay_tick (tDelay* const dl, float input)
7373 {
7474 _tDelay* d = *dl;
75−
75+
7676 // Input
7777 d->lastIn = input;
7878 d->buff[d->inPoint] = input * d->gain;
7979 if (++(d->inPoint) == d->maxDelay) d->inPoint = 0;
80−
80+
8181 // Output
8282 d->lastOut = d->buff[d->outPoint];
8383 if (++(d->outPoint) == d->maxDelay) d->outPoint = 0;
84−
84+
8585 return d->lastOut;
8686 }
8787
8888 int tDelay_setDelay (tDelay* const dl, uint32_t delay)
8989 {
9090 _tDelay* d = *dl;
91−
91+
9292 d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
93−
93+
9494 // read chases write
9595 if ( d->inPoint >= delay ) d->outPoint = d->inPoint - d->delay;
9696 else d->outPoint = d->maxDelay + d->inPoint - d->delay;
97−
97+
9898 return 0;
9999 }
100100
101101 float tDelay_tapOut (tDelay* const dl, uint32_t tapDelay)
102102 {
103103 _tDelay* d = *dl;
104−
104+
105105 int32_t tap = d->inPoint - tapDelay - 1;
106−
106+
107107 // Check for wraparound.
108108 while ( tap < 0 ) tap += d->maxDelay;
109−
109+
110110 return d->buff[tap];
111−
111+
112112 }
113113
114114 void tDelay_tapIn (tDelay* const dl, float value, uint32_t tapDelay)
115115 {
116116 _tDelay* d = *dl;
117−
117+
118118 int32_t tap = d->inPoint - tapDelay - 1;
119119
120120 // Check for wraparound.
@@ -181,17 +181,17 @@ void tLinearDelay_initToPool (tLinearDelay* const dl, float delay, uint32_t · 60 unmodified lines
181181 {
182182 _tMempool* m = *mp;
183183 _tLinearDelay* d = *dl = (_tLinearDelay*) mpool_alloc(sizeof(_tLinearDelay), m);
184−
184+
185185 d->maxDelay = maxDelay;
186−
186+
187187 if (delay > maxDelay) d->delay = maxDelay;
188188 else if (delay < 0.0f) d->delay = 0.0f;
189189 else d->delay = delay;
190−
190+
191191 d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, m);
192−
192+
193193 d->gain = 1.0f;
194−
194+
195195 d->lastIn = 0.0f;
196196 d->lastOut = 0.0f;
197197
@@ -222,9 +222,9 @@ void tLinearDelay_clear(tLinearDelay* const dl) · 24 unmodified lines
222222 float tLinearDelay_tick (tLinearDelay* const dl, float input)
223223 {
224224 _tLinearDelay* d = *dl;
225−
225+
226226 d->buff[d->inPoint] = input * d->gain;
227−
227+
228228 // Increment input pointer modulo length.
229229 if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
230230
@@ -239,14 +239,14 @@ float tLinearDelay_tick (tLinearDelay* const dl, float input) · 8 unmodified lines
239239
240240 // Increment output pointer modulo length
241241 if ( (++d->outPoint) >= d->maxDelay ) d->outPoint = 0;
242−
242+
243243 return d->lastOut;
244244 }
245245
246246 void tLinearDelay_tickIn (tLinearDelay* const dl, float input)
247247 {
248248 _tLinearDelay* d = *dl;
249−
249+
250250 d->buff[d->inPoint] = input * d->gain;
251251
252252 // Increment input pointer modulo length.
@@ -256,7 +256,7 @@ void tLinearDelay_tickIn (tLinearDelay* const dl, float input) · 3 unmodified lines
256256 float tLinearDelay_tickOut (tLinearDelay* const dl)
257257 {
258258 _tLinearDelay* d = *dl;
259−
259+
260260 uint32_t idx = (uint32_t) d->outPoint;
261261 // First 1/2 of interpolation
262262 d->lastOut = d->buff[idx] * d->omAlpha;
@@ -275,53 +275,53 @@ float tLinearDelay_tickOut (tLinearDelay* const dl) · 12 unmodified lines
275275 int tLinearDelay_setDelay (tLinearDelay* const dl, float delay)
276276 {
277277 _tLinearDelay* d = *dl;
278−
278+
279279 d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
280−
280+
281281 float outPointer = d->inPoint - d->delay;
282−
282+
283283 while ( outPointer < 0 )
284284 outPointer += d->maxDelay; // modulo maximum length
285−
285+
286286 d->outPoint = (uint32_t) outPointer; // integer part
287−
287+
288288 d->alpha = outPointer - d->outPoint; // fractional part
289289 d->omAlpha = 1.0f - d->alpha;
290−
290+
291291 if ( d->outPoint == d->maxDelay ) d->outPoint = 0;
292−
292+
293293 return 0;
294294 }
295295
296296 float tLinearDelay_tapOut (tLinearDelay* const dl, uint32_t tapDelay)
297297 {
298298 _tLinearDelay* d = *dl;
299−
299+
300300 uint32_t tap = d->inPoint - tapDelay - 1;
301301 // Check for wraparound.
302302 while ( tap < 0 ) tap += d->maxDelay;
303−
303+
304304 return d->buff[tap];
305305 }
306306
307307 void tLinearDelay_tapIn (tLinearDelay* const dl, float value, uint32_t tapDelay)
308308 {
309309 _tLinearDelay* d = *dl;
310−
310+
311311 uint32_t tap = d->inPoint - tapDelay - 1;
312−
312+
313313 // Check for wraparound.
314314 while ( tap < 0 ) tap += d->maxDelay;
315−
315+
316316 d->buff[tap] = value;
317317 }
318318
319319 float tLinearDelay_addTo (tLinearDelay* const dl, float value, uint32_t tapDelay)
320320 {
321321 _tLinearDelay* d = *dl;
322−
322+
323323 int32_t tap = d->inPoint - tapDelay - 1;
324−
324+
325325 // Check for wraparound.
326326 while ( tap < 0 ) tap += d->maxDelay;
327327
@@ -579,15 +579,15 @@ void tAllpassDelay_initToPool (tAllpassDelay* const dl, float delay, uint32_ · 251 unmodified lines
579579 {
580580 _tMempool* m = *mp;
581581 _tAllpassDelay* d = *dl = (_tAllpassDelay*) mpool_alloc(sizeof(_tAllpassDelay), m);
582−
582+
583583 d->maxDelay = maxDelay;
584−
584+
585585 if (delay > maxDelay) d->delay = maxDelay;
586586 else if (delay < 0.0f) d->delay = 0.0f;
587587 else d->delay = delay;
588−
588+
589589 d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, m);
590−
590+
591591 d->gain = 1.0f;
592592
593593 d->lastIn = 0.0f;
@@ -622,43 +622,43 @@ void tAllpassDelay_clear(tAllpassDelay* const dl) · 28 unmodified lines
622622 float tAllpassDelay_tick (tAllpassDelay* const dl, float input)
623623 {
624624 _tAllpassDelay* d = *dl;
625−
625+
626626 d->buff[d->inPoint] = input * d->gain;
627−
627+
628628 // Increment input pointer modulo length.
629629 if ( ++(d->inPoint) >= d->maxDelay ) d->inPoint = 0;
630−
630+
631631 // Do allpass interpolation delay.
632632 float out = d->lastOut * -d->coeff;
633633 out += d->apInput + ( d->coeff * d->buff[d->outPoint] );
634634 d->lastOut = out;
635−
635+
636636 // Save allpass input
637637 d->apInput = d->buff[d->outPoint];
638−
638+
639639 // Increment output pointer modulo length.
640640 if (++(d->outPoint) >= d->maxDelay ) d->outPoint = 0;
641−
641+
642642 return d->lastOut;
643643 }
644644
645645 int tAllpassDelay_setDelay (tAllpassDelay* const dl, float delay)
646646 {
647647 _tAllpassDelay* d = *dl;
648−
648+
649649 d->delay = LEAF_clip(0.5f, delay, d->maxDelay);
650−
650+
651651 // outPoint chases inPoint
652652 float outPointer = (float)d->inPoint - d->delay + 1.0f;
653−
653+
654654 while ( outPointer < 0 ) outPointer += d->maxDelay; // mod max length
655−
655+
656656 d->outPoint = (uint32_t) outPointer; // integer part
657−
657+
658658 if ( d->outPoint >= d->maxDelay ) d->outPoint = 0;
659−
659+
660660 d->alpha = 1.0f + (float)d->outPoint - outPointer; // fractional part
661−
661+
662662 if ( d->alpha < 0.5f )
663663 {
664664 // The optimal range for alpha is about 0.5 - 1.5 in order to
@@ -670,46 +670,46 @@ int tAllpassDelay_setDelay (tAllpassDelay* const dl, float delay) · 5 unmodified lines
670670
671671 d->alpha += 1.0f;
672672 }
673−
673+
674674 d->coeff = (1.0f - d->alpha) / (1.0f + d->alpha); // coefficient for allpass
675−
675+
676676 return 0;
677677 }
678678
679679 float tAllpassDelay_tapOut (tAllpassDelay* const dl, uint32_t tapDelay)
680680 {
681681 _tAllpassDelay* d = *dl;
682−
682+
683683 int32_t tap = d->inPoint - tapDelay - 1;
684−
684+
685685 // Check for wraparound.
686686 while ( tap < 0 ) tap += d->maxDelay;
687−
687+
688688 return d->buff[tap];
689−
689+
690690 }
691691
692692 void tAllpassDelay_tapIn (tAllpassDelay* const dl, float value, uint32_t tapDelay)
693693 {
694694 _tAllpassDelay* d = *dl;
695−
695+
696696 int32_t tap = d->inPoint - tapDelay - 1;
697−
697+
698698 // Check for wraparound.
699699 while ( tap < 0 ) tap += d->maxDelay;
700−
700+
701701 d->buff[tap] = value;
702702 }
703703
704704 float tAllpassDelay_addTo (tAllpassDelay* const dl, float value, uint32_t tapDelay)
705705 {
706706 _tAllpassDelay* d = *dl;
707−
707+
708708 int32_t tap = d->inPoint - tapDelay - 1;
709−
709+
710710 // Check for wraparound.
711711 while ( tap < 0 ) tap += d->maxDelay;
712−
712+
713713 return (d->buff[tap] += value);
714714 }
715715
@@ -759,20 +759,20 @@ void tTapeDelay_initToPool (tTapeDelay* const dl, float delay, uint32_t maxD · 43 unmodified lines
759759 {
760760 _tMempool* m = *mp;
761761 _tTapeDelay* d = *dl = (_tTapeDelay*) mpool_alloc(sizeof(_tTapeDelay), m);
762−
762+
763763 d->maxDelay = maxDelay;
764−
764+
765765 d->buff = (float*) mpool_alloc(sizeof(float) * maxDelay, m);
766−
766+
767767 d->gain = 1.0f;
768−
768+
769769 d->lastIn = 0.0f;
770770 d->lastOut = 0.0f;
771−
771+
772772 d->idx = 0.0f;
773773 d->inc = 1.0f;
774774 d->inPoint = 0;
775−
775+
776776 tTapeDelay_setDelay(dl, delay);
777777 }
778778
@@ -780,7 +780,7 @@ void tTapeDelay_freeFromPool(tTapeDelay* const dl, tMempool* const mp) · 1 unmodified line
780780 {
781781 _tMempool* m = *mp;
782782 _tTapeDelay* d = *dl;
783−
783+
784784 mpool_free((char*)d->buff, m);
785785 mpool_free((char*)d, m);
786786 }
@@ -799,28 +799,28 @@ void tTapeDelay_clear(tTapeDelay* const dl) · 12 unmodified lines
799799 float tTapeDelay_tick (tTapeDelay* const dl, float input)
800800 {
801801 _tTapeDelay* d = *dl;
802−
802+
803803 d->buff[d->inPoint] = input * d->gain;
804−
804+
805805 // Increment input pointer modulo length.
806806 if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
807807
808808 int idx = (int) d->idx;
809809 float alpha = d->idx - idx;
810−
810+
811811 d->lastOut = LEAF_interpolate_hermite_x (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
812812 d->buff[idx],
813813 d->buff[(idx + 1) % d->maxDelay],
814814 d->buff[(idx + 2) % d->maxDelay],
815815 alpha);
816−
816+
817817 float diff = (d->inPoint - d->idx);
818818 while (diff < 0.f) diff += d->maxDelay;
819−
819+
820820 d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
821821
822822 d->idx += d->inc;
823−
823+
824824 if (d->idx >= d->maxDelay) d->idx = 0.0f;
825825
826826 if (d->lastOut)
@@ -851,30 +851,30 @@ void tTapeDelay_setDelay (tTapeDelay* const dl, float delay) · 24 unmodified lines
851851 float tTapeDelay_tapOut (tTapeDelay* const dl, float tapDelay)
852852 {
853853 _tTapeDelay* d = *dl;
854−
854+
855855 float tap = (float) d->inPoint - tapDelay - 1.f;
856−
856+
857857 // Check for wraparound.
858858 while ( tap < 0.f ) tap += (float)d->maxDelay;
859−
859+
860860 int idx = (int) tap;
861−
861+
862862 float alpha = tap - idx;
863−
863+
864864 float samp = LEAF_interpolate_hermite_x (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
865865 d->buff[idx],
866866 d->buff[(idx + 1) % d->maxDelay],
867867 d->buff[(idx + 2) % d->maxDelay],
868868 alpha);
869−
869+
870870 return samp;
871−
871+
872872 }
873873
874874 void tTapeDelay_tapIn (tTapeDelay* const dl, float value, uint32_t tapDelay)
875875 {
876876 _tTapeDelay* d = *dl;
877−
877+
878878 int32_t tap = d->inPoint - tapDelay - 1;
879879
880880 // Check for wraparound.
leaf/Src/leaf-effects.c+3−1
@@ -859,12 +859,14 @@ float tVocoder_tick (tVocoder* const voc, float synth, float voice) · 858 unmodified lines
859859
860860 v->kout = oo;
861861 v->kval = k & 0x1;
862+#ifdef NO_DENORMAL_CHECK
863+#else
862864 if(fabs(v->f[0][11])<1.0e-10) v->f[0][11] = 0.0f; //catch HF envelope denormal
863865
864866 for(i=1;i<nb;i++)
865867 if(fabs(v->f[i][3])<1.0e-10 || fabs(v->f[i][7])<1.0e-10)
866868 for(k=3; k<12; k++) v->f[i][k] = 0.0f; //catch reson & envelope denormals
867−
869+#endif
868870 if(fabs(o)>10.0f) tVocoder_suspend(voc); //catch instability
869871
870872 return o;
leaf/Src/leaf-envelopes.c+6−0
@@ -1559,7 +1559,10 @@ float tSlide_tickNoInput(tSlide* const sl) · 1558 unmodified lines
15591559 {
15601560 s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide);
15611561 }
1562+#ifdef NO_DENORMAL_CHECK
1563+#else
15621564 if (s->currentOut < VSF) s->currentOut = 0.0f;
1565+#endif
15631566 s->prevIn = in;
15641567 s->prevOut = s->currentOut;
15651568 return s->currentOut;
@@ -1578,7 +1581,10 @@ float tSlide_tick(tSlide* const sl, float in) · 12 unmodified lines
15781581 {
15791582 s->currentOut = s->prevOut + ((in - s->prevOut) * s->invDownSlide);
15801583 }
1584+#ifdef NO_DENORMAL_CHECK
1585+#else
15811586 if (s->currentOut < VSF) s->currentOut = 0.0f;
1587+#endif
15821588 s->prevIn = in;
15831589 s->prevOut = s->currentOut;
15841590 return s->currentOut;
leaf/Src/leaf-sampling.c+26−18
@@ -268,12 +268,12 @@ float tSampler_tick (tSampler* const sp) · 267 unmodified lines
268268 float* buff = p->samp->buff;
269269
270270 // Variables so start is also before end
271− int32_t start = p->start;
272− int32_t end = p->end;
271+ int myStart = p->start;
272+ int myEnd = p->end;
273273 if (p->flip < 0)
274274 {
275− start = p->end;
276− end = p->start;
275+ myStart = p->end;
276+ myEnd = p->start;
277277 }
278278
279279 // Get the direction and a reverse flag for some calcs
@@ -306,17 +306,17 @@ float tSampler_tick (tSampler* const sp) · 26 unmodified lines
306306 buff[i4],
307307 alpha);
308308
309− uint32_t cfxlen = p->cfxlen;
309+ int32_t cfxlen = p->cfxlen;
310310 if (p->len * 0.25f < cfxlen) cfxlen = p->len * 0.25f;
311311
312312 // Determine crossfade points
313− uint32_t fadeLeftStart = 0;
314− if (start >= cfxlen) fadeLeftStart = start - cfxlen;
315− uint32_t fadeLeftEnd = fadeLeftStart + cfxlen;
313+ int32_t fadeLeftStart = 0;
314+ if (myStart >= cfxlen) fadeLeftStart = myStart - cfxlen;
315+ int32_t fadeLeftEnd = fadeLeftStart + cfxlen;
316316
317− uint32_t fadeRightEnd = end;// + (fadeLeftEnd - start);
317+ int32_t fadeRightEnd = myEnd;// + (fadeLeftEnd - start);
318318 // if (fadeRightEnd >= length) fadeRightEnd = length - 1;
319− uint32_t fadeRightStart = fadeRightEnd - cfxlen;
319+ int32_t fadeRightStart = fadeRightEnd - cfxlen;
320320
321321
322322
@@ -401,7 +401,7 @@ float tSampler_tick (tSampler* const sp) · 78 unmodified lines
401401 }
402402 }
403403
404− float inc = fmod(p->inc, p->len);
404+ float inc = fmodf(p->inc, (float)p->len);
405405 p->idx += (dir * inc);
406406 if (p->flipStart >= 0)
407407 {
@@ -424,11 +424,11 @@ float tSampler_tick (tSampler* const sp) · 16 unmodified lines
424424
425425 if (p->mode == PlayLoop)
426426 {
427− if((int)p->idx < start)
427+ if((int)p->idx < myStart)
428428 {
429429 p->idx += (float)(fadeRightEnd - fadeLeftEnd);
430430 }
431− if((int)p->idx > end)
431+ if((int)p->idx > myEnd)
432432 {
433433
434434 p->idx -= (float)(fadeRightEnd - fadeLeftEnd);
@@ -436,22 +436,30 @@ float tSampler_tick (tSampler* const sp) · 1 unmodified line
436436 }
437437 else if (p->mode == PlayBackAndForth)
438438 {
439− if (p->idx < start)
439+ if (p->idx < myStart)
440440 {
441441 p->bnf = -p->bnf;
442− p->idx = start + 1;
442+ p->idx = myStart + 1;
443443 }
444− else if (p->idx > end)
444+ else if (p->idx > myEnd)
445445 {
446446 p->bnf = -p->bnf;
447− p->idx = end - 1;
447+ p->idx = myEnd - 1;
448448 }
449449 }
450450
451451
452452 if (p->mode == PlayNormal)
453453 {
454− float ticksToEnd = rev ? ((idx - start) * p->iinc) : ((end - idx) * p->iinc);
454+ if (p->idx < myStart)
455+ {
456+ p->idx = myStart;
457+ }
458+ else if (p->idx > myEnd)
459+ {
460+ p->idx = myEnd;
461+ }
462+ float ticksToEnd = rev ? ((idx - myStart) * p->iinc) : ((myEnd - idx) * p->iinc);
455463 if (ticksToEnd < (0.007f * leaf.sampleRate))
456464 {
457465 tRamp_setDest(&p->gain, 0.f);

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