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/*==============================================================================1/*==============================================================================
2 2
3 In short, mpool is distributed under so called "BSD license",3 In short, mpool is distributed under so called "BSD license",
4 4
5 Copyright (c) 2009-2010 Tatsuhiko Kubo <cubicdaiya@gmail.com>5 Copyright (c) 2009-2010 Tatsuhiko Kubo <cubicdaiya@gmail.com>
@@ -29,31 +29,31 @@ · 23 unmodified lines
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 33
34 written by C99 style34 written by C99 style
35==============================================================================*/35==============================================================================*/
36 36
37#ifndef LEAF_MPOOL_H_INCLUDED37#ifndef LEAF_MPOOL_H_INCLUDED
38#define LEAF_MPOOL_H_INCLUDED38#define LEAF_MPOOL_H_INCLUDED
39 39
40#ifdef __cplusplus40#ifdef __cplusplus
41extern "C" {41extern "C" {
42#endif42#endif
43 43
44//==============================================================================44//==============================================================================
45 45
46#include <stdio.h>46#include <stdio.h>
47#include <stdlib.h>47#include <stdlib.h>
48#include <string.h>48#include <string.h>
49#include <stdbool.h>49#include <stdbool.h>
50 50
51//==============================================================================51//==============================================================================
52 52
53 53
54#define MPOOL_POOL_SIZE 50000054#define MPOOL_POOL_SIZE 50000
55 55
56#define MPOOL_ALIGN_SIZE (8)56#define MPOOL_ALIGN_SIZE (8)
57 57
58//#define size_t unsigned long58//#define size_t unsigned long
59 59
@@ -92,18 +92,18 @@ void leaf_free(void* ptr); · 32 unmodified lines
92size_t leaf_pool_get_size(void);92size_t leaf_pool_get_size(void);
93size_t leaf_pool_get_used(void);93size_t leaf_pool_get_used(void);
94 94
95void* leaf_pool_get_pool(void);95void* leaf_pool_get_pool(void);
96 96
97void leaf_mempool_overrun(void);97void leaf_mempool_overrun(void);
98 98
99//==============================================================================99//==============================================================================
100 100
101#ifdef __cplusplus101#ifdef __cplusplus
102}102}
103#endif103#endif
104 104
105#endif // LEAF_MPOOL_H105#endif // LEAF_MPOOL_H
106 106
107//==============================================================================107//==============================================================================
108 108
109 109
LEAF/Src/leaf-delay.c+161−163
@@ -61,7 +61,7 @@ float tDelay_tick (tDelay* const d, float input) · 60 unmodified lines
61 61
62int tDelay_setDelay (tDelay* const d, uint32_t delay)62int tDelay_setDelay (tDelay* const d, uint32_t delay)
63{63{
64 d->delay = LEAF_clip(0.0f, delay, d->maxDelay);64 d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
65 65
66 66
67 // read chases write67 // read chases write
@@ -161,15 +161,15 @@ float tDelayL_tick (tDelayL* const d, float input) · 93 unmodified lines
161 d->buff[d->inPoint] = input * d->gain;161 d->buff[d->inPoint] = input * d->gain;
162 162
163 // Increment input pointer modulo length.163 // Increment input pointer modulo length.
164 if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;164 if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
165 165
166 166
167 uint32_t idx = (uint32_t) d->outPoint;167 uint32_t idx = (uint32_t) d->outPoint;
168 168
169 d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],169 d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
170 d->buff[idx],170 d->buff[idx],
171 d->buff[(idx + 1) % d->maxDelay],171 d->buff[(idx + 1) % d->maxDelay],
172 d->buff[(idx + 2) % d->maxDelay],172 d->buff[(idx + 2) % d->maxDelay],
173 d->alpha);173 d->alpha);
174 174
175 // Increment output pointer modulo length175 // Increment output pointer modulo length
@@ -203,7 +203,7 @@ float tDelayL_tickOut (tDelayL* const d) · 27 unmodified lines
203}203}
204 204
205int tDelayL_setDelay (tDelayL* const d, float delay)205int tDelayL_setDelay (tDelayL* const d, float delay)
206{206{
207 d->delay = LEAF_clip(0.0f, delay, d->maxDelay);207 d->delay = LEAF_clip(0.0f, delay, d->maxDelay);
208 208
209 float outPointer = d->inPoint - d->delay;209 float outPointer = d->inPoint - d->delay;
@@ -226,20 +226,20 @@ float tDelayL_tapOut (tDelayL* const d, float tapDelay) · 16 unmodified lines
226 float tap = (float) d->inPoint - tapDelay - 1.f;226 float tap = (float) d->inPoint - tapDelay - 1.f;
227 227
228 // Check for wraparound.228 // Check for wraparound.
229 while ( tap < 0.f ) tap += (float)d->maxDelay;229 while ( tap < 0.f ) tap += (float)d->maxDelay;
230 230
231 float alpha = tap - (int)tap;231 float alpha = tap - (int)tap;
232 float omAlpha = 1.f - alpha;232 float omAlpha = 1.f - alpha;
233 233
234 int ptx = (int) tap;234 int ptx = (int) tap;
235 235
236 // First 1/2 of interpolation236 // First 1/2 of interpolation
237 float samp = d->buff[ptx] * omAlpha;237 float samp = d->buff[ptx] * omAlpha;
238 238
239 // Second 1/2 of interpolation239 // Second 1/2 of interpolation
240 if ((ptx + 1) < d->maxDelay)240 if ((ptx + 1) < d->maxDelay)
241 samp += d->buff[ptx+1] * d->alpha;241 samp += d->buff[ptx+1] * d->alpha;
242 else242 else
243 samp += d->buff[0] * d->alpha;243 samp += d->buff[0] * d->alpha;
244 244
245 return samp;245 return samp;
@@ -345,7 +345,7 @@ float tDelayA_tick (tDelayA* const d, float input) · 99 unmodified lines
345 345
346int tDelayA_setDelay (tDelayA* const d, float delay)346int tDelayA_setDelay (tDelayA* const d, float delay)
347{347{
348 d->delay = LEAF_clip(0.5f, delay, d->maxDelay);348 d->delay = LEAF_clip(0.5f, delay, d->maxDelay);
349 349
350 350
351 // outPoint chases inPoint351 // outPoint chases inPoint
@@ -431,142 +431,140 @@ void tDelayA_setGain (tDelayA* const d, float gain) · 79 unmodified lines
431float tDelayA_getGain (tDelayA* const d)431float tDelayA_getGain (tDelayA* const d)
432{432{
433 return d->gain;433 return d->gain;
434}434}
435 435
436// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //436// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TapeDelay ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ //
437void tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay)437void tTapeDelay_init (tTapeDelay* const d, float delay, uint32_t maxDelay)
438{438{
439 d->maxDelay = maxDelay;439 d->maxDelay = maxDelay;
440 440
441 d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);441 d->buff = (float*) leaf_alloc(sizeof(float) * maxDelay);
442 442
443 d->gain = 1.0f;443 d->gain = 1.0f;
444 444
445 d->lastIn = 0.0f;445 d->lastIn = 0.0f;
446 d->lastOut = 0.0f;446 d->lastOut = 0.0f;
447 447
448 d->idx = 0.0f;448 d->idx = 0.0f;
449 d->inc = 1.0f;449 d->inc = 1.0f;
450 d->inPoint = 0;450 d->inPoint = 0;
451 451
452 tTapeDelay_setDelay(d, delay);452 tTapeDelay_setDelay(d, delay);
453}453}
454 454
455void tTapeDelay_free(tTapeDelay* const d)455void tTapeDelay_free(tTapeDelay* const d)
456{456{
457 leaf_free(d->buff);457 leaf_free(d->buff);
458 leaf_free(d);458 leaf_free(d);
459}459}
460 460
461int count = 0;461//#define SMOOTH_FACTOR 10.f
462 462
463//#define SMOOTH_FACTOR 10.f463float tTapeDelay_tick (tTapeDelay* const d, float input)
464 464{
465float tTapeDelay_tick (tTapeDelay* const d, float input)465 d->buff[d->inPoint] = input * d->gain;
466{466
467 d->buff[d->inPoint] = input * d->gain;467 // Increment input pointer modulo length.
468 468 if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;
469 // Increment input pointer modulo length.469
470 if (++(d->inPoint) == d->maxDelay ) d->inPoint = 0;470 int idx = (int) d->idx;
471 471 float alpha = d->idx - idx;
472 int idx = (int) d->idx;472
473 float alpha = d->idx - idx;473 d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
474 474 d->buff[idx],
475 d->lastOut = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],475 d->buff[(idx + 1) % d->maxDelay],
476 d->buff[idx],476 d->buff[(idx + 2) % d->maxDelay],
477 d->buff[(idx + 1) % d->maxDelay],477 alpha);
478 d->buff[(idx + 2) % d->maxDelay],478
479 alpha);479 float diff = (d->inPoint - d->idx);
480 480 while (diff < 0.f) diff += d->maxDelay;
481 float diff = (d->inPoint - d->idx);481
482 while (diff < 0.f) diff += d->maxDelay;482 d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;
483 483
484 d->inc = 1.0f + (diff - d->delay) / d->delay; //* SMOOTH_FACTOR;484 d->idx += d->inc;
485 485
486 d->idx += d->inc;486 if (d->idx >= d->maxDelay) d->idx = 0.0f;
487 487
488 if (d->idx >= d->maxDelay) d->idx = 0.0f;488 return d->lastOut;
489 489}
490 return d->lastOut;490
491}491
492 492void tTapeDelay_setRate(tTapeDelay* const d, float rate)
493 493{
494void tTapeDelay_setRate(tTapeDelay* const d, float rate)494 d->inc = rate;
495{495}
496 d->inc = rate;496
497}497int tTapeDelay_setDelay (tTapeDelay* const d, float delay)
498 498{
499int tTapeDelay_setDelay (tTapeDelay* const d, float delay)499 d->delay = LEAF_clip(1.f, delay, d->maxDelay);
500{500
501 d->delay = LEAF_clip(1.f, delay, d->maxDelay);501 return 0;
502 502}
503 return 0;503
504}504float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay)
505 505{
506float tTapeDelay_tapOut (tTapeDelay* const d, float tapDelay)506 float tap = (float) d->inPoint - tapDelay - 1.f;
507{507
508 float tap = (float) d->inPoint - tapDelay - 1.f;508 // Check for wraparound.
509 509 while ( tap < 0.f ) tap += (float)d->maxDelay;
510 // Check for wraparound.510
511 while ( tap < 0.f ) tap += (float)d->maxDelay;511 int idx = (int) tap;
512 512
513 int idx = (int) tap;513 float alpha = tap - idx;
514 514
515 float alpha = tap - idx;515 float samp = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],
516 516 d->buff[idx],
517 float samp = LEAF_interpolate_hermite (d->buff[((idx - 1) + d->maxDelay) % d->maxDelay],517 d->buff[(idx + 1) % d->maxDelay],
518 d->buff[idx],518 d->buff[(idx + 2) % d->maxDelay],
519 d->buff[(idx + 1) % d->maxDelay],519 alpha);
520 d->buff[(idx + 2) % d->maxDelay],520
521 alpha);521 return samp;
522 522
523 return samp;523}
524 524
525}525void tTapeDelay_tapIn (tTapeDelay* const d, float value, uint32_t tapDelay)
526 526{
527void tTapeDelay_tapIn (tTapeDelay* const d, float value, uint32_t tapDelay)527 int32_t tap = d->inPoint - tapDelay - 1;
528{528
529 int32_t tap = d->inPoint - tapDelay - 1;529 // Check for wraparound.
530 530 while ( tap < 0 ) tap += d->maxDelay;
531 // Check for wraparound.531
532 while ( tap < 0 ) tap += d->maxDelay;532 d->buff[tap] = value;
533 533}
534 d->buff[tap] = value;534
535}535float tTapeDelay_addTo (tTapeDelay* const d, float value, uint32_t tapDelay)
536 536{
537float tTapeDelay_addTo (tTapeDelay* const d, float value, uint32_t tapDelay)537 int32_t tap = d->inPoint - tapDelay - 1;
538{538
539 int32_t tap = d->inPoint - tapDelay - 1;539 // Check for wraparound.
540 540 while ( tap < 0 ) tap += d->maxDelay;
541 // Check for wraparound.541
542 while ( tap < 0 ) tap += d->maxDelay;542 return (d->buff[tap] += value);
543 543}
544 return (d->buff[tap] += value);544
545}545float tTapeDelay_getDelay (tTapeDelay *d)
546 546{
547float tTapeDelay_getDelay (tTapeDelay *d)547 return d->delay;
548{548}
549 return d->delay;549
550}550float tTapeDelay_getLastOut (tTapeDelay* const d)
551 551{
552float tTapeDelay_getLastOut (tTapeDelay* const d)552 return d->lastOut;
553{553}
554 return d->lastOut;554
555}555float tTapeDelay_getLastIn (tTapeDelay* const d)
556 556{
557float tTapeDelay_getLastIn (tTapeDelay* const d)557 return d->lastIn;
558{558}
559 return d->lastIn;559
560}560void tTapeDelay_setGain (tTapeDelay* const d, float gain)
561 561{
562void tTapeDelay_setGain (tTapeDelay* const d, float gain)562 if (gain < 0.0f) d->gain = 0.0f;
563{563 else d->gain = gain;
564 if (gain < 0.0f) d->gain = 0.0f;564}
565 else d->gain = gain;565
566}566float tTapeDelay_getGain (tTapeDelay* const d)
567 567{
568float tTapeDelay_getGain (tTapeDelay* const d)568 return d->gain;
569{
570 return d->gain;
571}569}
572 570

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