Unified · Split
| @@ -113,6 +113,8 @@ extern "C" { · 112 unmodified lines | ||
| 113 | 113 | |
| 114 | 114 | //============================================================================== |
| 115 | 115 | |
| 116 | + extern tMempool leaf_mempool; | |
| 117 | + | |
| 116 | 118 | #ifdef __cplusplus |
| 117 | 119 | } |
| 118 | 120 | #endif |
| @@ -21,6 +21,7 @@ extern "C" { · 20 unmodified lines | ||
| 21 | 21 | #include "leaf-mempool.h" |
| 22 | 22 | #include "leaf-envelopes.h" |
| 23 | 23 | #include "leaf-mempool.h" |
| 24 | +#include "leaf-analysis.h" | |
| 24 | 25 | |
| 25 | 26 | //============================================================================== |
| 26 | 27 | |
| @@ -132,6 +133,40 @@ extern "C" { · 105 unmodified lines | ||
| 132 | 133 | |
| 133 | 134 | //============================================================================== |
| 134 | 135 | |
| 136 | + typedef struct _tAutoSampler | |
| 137 | + { | |
| 138 | + tSampler sampler; | |
| 139 | + tEnvelopeFollower ef; | |
| 140 | + uint32_t windowSize; | |
| 141 | + float threshold; | |
| 142 | + float previousPower; | |
| 143 | + uint32_t sampleCounter; | |
| 144 | + uint32_t powerCounter; | |
| 145 | + uint8_t sampleTriggered; | |
| 146 | + } _tAutoSampler; | |
| 147 | + | |
| 148 | + typedef _tAutoSampler* tAutoSampler; | |
| 149 | + | |
| 150 | + void tAutoSampler_init (tAutoSampler* const, tBuffer* const); | |
| 151 | + void tAutoSampler_free (tAutoSampler* const); | |
| 152 | + void tAutoSampler_initToPool (tAutoSampler* const, tBuffer* const, tMempool* const); | |
| 153 | + void tAutoSampler_freeFromPool (tAutoSampler* const, tMempool* const); | |
| 154 | + | |
| 155 | + float tAutoSampler_tick (tAutoSampler* const, float input); | |
| 156 | + | |
| 157 | + void tAutoSampler_setBuffer (tAutoSampler* const, tBuffer* const); | |
| 158 | + | |
| 159 | + void tAutoSampler_setMode (tAutoSampler* const, PlayMode mode); | |
| 160 | + | |
| 161 | + void tAutoSampler_play (tAutoSampler* const); | |
| 162 | + void tAutoSampler_stop (tAutoSampler* const); | |
| 163 | + | |
| 164 | + void tAutoSampler_setThreshold (tAutoSampler* const, float thresh); | |
| 165 | + void tAutoSampler_setWindowSize (tAutoSampler* const, uint32_t size); | |
| 166 | + void tAutoSampler_setCrossfadeLength (tAutoSampler* const, uint32_t length); | |
| 167 | + | |
| 168 | + void tAutoSampler_setRate (tAutoSampler* const, float rate); | |
| 169 | + | |
| 135 | 170 | #ifdef __cplusplus |
| 136 | 171 | } |
| 137 | 172 | #endif |
| @@ -903,7 +903,8 @@ float tTapeDelay_tick (tTapeDelay* const dl, float input) · 902 unmodified lines | ||
| 903 | 903 | if (d->idx >= d->maxDelay) d->idx = 0.0f; |
| 904 | 904 | |
| 905 | 905 | if (d->lastOut) |
| 906 | − return d->lastOut; | |
| 906 | + return d->lastOut; | |
| 907 | + return 0.0f; | |
| 907 | 908 | } |
| 908 | 909 | |
| 909 | 910 | void tTapeDelay_incrementInPoint(tTapeDelay* const dl) |
| @@ -48,9 +48,11 @@ · 47 unmodified lines | ||
| 48 | 48 | |
| 49 | 49 | #endif |
| 50 | 50 | |
| 51 | −tMempool leaf_pool; | |
| 51 | +_tMempool leaf_pool; | |
| 52 | +tMempool leaf_mempool; | |
| 52 | 53 | size_t header_size; |
| 53 | 54 | |
| 55 | + | |
| 54 | 56 | /** |
| 55 | 57 | * private function |
| 56 | 58 | */ |
| @@ -79,7 +81,9 @@ void mpool_create (char* memory, size_t size, mpool_t* pool) · 22 unmodified lines | ||
| 79 | 81 | |
| 80 | 82 | void leaf_pool_init(char* memory, size_t size) |
| 81 | 83 | { |
| 82 | − mpool_create(memory, size, &leaf_pool->pool); | |
| 84 | + mpool_create(memory, size, &leaf_pool.pool); | |
| 85 | + | |
| 86 | + leaf_mempool = &leaf_pool; | |
| 83 | 87 | } |
| 84 | 88 | |
| 85 | 89 | /** |
| @@ -206,7 +210,7 @@ void* mpool_calloc(size_t asize, mpool_t* pool) · 120 unmodified lines | ||
| 206 | 210 | void* leaf_alloc(size_t size) |
| 207 | 211 | { |
| 208 | 212 | //printf("alloc %i\n", size); |
| 209 | − void* block = mpool_alloc(size, &leaf_pool->pool); | |
| 213 | + void* block = mpool_alloc(size, &leaf_pool.pool); | |
| 210 | 214 | |
| 211 | 215 | if (block == NULL) leaf_mempool_overrun(); |
| 212 | 216 | |
| @@ -216,7 +220,7 @@ void* leaf_alloc(size_t size) · 3 unmodified lines | ||
| 216 | 220 | void* leaf_calloc(size_t size) |
| 217 | 221 | { |
| 218 | 222 | //printf("alloc %i\n", size); |
| 219 | − void* block = mpool_calloc(size, &leaf_pool->pool); | |
| 223 | + void* block = mpool_calloc(size, &leaf_pool.pool); | |
| 220 | 224 | |
| 221 | 225 | if (block == NULL) leaf_mempool_overrun(); |
| 222 | 226 | |
| @@ -288,7 +292,7 @@ void mpool_free(void* ptr, mpool_t* pool) · 65 unmodified lines | ||
| 288 | 292 | |
| 289 | 293 | void leaf_free(void* ptr) |
| 290 | 294 | { |
| 291 | − mpool_free(ptr, &leaf_pool->pool); | |
| 295 | + mpool_free(ptr, &leaf_pool.pool); | |
| 292 | 296 | } |
| 293 | 297 | |
| 294 | 298 | size_t mpool_get_size(mpool_t* pool) |
| @@ -303,17 +307,17 @@ size_t mpool_get_used(mpool_t* pool) · 8 unmodified lines | ||
| 303 | 307 | |
| 304 | 308 | size_t leaf_pool_get_size(void) |
| 305 | 309 | { |
| 306 | − return mpool_get_size(&leaf_pool->pool); | |
| 310 | + return mpool_get_size(&leaf_pool.pool); | |
| 307 | 311 | } |
| 308 | 312 | |
| 309 | 313 | size_t leaf_pool_get_used(void) |
| 310 | 314 | { |
| 311 | − return mpool_get_used(&leaf_pool->pool); | |
| 315 | + return mpool_get_used(&leaf_pool.pool); | |
| 312 | 316 | } |
| 313 | 317 | |
| 314 | 318 | void* leaf_pool_get_pool(void) |
| 315 | 319 | { |
| 316 | − float* buff = (float*)leaf_pool->pool.mpool; | |
| 320 | + float* buff = (float*)leaf_pool.pool.mpool; | |
| 317 | 321 | |
| 318 | 322 | return buff; |
| 319 | 323 | } |
| @@ -362,12 +366,12 @@ void leaf_mempool_overrun(void) · 42 unmodified lines | ||
| 362 | 366 | |
| 363 | 367 | void tMempool_init(tMempool* const mp, char* memory, size_t size) |
| 364 | 368 | { |
| 365 | − tMempool_initToPool(mp, memory, size, &leaf_pool); | |
| 369 | + tMempool_initToPool(mp, memory, size, &leaf_mempool); | |
| 366 | 370 | } |
| 367 | 371 | |
| 368 | 372 | void tMempool_free(tMempool* const mp) |
| 369 | 373 | { |
| 370 | − tMempool_freeFromPool(mp, &leaf_pool); | |
| 374 | + tMempool_freeFromPool(mp, &leaf_mempool); | |
| 371 | 375 | } |
| 372 | 376 | |
| 373 | 377 | void tMempool_initToPool (tMempool* const mp, char* memory, size_t size, tMempool* const mem) |
| @@ -164,7 +164,18 @@ static void attemptStartEndChange(tSampler* const sp); · 163 unmodified lines | ||
| 164 | 164 | |
| 165 | 165 | void tSampler_init(tSampler* const sp, tBuffer* const b) |
| 166 | 166 | { |
| 167 | − _tSampler* p = *sp = (_tSampler*) leaf_alloc(sizeof(_tSampler)); | |
| 167 | + tSampler_initToPool(sp, b, &leaf_mempool); | |
| 168 | +} | |
| 169 | + | |
| 170 | +void tSampler_free (tSampler* const sp) | |
| 171 | +{ | |
| 172 | + tSampler_freeFromPool(sp, &leaf_mempool); | |
| 173 | +} | |
| 174 | + | |
| 175 | +void tSampler_initToPool(tSampler* const sp, tBuffer* const b, tMempool* const mp) | |
| 176 | +{ | |
| 177 | + _tMempool* m = *mp; | |
| 178 | + _tSampler* p = *sp = (_tSampler*) mpool_alloc(sizeof(_tSampler), &m->pool); | |
| 168 | 179 | _tBuffer* s = *b; |
| 169 | 180 | |
| 170 | 181 | p->samp = s; |
| @@ -188,19 +199,20 @@ void tSampler_init(tSampler* const sp, tBuffer* const b) · 17 unmodified lines | ||
| 188 | 199 | |
| 189 | 200 | p->cfxlen = 500; // default 300 sample crossfade |
| 190 | 201 | |
| 191 | − tRamp_init(&p->gain, 7.0f, 1); | |
| 202 | + tRamp_initToPool(&p->gain, 7.0f, 1, mp); | |
| 192 | 203 | tRamp_setVal(&p->gain, 0.f); |
| 193 | 204 | |
| 194 | 205 | p->targetstart = -1; |
| 195 | 206 | p->targetend = -1; |
| 196 | 207 | } |
| 197 | 208 | |
| 198 | −void tSampler_free (tSampler* const sp) | |
| 209 | +void tSampler_freeFromPool (tSampler* const sp, tMempool* const mp) | |
| 199 | 210 | { |
| 211 | + _tMempool* m = *mp; | |
| 200 | 212 | _tSampler* p = *sp; |
| 201 | − tRamp_free(&p->gain); | |
| 213 | + tRamp_freeFromPool(&p->gain, mp); | |
| 202 | 214 | |
| 203 | − leaf_free(p); | |
| 215 | + mpool_free(p, &m->pool); | |
| 204 | 216 | } |
| 205 | 217 | |
| 206 | 218 | void tSampler_setSample (tSampler* const sp, tBuffer* const b) |
| @@ -704,3 +716,129 @@ void tSampler_setRate (tSampler* const sp, float rate) · 497 unmodified lines | ||
| 704 | 716 | } |
| 705 | 717 | |
| 706 | 718 | //============================================================================== |
| 719 | + | |
| 720 | +void tAutoSampler_init (tAutoSampler* const as, tBuffer* const b) | |
| 721 | +{ | |
| 722 | + tAutoSampler_initToPool(as, b, &leaf_mempool); | |
| 723 | +} | |
| 724 | + | |
| 725 | +void tAutoSampler_free (tAutoSampler* const as) | |
| 726 | +{ | |
| 727 | + tAutoSampler_freeFromPool(as, &leaf_mempool); | |
| 728 | +} | |
| 729 | + | |
| 730 | +void tAutoSampler_initToPool (tAutoSampler* const as, tBuffer* const b, tMempool* const mp) | |
| 731 | +{ | |
| 732 | + _tMempool* m = *mp; | |
| 733 | + _tAutoSampler* a = *as = (_tAutoSampler*) mpool_alloc(sizeof(_tAutoSampler), &m->pool); | |
| 734 | + | |
| 735 | + tBuffer_setRecordMode(b, RecordOneShot); | |
| 736 | + tSampler_initToPool(&a->sampler, b, mp); | |
| 737 | + tSampler_setMode(&a->sampler, PlayLoop); | |
| 738 | + tEnvelopeFollower_initToPool(&a->ef, 0.05f, 0.9999f, mp); | |
| 739 | +} | |
| 740 | + | |
| 741 | +void tAutoSampler_freeFromPool (tAutoSampler* const as, tMempool* const mp) | |
| 742 | +{ | |
| 743 | + _tMempool* m = *mp; | |
| 744 | + _tAutoSampler* a = *as; | |
| 745 | + | |
| 746 | + tEnvelopeFollower_freeFromPool(&a->ef, mp); | |
| 747 | + tSampler_freeFromPool(&a->sampler, mp); | |
| 748 | + | |
| 749 | + mpool_free(a, &m->pool); | |
| 750 | +} | |
| 751 | + | |
| 752 | +float tAutoSampler_tick (tAutoSampler* const as, float input) | |
| 753 | +{ | |
| 754 | + _tAutoSampler* a = *as; | |
| 755 | + float currentPower = tEnvelopeFollower_tick(&a->ef, input); | |
| 756 | + | |
| 757 | + if ((currentPower > (a->threshold)) && | |
| 758 | + (currentPower > a->previousPower + 0.001f) && | |
| 759 | + (a->sampleTriggered == 0) && | |
| 760 | + (a->sampleCounter == 0)) | |
| 761 | + { | |
| 762 | + a->sampleTriggered = 1; | |
| 763 | + tBuffer_record(&a->sampler->samp); | |
| 764 | + a->sampler->samp->recordedLength = a->sampler->samp->bufferLength; | |
| 765 | + a->sampleCounter = a->windowSize + 24;//arbitrary extra time to avoid resampling while playing previous sample - better solution would be alternating buffers and crossfading | |
| 766 | + a->powerCounter = 1000; | |
| 767 | + } | |
| 768 | + | |
| 769 | + if (a->sampleCounter > 0) | |
| 770 | + { | |
| 771 | + a->sampleCounter--; | |
| 772 | + } | |
| 773 | + | |
| 774 | + | |
| 775 | + tSampler_setEnd(&a->sampler, a->windowSize); | |
| 776 | + tBuffer_tick(&a->sampler->samp, input); | |
| 777 | + //on it's way down | |
| 778 | + if (currentPower <= a->previousPower) | |
| 779 | + { | |
| 780 | + if (a->powerCounter > 0) | |
| 781 | + { | |
| 782 | + a->powerCounter--; | |
| 783 | + } | |
| 784 | + else if (a->sampleTriggered == 1) | |
| 785 | + { | |
| 786 | + a->sampleTriggered = 0; | |
| 787 | + } | |
| 788 | + } | |
| 789 | + | |
| 790 | + a->previousPower = currentPower; | |
| 791 | + | |
| 792 | + return tSampler_tick(&a->sampler); | |
| 793 | +} | |
| 794 | + | |
| 795 | +void tAutoSampler_setBuffer (tAutoSampler* const as, tBuffer* const b) | |
| 796 | +{ | |
| 797 | + _tAutoSampler* a = *as; | |
| 798 | + tBuffer_setRecordMode(b, RecordOneShot); | |
| 799 | + if (a->windowSize > tBuffer_getBufferLength(b)) | |
| 800 | + a->windowSize = tBuffer_getBufferLength(b); | |
| 801 | + tSampler_setSample(&a->sampler, b); | |
| 802 | +} | |
| 803 | + | |
| 804 | +void tAutoSampler_setMode (tAutoSampler* const as, PlayMode mode) | |
| 805 | +{ | |
| 806 | + _tAutoSampler* a = *as; | |
| 807 | + tSampler_setMode(&a->sampler, mode); | |
| 808 | +} | |
| 809 | + | |
| 810 | +void tAutoSampler_play (tAutoSampler* const as) | |
| 811 | +{ | |
| 812 | + _tAutoSampler* a = *as; | |
| 813 | + tSampler_play(&a->sampler); | |
| 814 | +} | |
| 815 | +void tAutoSampler_stop (tAutoSampler* const as) | |
| 816 | +{ | |
| 817 | + _tAutoSampler* a = *as; | |
| 818 | + tSampler_stop(&a->sampler); | |
| 819 | +} | |
| 820 | + | |
| 821 | +void tAutoSampler_setThreshold (tAutoSampler* const as, float thresh) | |
| 822 | +{ | |
| 823 | + _tAutoSampler* a = *as; | |
| 824 | + a->threshold = thresh; | |
| 825 | +} | |
| 826 | + | |
| 827 | +void tAutoSampler_setWindowSize (tAutoSampler* const as, uint32_t size) | |
| 828 | +{ | |
| 829 | + _tAutoSampler* a = *as; | |
| 830 | + if (size > tBuffer_getBufferLength(&a->sampler->samp)) | |
| 831 | + a->windowSize = tBuffer_getBufferLength(&a->sampler->samp); | |
| 832 | + else a->windowSize = size; | |
| 833 | +} | |
| 834 | + | |
| 835 | +void tAutoSampler_setCrossfadeLength (tAutoSampler* const as, uint32_t length) | |
| 836 | +{ | |
| 837 | + _tAutoSampler* a = *as; | |
| 838 | + tSampler_setCrossfadeLength(&a->sampler, length); | |
| 839 | +} | |
| 840 | + | |
| 841 | +void tAutoSampler_setRate (tAutoSampler* const as, float rate) | |
| 842 | +{ | |
| 843 | + ; | |
| 844 | +} | |
| @@ -317,7 +317,7 @@ · 316 unmodified lines | ||
| 317 | 317 | // Audio plugin settings.. |
| 318 | 318 | |
| 319 | 319 | #ifndef JucePlugin_Build_VST |
| 320 | − #define JucePlugin_Build_VST 1 | |
| 320 | + #define JucePlugin_Build_VST 0 | |
| 321 | 321 | #endif |
| 322 | 322 | #ifndef JucePlugin_Build_VST3 |
| 323 | 323 | #define JucePlugin_Build_VST3 0 |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | <JUCERPROJECT id="ArQetv" name="LEAF" projectType="audioplug" version="1.0.0" |
| 4 | 4 | bundleIdentifier="com.pumusic.LEAF" includeBinaryInAppConfig="1" |
| 5 | − buildVST="1" buildVST3="0" buildAU="1" buildAUv3="0" buildRTAS="0" | |
| 5 | + buildVST="0" buildVST3="0" buildAU="1" buildAUv3="0" buildRTAS="0" | |
| 6 | 6 | buildAAX="0" pluginName="LEAF" pluginDesc="LEAF" pluginManufacturer="pumusic" |
| 7 | 7 | pluginManufacturerCode="Manu" pluginCode="Arqe" pluginChannelConfigs="{2,2}" |
| 8 | 8 | pluginIsSynth="0" pluginWantsMidiIn="1" pluginProducesMidiOut="0" |
| @@ -11,7 +11,7 @@ · 2 unmodified lines | ||
| 11 | 11 | jucerVersion="5.4.7" companyName="Princeton University" companyEmail="mrmulshine@gmail.com" |
| 12 | 12 | displaySplashScreen="1" reportAppUsage="1" splashScreenColour="Dark" |
| 13 | 13 | buildStandalone="1" enableIAA="0" cppLanguageStandard="11" companyCopyright="Princeton University" |
| 14 | − pluginFormats="buildVST,buildAU,buildStandalone" pluginCharacteristicsValue="pluginWantsMidiIn"> | |
| 14 | + pluginFormats="buildAU,buildStandalone" pluginCharacteristicsValue="pluginWantsMidiIn"> | |
| 15 | 15 | <MAINGROUP id="F7Bywq" name="LEAF"> |
| 16 | 16 | <GROUP id="{14C5E2CD-5D51-3FD3-5677-28BECA29E95E}" name="Source"> |
| 17 | 17 | <GROUP id="{C9F79DF0-2C57-F2B0-7B1B-78A14937E038}" name="LEAF"> |
| @@ -46,7 +46,7 @@ void LEAFTest_init (float sampleRate, int blockSize) · 45 unmodified lines | ||
| 46 | 46 | tSVF_init(&bp1, SVFTypeBandpass, 100, 4.0f); |
| 47 | 47 | tSVF_init(&bp2, SVFTypeBandpass, 1000, 4.0f); |
| 48 | 48 | |
| 49 | − tFormantShifter_init(&fs, 2048, 20); | |
| 49 | + tFormantShifter_init(&fs, 20); | |
| 50 | 50 | |
| 51 | 51 | // Init and set record |
| 52 | 52 | tBuffer_init (&buff, leaf.sampleRate); // init, 1 second buffer |