History

tDualPitchDetector and other bacf pitch detector updates

Matthew Wang committed 6 years ago

Commit 3152c9f1 parent 697a53f3 files · +467 −318Browse files

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

Unified · Split

TestPlugin/Source/MyTest.cpp+35−27
@@ -18,14 +18,18 @@ tMBSaw bsaw; · 17 unmodified lines
1818 tMBTriangle btri;
1919 tMBPulse bpulse;
2020
21−tPitchDetector detector;
21+tDualPitchDetector detector;
22+
23+tCompressor compressor;
24+
25+tSVF lp, hp;
2226
2327 tPeriodDetection pd;
2428
2529 tZeroCrossingCounter zc;
2630 tEnvelopeFollower ef;
2731
28−tCycle sine;
32+tTriangle tri;
2933
3034 tBuffer samp;
3135 tMBSampler sampler;
@@ -54,16 +58,21 @@ void LEAFTest_init (float sampleRate, int blockSize) · 22 unmodified lines
5458
5559 bufIn = (float*) leaf_alloc(sizeof(float) * 4096);
5660 bufOut = (float*) leaf_alloc(sizeof(float) * 4096);
57− // lowestFreq, highestFreq, hysteresis (width of hysteresis region around 0.0 for zero crossing detection)
58− tPitchDetector_init(&detector, mtof(48), mtof(84), 0.01f);
61+
62+ tDualPitchDetector_init(&detector, mtof(53), mtof(77));
63+
64+ tCompressor_init(&compressor);
65+
66+ tSVF_init(&lp, SVFTypeLowpass, mtof(77) * 2.0f, 1.0f);
67+ tSVF_init(&hp, SVFTypeHighpass, mtof(48) * 0.5f, 1.0f);
5968
6069 tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024);
6170
6271 tZeroCrossingCounter_init(&zc, 128);
6372 tEnvelopeFollower_init(&ef, 0.02f, 0.9999f);
6473
65− tCycle_init(&sine);
66− tCycle_setFreq(&sine, 100);
74+ tTriangle_init(&tri);
75+ tTriangle_setFreq(&tri, 100);
6776
6877 tBuffer_init(&samp, 5.0f * leaf.sampleRate);
6978 tMBSampler_init(&sampler, &samp);
@@ -81,12 +90,11 @@ inline double getSawFall(double angle) { · 11 unmodified lines
8190
8291 }
8392
84−float lastFreq;
8593 float LEAFTest_tick (float input)
8694 {
87− tBuffer_tick(&samp, input);
88−
89− return tMBSampler_tick(&sampler);
95+// tBuffer_tick(&samp, input);
96+//
97+// return tMBSampler_tick(&sampler);
9098
9199
92100 // tMBSaw_setFreq(&bsaw, x);
@@ -99,34 +107,34 @@ float LEAFTest_tick (float input) · 6 unmodified lines
99107 //// return tMBSaw_tick(&bsaw);
100108 //// return tMBTriangle_tick(&btri);
101109 // return tMBPulse_tick(&bpulse);
102−
110+
111+ input = tSVF_tick(&hp, tSVF_tick(&lp, tCompressor_tick(&compressor, input)));
103112
104113 // float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
105−// tPitchDetector_tick(&detector, input);
106−// float altFreq = tPitchDetector_getFrequency(&detector);
107−//
114+ tDualPitchDetector_tick(&detector, input);
115+ float altFreq = tDualPitchDetector_getFrequency(&detector);
116+
108117 // if (fabsf(1.0f - (freq / altFreq)) < 0.05f)
109−//// if (tZeroCrossingCounter_tick(&zc, input) < 0.05 && freq > 0.0f)
110−// {
111−// tCycle_setFreq(&sine, altFreq);
112−// }
113−//
114−// float g = tEnvelopeFollower_tick(&ef, input);
115−//
116−// lastFreq = freq;
117−//
118−// return tCycle_tick(&sine) * g * 2.0f + input;
118+// if (tZeroCrossingCounter_tick(&zc, input) < 0.05 && freq > 0.0f)
119+ if (altFreq > 0.0f)
120+ {
121+ tTriangle_setFreq(&tri, altFreq);
122+ }
123+
124+ float g = tEnvelopeFollower_tick(&ef, input);
125+
126+ return tTriangle_tick(&tri) * g;
119127 }
120128
121129 int firstFrame = 1;
122130 bool lastState = false, lastPlayState = false;
123131 void LEAFTest_block (void)
124132 {
125− float periodicity = tPitchDetector_getPeriodicity(&detector);
133+ float periodicity = tDualPitchDetector_getPeriodicity(&detector);
126134 if (periodicity > 0.99f)
127135 {
128− DBG(tPitchDetector_getFrequency(&detector));
129− DBG(tPitchDetector_getPeriodicity(&detector));
136+ DBG(tDualPitchDetector_getFrequency(&detector));
137+ DBG(tDualPitchDetector_getPeriodicity(&detector));
130138 }
131139
132140 float val = getSliderValue("on/off");

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