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 | tPeriodDetection pd; | 38 | tPeriodDetection pd; |
| 39 | 39 | ||
| 40 | tZeroCrossing zc; | ||
| 41 | tEnvelopeFollower ef; | ||
| 42 | |||
| 40 | float gain; | 43 | float gain; |
| 41 | float freq; | ||
| 42 | float dtime; | 44 | float dtime; |
| 43 | bool buttonState; | 45 | bool buttonState; |
| 44 | int ratio = 2; | 46 | int ratio = 2; |
| @@ -46,8 +48,8 @@ float x = 0.0f; · 1 unmodified line | |||
| 46 | float y = 0.0f; | 48 | float y = 0.0f; |
| 47 | float a, b, c, d; | 49 | float a, b, c, d; |
| 48 | 50 | ||
| 49 | float bufIn[4096]; | 51 | float* bufIn; |
| 50 | float bufOut[4096]; | 52 | float* bufOut; |
| 51 | 53 | ||
| 52 | #define MSIZE 500000 | 54 | #define MSIZE 500000 |
| 53 | char memory[MSIZE]; | 55 | char memory[MSIZE]; |
| @@ -60,11 +62,15 @@ void LEAFTest_init (float sampleRate, int blockSize) · 6 unmodified lines | |||
| 60 | tMBTriangle_init(&btri); | 62 | tMBTriangle_init(&btri); |
| 61 | tMBPulse_init(&bpulse); | 63 | tMBPulse_init(&bpulse); |
| 62 | 64 | ||
| 63 | 65 | bufIn = (float*) leaf_alloc(sizeof(float) * 4096); | |
| 66 | bufOut = (float*) leaf_alloc(sizeof(float) * 4096); | ||
| 64 | // lowestFreq, highestFreq, hysteresis (width of hysteresis region around 0.0 for zero crossing detection) | 67 | // lowestFreq, highestFreq, hysteresis (width of hysteresis region around 0.0 for zero crossing detection) |
| 65 | tPitchDetector_init(&detector, mtof(48), mtof(84), 0.01f); | 68 | tPitchDetector_init(&detector, mtof(48), mtof(84), 0.01f); |
| 66 | 69 | ||
| 67 | tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024); | 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 | inline double getSawFall(double angle) { | 76 | inline double getSawFall(double angle) { |
| @@ -88,15 +94,28 @@ float LEAFTest_tick (float input) · 17 unmodified lines | |||
| 88 | //// return tMBSaw_tick(&bsaw); | 94 | //// return tMBSaw_tick(&bsaw); |
| 89 | //// return tMBTriangle_tick(&btri); | 95 | //// return tMBTriangle_tick(&btri); |
| 90 | // return tMBPulse_tick(&bpulse); | 96 | // return tMBPulse_tick(&bpulse); |
| 97 | |||
| 91 | 98 | ||
| 92 | tPitchDetector_tick(&detector, input); | 99 | if (x > 0.5) |
| 93 | 100 | { | |
| 94 | tMBTriangle_setFreq(&btri, tPitchDetector_getFrequency(&detector)); | 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; | 109 | } |
| 97 | // tMBTriangle_setFreq(&btri, freq); | 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 | int firstFrame = 1; | 121 | int firstFrame = 1; |
| @@ -114,7 +133,9 @@ void LEAFTest_block (void) · 11 unmodified lines | |||
| 114 | 133 | ||
| 115 | float val = getSliderValue("mod freq"); | 134 | float val = getSliderValue("mod freq"); |
| 116 | 135 | ||
| 117 | x = val * 20000.0f + 220.0f; | 136 | x = val; |
| 137 | |||
| 138 | |||
| 118 | 139 | ||
| 119 | // a = val * tBuffer_getBufferLength(&buff); | 140 | // a = val * tBuffer_getBufferLength(&buff); |
| 120 | 141 | ||