History

reduced mempool size and removed variable count

Matthew Wang committed 7 years ago

Commit d4077051 parent 91710622 files · +186 −188Browse files

Unified · Split

2 files
  1. LEAF/Inc/leaf-mempool.h +25 −25
  2. LEAF/Src/leaf-delay.c +161 −163
LEAF/Inc/leaf-mempool.h+25−25
@@ -1,5 +1,5 @@
1−/*==============================================================================
2−
1+/*==============================================================================
2+
33 In short, mpool is distributed under so called "BSD license",
44
55 Copyright (c) 2009-2010 Tatsuhiko Kubo <cubicdaiya@gmail.com>
@@ -29,31 +29,31 @@ · 23 unmodified lines
2929 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3030 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3131 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32− SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33−
32+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
3434 written by C99 style
3535 ==============================================================================*/
3636
3737 #ifndef LEAF_MPOOL_H_INCLUDED
38−#define LEAF_MPOOL_H_INCLUDED
39−
40−#ifdef __cplusplus
41−extern "C" {
42−#endif
43−
38+#define LEAF_MPOOL_H_INCLUDED
39+
40+#ifdef __cplusplus
41+extern "C" {
42+#endif
43+
4444 //==============================================================================
4545
4646 #include <stdio.h>
4747 #include <stdlib.h>
4848 #include <string.h>
49−#include <stdbool.h>
50−
49+#include <stdbool.h>
50+
5151 //==============================================================================
5252
53−
54−#define MPOOL_POOL_SIZE 500000
55−
56−#define MPOOL_ALIGN_SIZE (8)
53+
54+#define MPOOL_POOL_SIZE 50000
55+
56+#define MPOOL_ALIGN_SIZE (8)
5757
5858 //#define size_t unsigned long
5959
@@ -92,18 +92,18 @@ void leaf_free(void* ptr); · 32 unmodified lines
9292 size_t leaf_pool_get_size(void);
9393 size_t leaf_pool_get_used(void);
9494
95−void* leaf_pool_get_pool(void);
96−
97−void leaf_mempool_overrun(void);
98−
95+void* leaf_pool_get_pool(void);
96+
97+void leaf_mempool_overrun(void);
98+
9999 //==============================================================================
100−
101−#ifdef __cplusplus
102−}
100+
101+#ifdef __cplusplus
102+}
103103 #endif
104104
105−#endif // LEAF_MPOOL_H
106−
105+#endif // LEAF_MPOOL_H
106+
107107 //==============================================================================
108108
109109
LEAF/Src/leaf-delay.c+161−163
@@ -61,7 +61,7 @@ float tDelay_tick (tDelay* const d, float input) · 60 unmodified lines
6161
6262 int tDelay_setDelay (tDelay* const d, uint32_t delay)
6363 {
64− d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
64+ d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
6565
6666
6767 // read chases write
@@ -161,15 +161,15 @@ float tDelayL_tick (tDelayL* const d, float input) · 93 unmodified lines
161161 d->buff[d->inPoint] = input * d->gain;
162162
163163 // Increment input pointer modulo length.
164− if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
165−
166−
167− uint32_t idx = (uint32_t) d->outPoint;
168−
169− d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
170− d->buff[idx],
171− d->buff[(idx + 1) % d->maxDelay],
172− d->buff[(idx + 2) % d->maxDelay],
164+ if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
165+
166+
167+ uint32_t idx = (uint32_t) d->outPoint;
168+
169+ d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
170+ d->buff[idx],
171+ d->buff[(idx + 1) % d->maxDelay],
172+ d->buff[(idx + 2) % d->maxDelay],
173173 d->alpha);
174174
175175 // Increment output pointer modulo length
@@ -203,7 +203,7 @@ float tDelayL_tickOut (tDelayL* const d) · 27 unmodified lines
203203 }
204204
205205 int tDelayL_setDelay (tDelayL* const d, float delay)
206−{
206+{
207207 d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
208208
209209 float outPointer = d->inPoint - d->delay;
@@ -226,20 +226,20 @@ float tDelayL_tapOut (tDelayL* const d, float tapDelay) · 16 unmodified lines
226226 float tap = (float) d->inPoint - tapDelay - 1.f;
227227
228228 // Check for wraparound.
229− while ( tap < 0.f ) tap += (float)d->maxDelay;
230−
231− float alpha = tap - (int)tap;
232− float omAlpha = 1.f - alpha;
233−
234− int ptx = (int) tap;
235−
236− // First 1/2 of interpolation
237− float samp = d->buff[ptx] * omAlpha;
238−
239− // Second 1/2 of interpolation
240− if ((ptx + 1) < d->maxDelay)
241− samp += d->buff[ptx+1] * d->alpha;
242− else
229+ while ( tap < 0.f ) tap += (float)d->maxDelay;
230+
231+ float alpha = tap - (int)tap;
232+ float omAlpha = 1.f - alpha;
233+
234+ int ptx = (int) tap;
235+
236+ // First 1/2 of interpolation
237+ float samp = d->buff[ptx] * omAlpha;
238+
239+ // Second 1/2 of interpolation
240+ if ((ptx + 1) < d->maxDelay)
241+ samp += d->buff[ptx+1] * d->alpha;
242+ else
243243 samp += d->buff[0] * d->alpha;
244244
245245 return samp;
@@ -345,7 +345,7 @@ float tDelayA_tick (tDelayA* const d, float input) · 99 unmodified lines
345345
346346 int tDelayA_setDelay (tDelayA* const d, float delay)
347347 {
348− d->delay = LEAF_clip(0.5f, delay, d->maxDelay);
348+ d->delay = LEAF_clip(0.5f, delay, d->maxDelay);
349349
350350
351351 // outPoint chases inPoint
@@ -431,142 +431,140 @@ void tDelayA_setGain (tDelayA* const d, float gain) · 79 unmodified lines
431431 float tDelayA_getGain (tDelayA* const d)
432432 {
433433 return d->gain;
434−}
435−
436−// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
437−void tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay)
438−{
439− d->maxDelay = maxDelay;
440−
441− d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
442−
443− d->gain = 1.0f;
444−
445− d->lastIn = 0.0f;
446− d->lastOut = 0.0f;
447−
448− d->idx = 0.0f;
449− d->inc = 1.0f;
450− d->inPoint = 0;
451−
452− tTapeDelay_setDelay(d, delay);
453−}
454−
455−void tTapeDelay_free(tTapeDelay* const d)
456−{
457− leaf_free(d->buff);
458− leaf_free(d);
459−}
460−
461−int count = 0;
462−
463−//#define SMOOTH_FACTOR 10.f
464−
465−float tTapeDelay_tick (tTapeDelay* const d, float input)
466−{
467− d->buff[d->inPoint] = input * d->gain;
468−
469− // Increment input pointer modulo length.
470− if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
471−
472− int idx = (int) d->idx;
473− float alpha = d->idx - idx;
474−
475− d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
476− d->buff[idx],
477− d->buff[(idx + 1) % d->maxDelay],
478− d->buff[(idx + 2) % d->maxDelay],
479− alpha);
480−
481− float diff = (d->inPoint - d->idx);
482− while (diff < 0.f) diff += d->maxDelay;
483−
484− d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
485−
486− d->idx += d->inc;
487−
488− if (d->idx >= d->maxDelay) d->idx = 0.0f;
489−
490− return d->lastOut;
491−}
492−
493−
494−void tTapeDelay_setRate(tTapeDelay* const d, float rate)
495−{
496− d->inc = rate;
497−}
498−
499−int tTapeDelay_setDelay (tTapeDelay* const d, float delay)
500−{
501− d->delay = LEAF_clip(1.f, delay, d->maxDelay);
502−
503− return 0;
504−}
505−
506−float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay)
507−{
508− float tap = (float) d->inPoint - tapDelay - 1.f;
509−
510− // Check for wraparound.
511− while ( tap < 0.f ) tap += (float)d->maxDelay;
512−
513− int idx = (int) tap;
514−
515− float alpha = tap - idx;
516−
517− float samp = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
518− d->buff[idx],
519− d->buff[(idx + 1) % d->maxDelay],
520− d->buff[(idx + 2) % d->maxDelay],
521− alpha);
522−
523− return samp;
524−
525−}
526−
527−void tTapeDelay_tapIn (tTapeDelay* const d, float value, uint32_t tapDelay)
528−{
529− int32_t tap = d->inPoint - tapDelay - 1;
530−
531− // Check for wraparound.
532− while ( tap < 0 ) tap += d->maxDelay;
533−
534− d->buff[tap] = value;
535−}
536−
537−float tTapeDelay_addTo (tTapeDelay* const d, float value, uint32_t tapDelay)
538−{
539− int32_t tap = d->inPoint - tapDelay - 1;
540−
541− // Check for wraparound.
542− while ( tap < 0 ) tap += d->maxDelay;
543−
544− return (d->buff[tap] += value);
545−}
546−
547−float tTapeDelay_getDelay (tTapeDelay *d)
548−{
549− return d->delay;
550−}
551−
552−float tTapeDelay_getLastOut (tTapeDelay* const d)
553−{
554− return d->lastOut;
555−}
556−
557−float tTapeDelay_getLastIn (tTapeDelay* const d)
558−{
559− return d->lastIn;
560−}
561−
562−void tTapeDelay_setGain (tTapeDelay* const d, float gain)
563−{
564− if (gain < 0.0f) d->gain = 0.0f;
565− else d->gain = gain;
566−}
567−
568−float tTapeDelay_getGain (tTapeDelay* const d)
569−{
570− return d->gain;
434+}
435+
436+// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
437+void tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay)
438+{
439+ d->maxDelay = maxDelay;
440+
441+ d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
442+
443+ d->gain = 1.0f;
444+
445+ d->lastIn = 0.0f;
446+ d->lastOut = 0.0f;
447+
448+ d->idx = 0.0f;
449+ d->inc = 1.0f;
450+ d->inPoint = 0;
451+
452+ tTapeDelay_setDelay(d, delay);
453+}
454+
455+void tTapeDelay_free(tTapeDelay* const d)
456+{
457+ leaf_free(d->buff);
458+ leaf_free(d);
459+}
460+
461+//#define SMOOTH_FACTOR 10.f
462+
463+float tTapeDelay_tick (tTapeDelay* const d, float input)
464+{
465+ d->buff[d->inPoint] = input * d->gain;
466+
467+ // Increment input pointer modulo length.
468+ if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
469+
470+ int idx = (int) d->idx;
471+ float alpha = d->idx - idx;
472+
473+ d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
474+ d->buff[idx],
475+ d->buff[(idx + 1) % d->maxDelay],
476+ d->buff[(idx + 2) % d->maxDelay],
477+ alpha);
478+
479+ float diff = (d->inPoint - d->idx);
480+ while (diff < 0.f) diff += d->maxDelay;
481+
482+ d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
483+
484+ d->idx += d->inc;
485+
486+ if (d->idx >= d->maxDelay) d->idx = 0.0f;
487+
488+ return d->lastOut;
489+}
490+
491+
492+void tTapeDelay_setRate(tTapeDelay* const d, float rate)
493+{
494+ d->inc = rate;
495+}
496+
497+int tTapeDelay_setDelay (tTapeDelay* const d, float delay)
498+{
499+ d->delay = LEAF_clip(1.f, delay, d->maxDelay);
500+
501+ return 0;
502+}
503+
504+float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay)
505+{
506+ float tap = (float) d->inPoint - tapDelay - 1.f;
507+
508+ // Check for wraparound.
509+ while ( tap < 0.f ) tap += (float)d->maxDelay;
510+
511+ int idx = (int) tap;
512+
513+ float alpha = tap - idx;
514+
515+ float samp = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
516+ d->buff[idx],
517+ d->buff[(idx + 1) % d->maxDelay],
518+ d->buff[(idx + 2) % d->maxDelay],
519+ alpha);
520+
521+ return samp;
522+
523+}
524+
525+void tTapeDelay_tapIn (tTapeDelay* const d, float value, uint32_t tapDelay)
526+{
527+ int32_t tap = d->inPoint - tapDelay - 1;
528+
529+ // Check for wraparound.
530+ while ( tap < 0 ) tap += d->maxDelay;
531+
532+ d->buff[tap] = value;
533+}
534+
535+float tTapeDelay_addTo (tTapeDelay* const d, float value, uint32_t tapDelay)
536+{
537+ int32_t tap = d->inPoint - tapDelay - 1;
538+
539+ // Check for wraparound.
540+ while ( tap < 0 ) tap += d->maxDelay;
541+
542+ return (d->buff[tap] += value);
543+}
544+
545+float tTapeDelay_getDelay (tTapeDelay *d)
546+{
547+ return d->delay;
548+}
549+
550+float tTapeDelay_getLastOut (tTapeDelay* const d)
551+{
552+ return d->lastOut;
553+}
554+
555+float tTapeDelay_getLastIn (tTapeDelay* const d)
556+{
557+ return d->lastIn;
558+}
559+
560+void tTapeDelay_setGain (tTapeDelay* const d, float gain)
561+{
562+ if (gain < 0.0f) d->gain = 0.0f;
563+ else d->gain = gain;
564+}
565+
566+float tTapeDelay_getGain (tTapeDelay* const d)
567+{
568+ return d->gain;
571569 }
572570

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