History

pitch detector testing

Matthew Wang committed 6 years ago

Commit 327ba3d1 parent 7acbeda3 files · +28 −18Browse files

Showing the changes to TestPlugin/Source/MyTest.cpp (1 of 3 files). Show all

Unified · Split

TestPlugin/Source/MyTest.cpp+14−13
@@ -82,6 +82,7 @@ inline double getSawFall(double angle) { · 81 unmodified lines
8282
8383 }
8484
85+float lastFreq;
8586 float LEAFTest_tick (float input)
8687 {
8788 // tMBSaw_setFreq(&bsaw, x);
@@ -96,25 +97,25 @@ float LEAFTest_tick (float input) · 8 unmodified lines
9697 // return tMBPulse_tick(&bpulse);
9798
9899
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− }
100+ float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
101+ tPitchDetector_tick(&detector, input);
108102
103+ if (tPitchDetector_getPeriodicity(&detector) > 0.0)
104+ {
105+ float altFreq = tPitchDetector_getFrequency(&detector);
106+ if (fabsf(lastFreq - freq) > fabsf(lastFreq - altFreq))
107+ freq = altFreq;
109108 }
110− else
109+
110+ if (tZeroCrossing_tick(&zc, input) < 0.05 && freq > 0.0f)
111111 {
112− float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
113− if (tZeroCrossing_tick(&zc, input) < 0.05)
114− tMBTriangle_setFreq(&btri, freq);
112+ tMBTriangle_setFreq(&btri, freq);
115113 }
116114
117115 float g = tEnvelopeFollower_tick(&ef, input);
116+
117+ lastFreq = freq;
118+
118119 return input + tMBTriangle_tick(&btri) * g * 10.0f;
119120 }
120121

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t