Showing the changes to TestPlugin/Source/MyTest.cpp (1 of 15 files). Show all
Unified · Split
| @@ -0,0 +1,222 @@ | ||
| 1 | +/* | |
| 2 | + ============================================================================== | |
| 3 | + FM.c | |
| 4 | + Created: 23 Jan 2017 9:39:38am | |
| 5 | + Author: Michael R Mulshine | |
| 6 | + ============================================================================== | |
| 7 | + */ | |
| 8 | + | |
| 9 | +#include "LEAFTest.h" | |
| 10 | +#include "MyTest.h" | |
| 11 | + | |
| 12 | + | |
| 13 | +static void leaf_pool_report(void); | |
| 14 | +static void leaf_pool_dump(void); | |
| 15 | +static void run_pool_test(void); | |
| 16 | + | |
| 17 | +tNoise noise; | |
| 18 | +tSVF bp1; | |
| 19 | +tSVF bp2; | |
| 20 | +tFormantShifter fs; | |
| 21 | + | |
| 22 | +tSampler samp; | |
| 23 | +tBuffer buff; | |
| 24 | +tEnvelope env; | |
| 25 | + | |
| 26 | +tAutotune at; | |
| 27 | + | |
| 28 | + | |
| 29 | +tMinBLEP minblep; | |
| 30 | + | |
| 31 | +tPhasor phasor; | |
| 32 | + | |
| 33 | +tHighpass hipass; | |
| 34 | + | |
| 35 | +tMBSaw saw; | |
| 36 | +tMBPulse pulse; | |
| 37 | +tMBTriangle tri; | |
| 38 | + | |
| 39 | +float gain; | |
| 40 | +float freq; | |
| 41 | +float dtime; | |
| 42 | +bool buttonState; | |
| 43 | +int ratio = 2; | |
| 44 | +float x = 0.0f; | |
| 45 | +float y = 0.0f; | |
| 46 | +float a, b, c, d; | |
| 47 | + | |
| 48 | +#define MSIZE 500000 | |
| 49 | +char memory[MSIZE]; | |
| 50 | + | |
| 51 | +void LEAFTest_init (float sampleRate, int blockSize) | |
| 52 | +{ | |
| 53 | + LEAF_init(sampleRate, blockSize, memory, MSIZE, &getRandomFloat); | |
| 54 | + | |
| 55 | + tMBSaw_init(&saw); | |
| 56 | + | |
| 57 | + tMBPulse_init(&pulse); | |
| 58 | + | |
| 59 | + tMBTriangle_init(&tri); | |
| 60 | + | |
| 61 | + tPhasor_init(&phasor); | |
| 62 | + | |
| 63 | + tPhasor_setFreq(&phasor, 200); | |
| 64 | +} | |
| 65 | + | |
| 66 | +inline double getSawFall(double angle) { | |
| 67 | + | |
| 68 | + angle = fmod(angle + double_Pi, 2*double_Pi); // shift x | |
| 69 | + double sample = angle/double_Pi - double(1); // computer as remainder | |
| 70 | + | |
| 71 | + return sample; | |
| 72 | + | |
| 73 | +} | |
| 74 | + | |
| 75 | +float LEAFTest_tick (float input) | |
| 76 | +{ | |
| 77 | + | |
| 78 | + tMBSaw_setFreq(&saw, y); | |
| 79 | + tMBPulse_setWidth(&pulse, x); | |
| 80 | + tMBPulse_setFreq(&pulse, y); | |
| 81 | + tMBTriangle_setSkew(&tri, 0.0);//x*2.0f - 1.0f); | |
| 82 | + tMBTriangle_setFreq(&tri, y); | |
| 83 | + | |
| 84 | + tPhasor_tick(&phasor); | |
| 85 | + | |
| 86 | +// if (phasor->phaseDidReset) tMBSaw_sync(&saw, 0.0f); | |
| 87 | +// if (phasor->phaseDidReset) tMBPulse_sync(&pulse, 0.0f); | |
| 88 | + if (phasor->phaseDidReset) tMBTriangle_sync(&tri, 0.0f); | |
| 89 | + | |
| 90 | +// return tMBSaw_tick(&saw); | |
| 91 | +// return tMBPulse_tick(&pulse); | |
| 92 | + return tMBTriangle_tick(&tri); | |
| 93 | +} | |
| 94 | + | |
| 95 | +int firstFrame = 1; | |
| 96 | +bool lastState = false, lastPlayState = false; | |
| 97 | +void LEAFTest_block (void) | |
| 98 | +{ | |
| 99 | + // if (firstFrame == 1) | |
| 100 | + // { | |
| 101 | + // tBuffer_record(&buff); // starts recording | |
| 102 | + // tSampler_play(&samp); // start spitting samples out | |
| 103 | + // firstFrame = 0; | |
| 104 | + // } | |
| 105 | + | |
| 106 | + float val = getSliderValue("mod freq"); | |
| 107 | + | |
| 108 | + x = val ; | |
| 109 | + | |
| 110 | + // a = val * tBuffer_getBufferLength(&buff); | |
| 111 | + | |
| 112 | + DBG("start: " + String(a)); | |
| 113 | + | |
| 114 | + val = getSliderValue("mod depth"); | |
| 115 | + | |
| 116 | + y = val * 5000.0f + 20.0f; | |
| 117 | + | |
| 118 | + DBG(String(y)); | |
| 119 | + // b = val * tBuffer_getBufferLength(&buff); | |
| 120 | + | |
| 121 | + DBG("rate: " + String(b)); | |
| 122 | + // | |
| 123 | + // tSampler_setStart(&samp, a); | |
| 124 | + // tSampler_setEnd(&samp, b); | |
| 125 | + // tSampler_setRate(&samp, b); | |
| 126 | + | |
| 127 | + // tFormantShifter_setShiftFactor(&fs, x); | |
| 128 | + // tFormantShifter_setIntensity(&fs, y); | |
| 129 | + | |
| 130 | +} | |
| 131 | + | |
| 132 | +void LEAFTest_controllerInput (int cnum, float cval) | |
| 133 | +{ | |
| 134 | + | |
| 135 | +} | |
| 136 | + | |
| 137 | +void LEAFTest_pitchBendInput (int pitchBend) | |
| 138 | +{ | |
| 139 | + | |
| 140 | +} | |
| 141 | + | |
| 142 | +int lastNote; | |
| 143 | +void LEAFTest_noteOn (int note, float velocity) | |
| 144 | +{ | |
| 145 | +} | |
| 146 | + | |
| 147 | + | |
| 148 | +void LEAFTest_noteOff (int note) | |
| 149 | +{ | |
| 150 | +} | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | +void LEAFTest_end (void) | |
| 155 | +{ | |
| 156 | + | |
| 157 | +} | |
| 158 | + | |
| 159 | +// LEAF POOL UTILITIES | |
| 160 | + | |
| 161 | +void leaf_pool_report(void) | |
| 162 | +{ | |
| 163 | + DBG(String(leaf_pool_get_used()) + " of " + String(leaf_pool_get_size())); | |
| 164 | +} | |
| 165 | + | |
| 166 | +void leaf_pool_dump(void) | |
| 167 | +{ | |
| 168 | + float* buff = (float*)leaf_pool_get_pool(); | |
| 169 | + unsigned long siz = leaf_pool_get_size(); | |
| 170 | + siz /= sizeof(float); | |
| 171 | + for (int i = 0; i < siz; i++) | |
| 172 | + { | |
| 173 | + DBG(String(buff[i])); | |
| 174 | + } | |
| 175 | +} | |
| 176 | + | |
| 177 | +static void run_pool_test(void) | |
| 178 | +{ | |
| 179 | + leaf_pool_report(); | |
| 180 | + | |
| 181 | + DBG("ALLOC BUFFER 1"); | |
| 182 | + int size = 50; | |
| 183 | + float* buffer; | |
| 184 | + buffer = (float*) leaf_alloc(sizeof(float) * size); | |
| 185 | + | |
| 186 | + for (int i = 0; i < size; i++) | |
| 187 | + { | |
| 188 | + buffer[i] = (float)i; | |
| 189 | + | |
| 190 | + } | |
| 191 | + | |
| 192 | + leaf_pool_report(); | |
| 193 | + | |
| 194 | + DBG("ALLOC BUFFER 2"); | |
| 195 | + size = 25; | |
| 196 | + | |
| 197 | + buffer = (float*) leaf_alloc(sizeof(float) * size); | |
| 198 | + | |
| 199 | + leaf_pool_report(); | |
| 200 | + | |
| 201 | + for (int i = 0; i < size; i++) | |
| 202 | + { | |
| 203 | + buffer[i] = (float)(i*2); | |
| 204 | + } | |
| 205 | + leaf_free((char*)buffer); | |
| 206 | + | |
| 207 | + leaf_pool_report(); | |
| 208 | + | |
| 209 | + DBG("ALLOC BUFFER 3"); | |
| 210 | + size = 15; | |
| 211 | + | |
| 212 | + buffer = (float*) leaf_alloc(sizeof(float) * size); | |
| 213 | + | |
| 214 | + for (int i = 0; i < size; i++) | |
| 215 | + { | |
| 216 | + buffer[i] = (float)(i*3); | |
| 217 | + } | |
| 218 | + | |
| 219 | + leaf_pool_report(); | |
| 220 | + | |
| 221 | + leaf_pool_dump(); | |
| 222 | +} | |