| @@ -40,6 +40,8 @@ tPeriodDetection pd; · 39 unmodified lines |
| 40 | tZeroCrossingCounter zc; | 40 | tZeroCrossingCounter zc; |
| 41 | tEnvelopeFollower ef; | 41 | tEnvelopeFollower ef; |
| 42 | | 42 | |
| | 43 | tCycle sine; |
| | 44 | |
| 43 | float gain; | 45 | float gain; |
| 44 | float dtime; | 46 | float dtime; |
| 45 | bool buttonState; | 47 | bool buttonState; |
| @@ -71,6 +73,9 @@ void LEAFTest_init (float sampleRate, int blockSize) · 25 unmodified lines |
| 71 | | 73 | |
| 72 | tZeroCrossingCounter_init(&zc, 128); | 74 | tZeroCrossingCounter_init(&zc, 128); |
| 73 | tEnvelopeFollower_init(&ef, 0.02f, 0.9999f); | 75 | tEnvelopeFollower_init(&ef, 0.02f, 0.9999f); |
| | 76 | |
| | 77 | tCycle_init(&sine); |
| | 78 | tCycle_setFreq(&sine, 100); |
| 74 | } | 79 | } |
| 75 | | 80 | |
| 76 | inline double getSawFall(double angle) { | 81 | inline double getSawFall(double angle) { |
| @@ -99,32 +104,31 @@ float LEAFTest_tick (float input) · 22 unmodified lines |
| 99 | | 104 | |
| 100 | float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate; | 105 | float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate; |
| 101 | tPitchDetector_tick(&detector, input); | 106 | tPitchDetector_tick(&detector, input); |
| | 107 | float altFreq = tPitchDetector_getFrequency(&detector); |
| 102 | | 108 | |
| 103 | if (tPitchDetector_getPeriodicity(&detector) > 0.0) | 109 | if (fabsf(1.0f - (freq / altFreq)) < 0.05f) |
| 104 | { | | |
| 105 | float altFreq = tPitchDetector_getFrequency(&detector); | | |
| 106 | // if (fabsf(lastFreq - freq) > fabsf(lastFreq - altFreq)) | | |
| 107 | freq = altFreq; | | |
| 108 | } | | |
| 109 | | | |
| 110 | // if (tZeroCrossingCounter_tick(&zc, input) < 0.05 && freq > 0.0f) | 110 | // if (tZeroCrossingCounter_tick(&zc, input) < 0.05 && freq > 0.0f) |
| 111 | { | 111 | { |
| 112 | tMBTriangle_setFreq(&btri, freq); | 112 | tCycle_setFreq(&sine, altFreq); |
| 113 | } | 113 | } |
| 114 | | 114 | |
| 115 | float g = tEnvelopeFollower_tick(&ef, input); | 115 | float g = tEnvelopeFollower_tick(&ef, input); |
| 116 | | 116 | |
| 117 | lastFreq = freq; | 117 | lastFreq = freq; |
| 118 | | 118 | |
| 119 | return input + tMBTriangle_tick(&btri) * g * 10.0f; | 119 | return tCycle_tick(&sine) * g * 2.0f + input; |
| 120 | } | 120 | } |
| 121 | | 121 | |
| 122 | int firstFrame = 1; | 122 | int firstFrame = 1; |
| 123 | bool lastState = false, lastPlayState = false; | 123 | bool lastState = false, lastPlayState = false; |
| 124 | void LEAFTest_block (void) | 124 | void LEAFTest_block (void) |
| 125 | { | 125 | { |
| 126 | DBG(tPitchDetector_getFrequency(&detector)); | 126 | float periodicity = tPitchDetector_getPeriodicity(&detector); |
| 127 | DBG(tPitchDetector_getPeriodicity(&detector)); | 127 | if (periodicity > 0.99f) |
| | 128 | { |
| | 129 | DBG(tPitchDetector_getFrequency(&detector)); |
| | 130 | DBG(tPitchDetector_getPeriodicity(&detector)); |
| | 131 | } |
| 128 | // if (firstFrame == 1) | 132 | // if (firstFrame == 1) |
| 129 | // { | 133 | // { |
| 130 | // tBuffer_record(&buff); // starts recording | 134 | // tBuffer_record(&buff); // starts recording |