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