Showing the changes to TestPlugin/Source/MyTest.cpp (1 of 2 files). Show all
Unified · Split
| @@ -37,8 +37,10 @@ tPitchDetector detector; · 36 unmodified lines | ||
| 37 | 37 | |
| 38 | 38 | tPeriodDetection pd; |
| 39 | 39 | |
| 40 | +tZeroCrossing zc; | |
| 41 | +tEnvelopeFollower ef; | |
| 42 | + | |
| 40 | 43 | float gain; |
| 41 | −float freq; | |
| 42 | 44 | float dtime; |
| 43 | 45 | bool buttonState; |
| 44 | 46 | int ratio = 2; |
| @@ -46,8 +48,8 @@ float x = 0.0f; · 1 unmodified line | ||
| 46 | 48 | float y = 0.0f; |
| 47 | 49 | float a, b, c, d; |
| 48 | 50 | |
| 49 | −float bufIn[4096]; | |
| 50 | −float bufOut[4096]; | |
| 51 | +float* bufIn; | |
| 52 | +float* bufOut; | |
| 51 | 53 | |
| 52 | 54 | #define MSIZE 500000 |
| 53 | 55 | char memory[MSIZE]; |
| @@ -60,11 +62,15 @@ void LEAFTest_init (float sampleRate, int blockSize) · 6 unmodified lines | ||
| 60 | 62 | tMBTriangle_init(&btri); |
| 61 | 63 | tMBPulse_init(&bpulse); |
| 62 | 64 | |
| 63 | − | |
| 65 | + bufIn = (float*) leaf_alloc(sizeof(float) * 4096); | |
| 66 | + bufOut = (float*) leaf_alloc(sizeof(float) * 4096); | |
| 64 | 67 | // lowestFreq, highestFreq, hysteresis (width of hysteresis region around 0.0 for zero crossing detection) |
| 65 | 68 | tPitchDetector_init(&detector, mtof(48), mtof(84), 0.01f); |
| 66 | 69 | |
| 67 | 70 | tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024); |
| 71 | + | |
| 72 | + tZeroCrossing_init(&zc, 128); | |
| 73 | + tEnvelopeFollower_init(&ef, 0.02f, 0.9999f); | |
| 68 | 74 | } |
| 69 | 75 | |
| 70 | 76 | inline double getSawFall(double angle) { |
| @@ -88,15 +94,28 @@ float LEAFTest_tick (float input) · 17 unmodified lines | ||
| 88 | 94 | //// return tMBSaw_tick(&bsaw); |
| 89 | 95 | //// return tMBTriangle_tick(&btri); |
| 90 | 96 | // return tMBPulse_tick(&bpulse); |
| 97 | + | |
| 91 | 98 | |
| 92 | − tPitchDetector_tick(&detector, input); | |
| 93 | − | |
| 94 | − tMBTriangle_setFreq(&btri, tPitchDetector_getFrequency(&detector)); | |
| 99 | + if (x > 0.5) | |
| 100 | + { | |
| 101 | + tPitchDetector_tick(&detector, input); | |
| 102 | + if (tPitchDetector_getPeriodicity(&detector) > 0.99 && (tZeroCrossing_tick(&zc, input) < 0.05)) | |
| 103 | + { | |
| 104 | + float freq = tPitchDetector_getFrequency(&detector); | |
| 105 | + if (freq != 0.0f) | |
| 106 | + tMBTriangle_setFreq(&btri, freq); | |
| 107 | + } | |
| 95 | 108 | |
| 96 | −// float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate; | |
| 97 | −// tMBTriangle_setFreq(&btri, freq); | |
| 109 | + } | |
| 110 | + else | |
| 111 | + { | |
| 112 | + float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate; | |
| 113 | + if (tZeroCrossing_tick(&zc, input) < 0.05) | |
| 114 | + tMBTriangle_setFreq(&btri, freq); | |
| 115 | + } | |
| 98 | 116 | |
| 99 | − return tMBTriangle_tick(&btri);// * 0.25; | |
| 117 | + float g = tEnvelopeFollower_tick(&ef, input); | |
| 118 | + return input + tMBTriangle_tick(&btri) * g * 10.0f; | |
| 100 | 119 | } |
| 101 | 120 | |
| 102 | 121 | int firstFrame = 1; |
| @@ -114,7 +133,9 @@ void LEAFTest_block (void) · 11 unmodified lines | ||
| 114 | 133 | |
| 115 | 134 | float val = getSliderValue("mod freq"); |
| 116 | 135 | |
| 117 | − x = val * 20000.0f + 220.0f; | |
| 136 | + x = val; | |
| 137 | + | |
| 138 | + | |
| 118 | 139 | |
| 119 | 140 | // a = val * tBuffer_getBufferLength(&buff); |
| 120 | 141 | |