| @@ -21,99 +21,83 @@ float fx = 1.f; · 20 unmodified lines |
| 21 | | 21 | |
| 22 | #define NUM_GRAINS 20 | 22 | #define NUM_GRAINS 20 |
| 23 | | 23 | |
| 24 | tBuffer buff; | 24 | |
| 25 | tSampler samp[NUM_GRAINS]; | | |
| 26 | | 25 | |
| 27 | tTapeDelay delay; | 26 | tTapeDelay delay; |
| 28 | | 27 | |
| 29 | float feedback = 0.f; | 28 | float feedback = 0.f; |
| 30 | | 29 | |
| | 30 | tBuffer buff; |
| | 31 | tSampler samp; |
| | 32 | |
| | 33 | tCycle osc; |
| 31 | | 34 | |
| 32 | void LEAFTest_init (float sampleRate, int blockSize) | 35 | void LEAFTest_init (float sampleRate, int blockSize) |
| 33 | { | 36 | { |
| 34 | LEAF_init(sampleRate, blockSize, &getRandomFloat); | 37 | LEAF_init(sampleRate, blockSize, &getRandomFloat); |
| 35 | | 38 | |
| 36 | // Init and set record loop | 39 | // Init and set record |
| 37 | tBuffer_init (&buff, leaf.sampleRate * 1.f); // 0.5-second buffers | 40 | tBuffer_init (&buff, leaf.sampleRate * 1.f); // init, 1 second buffer |
| 38 | tBuffer_setRecordMode (&buff, RecordLoop); | 41 | tBuffer_setRecordMode (&buff, RecordOneShot); // RecordOneShot records once through |
| 39 | tBuffer_record(&buff); | 42 | tBuffer_record(&buff); // starts recording |
| 40 | | | |
| 41 | for (int i = 0; i < NUM_GRAINS; i++) | | |
| 42 | { | | |
| 43 | // Init and set play loop | | |
| 44 | tSampler_init (&samp[i], &buff); | | |
| 45 | tSampler_setMode (&samp[i], PlayLoop); | | |
| 46 | | 43 | |
| 47 | /* | 44 | // Init and set play |
| 48 | float speed = ((getRandomFloat() < 0.5f) ? 0.5f : 1.f); | 45 | tSampler_init (&samp, &buff); // init, give address of record buffer |
| 49 | float dir = (getRandomFloat() < 0.5f) ? -1 : 1; | 46 | tSampler_setMode (&samp, PlayLoop); //set in Loop Mode |
| 50 | | 47 | tSampler_setRate(&samp, 1.f); // Rate of 1.0 |
| 51 | tSampler_setRate(&samp[i], speed * dir); | 48 | tSampler_play(&samp); // start spitting samples out |
| 52 | */ | 49 | |
| 53 | | 50 | tCycle_init(&osc); |
| 54 | tSampler_setRate(&samp[i], 1.f); | | |
| 55 | | | |
| 56 | // Record and play | | |
| 57 | tSampler_play(&samp[i]); | | |
| 58 | } | | |
| 59 | | | |
| 60 | tTapeDelay_init(&delay, leaf.sampleRate * 0.05f, leaf.sampleRate * 1.f); // 1 second delay, starts out at 50 ms | | |
| 61 | | 51 | |
| 62 | leaf_pool_report(); | 52 | leaf_pool_report(); |
| 63 | } | 53 | } |
| 64 | | 54 | |
| 65 | int timer = 0; | 55 | float depth = 1.0f; |
| 66 | | | |
| 67 | float lastOut; | | |
| 68 | | 56 | |
| 69 | float LEAFTest_tick (float input) | 57 | float LEAFTest_tick (float input) |
| 70 | { | 58 | { |
| 71 | float sample = 0.f; | 59 | float sample = 0.f; |
| 72 | | 60 | |
| 73 | tBuffer_tick(&buff, input); | 61 | tBuffer_tick(&buff, input); // ticking the buffer records in to buffer |
| 74 | | 62 | |
| 75 | for (int i = 0; i < NUM_GRAINS; i++) | 63 | tSampler_setRate(&samp, tCycle_tick(&osc) * depth); |
| | 64 | |
| | 65 | // dont tick sampler if buffer not active (not recording) |
| | 66 | if (buff.active == 0) |
| 76 | { | 67 | { |
| 77 | sample += tSampler_tick(&samp[i]); | 68 | sample = tSampler_tick(&samp); // ticking sampler loops sample |
| 78 | } | 69 | } |
| 79 | | 70 | |
| 80 | sample /= NUM_GRAINS; | | |
| 81 | | | |
| 82 | sample = tTapeDelay_tick(&delay, (1.f - feedback) * sample + feedback * lastOut); | | |
| 83 | | 71 | |
| 84 | lastOut = sample; | 72 | return sample; |
| 85 | | | |
| 86 | return (sample * mix) + | | |
| 87 | (input * (1.f - mix)); | | |
| 88 | } | 73 | } |
| 89 | | 74 | |
| 90 | bool lastState = false, lastPlayState = false; | 75 | bool lastState = false, lastPlayState = false; |
| 91 | void LEAFTest_block (void) | 76 | void LEAFTest_block (void) |
| 92 | { | 77 | { |
| 93 | float val = getSliderValue("mix"); | 78 | bool state = getButtonState("record"); |
| 94 | | 79 | |
| 95 | mix = val; | 80 | if (state) |
| 96 | | 81 | { |
| 97 | val = getSliderValue("delay"); | 82 | setButtonState("record", false); |
| 98 | | 83 | tBuffer_record(&buff); |
| 99 | tTapeDelay_setDelay(&delay, val * leaf.sampleRate); | 84 | } |
| 100 | | 85 | |
| 101 | val = getSliderValue("feedback"); | 86 | float val = getSliderValue("mod freq"); |
| 102 | | 87 | |
| 103 | feedback = val; | 88 | float freq = 0.1 + 999.9 * val; |
| 104 | | 89 | |
| 105 | for (int i = 0; i < NUM_GRAINS; i++) | 90 | tCycle_setFreq(&osc, freq); |
| 106 | { | 91 | |
| 107 | if (getRandomFloat() < 0.01f) | 92 | DBG("mod freq: " + String(freq)); |
| 108 | { | 93 | |
| 109 | tSampler_setStart(&samp[i], leaf.sampleRate * 0.05f + leaf.sampleRate * getRandomFloat() * 0.95f); | 94 | val = getSliderValue("mod depth"); |
| 110 | | 95 | |
| 111 | uint64_t end = (leaf.sampleRate * 0.05f + getRandomFloat() * leaf.sampleRate * 0.45f + samp[i].start); | 96 | depth = 0.1 + val * 15.9f; |
| 112 | | 97 | |
| 113 | tSampler_setEnd(&samp[i], end % buff.length); // 10 - 1010 ms | 98 | DBG("mod depth: " + String(depth)); |
| 114 | } | 99 | |
| 115 | } | 100 | |
| 116 | | | |
| 117 | } | 101 | } |
| 118 | | 102 | |
| 119 | void LEAFTest_controllerInput (int cnum, float cval) | 103 | void LEAFTest_controllerInput (int cnum, float cval) |