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
18tMBTriangle btri;18tMBTriangle btri;
19tMBPulse bpulse;19tMBPulse bpulse;
20 20
21tPitchDetector detector;21tDualPitchDetector detector;
22
23tCompressor compressor;
24
25tSVF lp, hp;
22 26
23tPeriodDetection pd;27tPeriodDetection pd;
24 28
25tZeroCrossingCounter zc;29tZeroCrossingCounter zc;
26tEnvelopeFollower ef;30tEnvelopeFollower ef;
27 31
28tCycle sine;32tTriangle tri;
29 33
30tBuffer samp;34tBuffer samp;
31tMBSampler sampler;35tMBSampler sampler;
@@ -54,16 +58,21 @@ void LEAFTest_init (float sampleRate, int blockSize) · 22 unmodified lines
54 58
55 bufIn = (float*) leaf_alloc(sizeof(float) * 4096);59 bufIn = (float*) leaf_alloc(sizeof(float) * 4096);
56 bufOut = (float*) leaf_alloc(sizeof(float) * 4096);60 bufOut = (float*) leaf_alloc(sizeof(float) * 4096);
57 // lowestFreq, highestFreq, hysteresis (width of hysteresis region around 0.0 for zero crossing detection)61
58 tPitchDetector_init(&detector, mtof(48), mtof(84), 0.01f);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);
59 68
60 tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024);69 tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024);
61 70
62 tZeroCrossingCounter_init(&zc, 128);71 tZeroCrossingCounter_init(&zc, 128);
63 tEnvelopeFollower_init(&ef, 0.02f, 0.9999f);72 tEnvelopeFollower_init(&ef, 0.02f, 0.9999f);
64 73
65 tCycle_init(&sine);74 tTriangle_init(&tri);
66 tCycle_setFreq(&sine, 100);75 tTriangle_setFreq(&tri, 100);
67 76
68 tBuffer_init(&samp, 5.0f * leaf.sampleRate);77 tBuffer_init(&samp, 5.0f * leaf.sampleRate);
69 tMBSampler_init(&sampler, &samp);78 tMBSampler_init(&sampler, &samp);
@@ -81,12 +90,11 @@ inline double getSawFall(double angle) { · 11 unmodified lines
81 90
82}91}
83 92
84float lastFreq;
85float LEAFTest_tick (float input)93float LEAFTest_tick (float input)
86{94{
87 tBuffer_tick(&samp, input);95// tBuffer_tick(&samp, input);
88 96//
89 return tMBSampler_tick(&sampler);97// return tMBSampler_tick(&sampler);
90 98
91 99
92// tMBSaw_setFreq(&bsaw, x);100// tMBSaw_setFreq(&bsaw, x);
@@ -99,34 +107,34 @@ float LEAFTest_tick (float input) · 6 unmodified lines
99//// return tMBSaw_tick(&bsaw);107//// return tMBSaw_tick(&bsaw);
100//// return tMBTriangle_tick(&btri);108//// return tMBTriangle_tick(&btri);
101// return tMBPulse_tick(&bpulse);109// return tMBPulse_tick(&bpulse);
102 110
111 input = tSVF_tick(&hp, tSVF_tick(&lp, tCompressor_tick(&compressor, input)));
103 112
104// float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;113// float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
105// tPitchDetector_tick(&detector, input);114 tDualPitchDetector_tick(&detector, input);
106// float altFreq = tPitchDetector_getFrequency(&detector);115 float altFreq = tDualPitchDetector_getFrequency(&detector);
107//116
108// if (fabsf(1.0f - (freq / altFreq)) < 0.05f)117// if (fabsf(1.0f - (freq / altFreq)) < 0.05f)
109//// if (tZeroCrossingCounter_tick(&zc, input) < 0.05 && freq > 0.0f)118// if (tZeroCrossingCounter_tick(&zc, input) < 0.05 && freq > 0.0f)
110// {119 if (altFreq > 0.0f)
111// tCycle_setFreq(&sine, altFreq);120 {
112// }121 tTriangle_setFreq(&tri, altFreq);
113//122 }
114// float g = tEnvelopeFollower_tick(&ef, input);123
115//124 float g = tEnvelopeFollower_tick(&ef, input);
116// lastFreq = freq;125
117//126 return tTriangle_tick(&tri) * g;
118// return tCycle_tick(&sine) * g * 2.0f + input;
119}127}
120 128
121int firstFrame = 1;129int firstFrame = 1;
122bool lastState = false, lastPlayState = false;130bool lastState = false, lastPlayState = false;
123void LEAFTest_block (void)131void LEAFTest_block (void)
124{132{
125 float periodicity = tPitchDetector_getPeriodicity(&detector);133 float periodicity = tDualPitchDetector_getPeriodicity(&detector);
126 if (periodicity > 0.99f)134 if (periodicity > 0.99f)
127 {135 {
128 DBG(tPitchDetector_getFrequency(&detector));136 DBG(tDualPitchDetector_getFrequency(&detector));
129 DBG(tPitchDetector_getPeriodicity(&detector));137 DBG(tDualPitchDetector_getPeriodicity(&detector));
130 }138 }
131 139
132 float val = getSliderValue("on/off");140 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