History

more pitch detection testing; using both algs and only setting pitch when they match within some error works decently but at the cost of running both; at least suggests that they tend to make different errors

Matthew Wang committed 6 years ago

Commit d634fb31 parent 45af5ea3 files · +21 −13Browse files

Unified · Split

3 files
  1. TestPlugin/Source/MyTest.cpp +15 −11
  2. leaf/Inc/leaf-analysis.h +2 −2
  3. leaf/Src/leaf-oscillators.c +4 −0
TestPlugin/Source/MyTest.cpp+15−11
@@ -40,6 +40,8 @@ tPeriodDetection pd; · 39 unmodified lines
4040 tZeroCrossingCounter zc;
4141 tEnvelopeFollower ef;
4242
43+tCycle sine;
44+
4345 float gain;
4446 float dtime;
4547 bool buttonState;
@@ -71,6 +73,9 @@ void LEAFTest_init (float sampleRate, int blockSize) · 25 unmodified lines
7173
7274 tZeroCrossingCounter_init(&zc, 128);
7375 tEnvelopeFollower_init(&ef, 0.02f, 0.9999f);
76+
77+ tCycle_init(&sine);
78+ tCycle_setFreq(&sine, 100);
7479 }
7580
7681 inline double getSawFall(double angle) {
@@ -99,32 +104,31 @@ float LEAFTest_tick (float input) · 22 unmodified lines
99104
100105 float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
101106 tPitchDetector_tick(&detector, input);
107+ float altFreq = tPitchDetector_getFrequency(&detector);
102108
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;
108− }
109−
109+ if (fabsf(1.0f - (freq / altFreq)) < 0.05f)
110110 // if (tZeroCrossingCounter_tick(&zc, input) < 0.05 && freq > 0.0f)
111111 {
112− tMBTriangle_setFreq(&btri, freq);
112+ tCycle_setFreq(&sine, altFreq);
113113 }
114114
115115 float g = tEnvelopeFollower_tick(&ef, input);
116116
117117 lastFreq = freq;
118118
119− return input + tMBTriangle_tick(&btri) * g * 10.0f;
119+ return tCycle_tick(&sine) * g * 2.0f + input;
120120 }
121121
122122 int firstFrame = 1;
123123 bool lastState = false, lastPlayState = false;
124124 void LEAFTest_block (void)
125125 {
126− DBG(tPitchDetector_getFrequency(&detector));
127− DBG(tPitchDetector_getPeriodicity(&detector));
126+ float periodicity = tPitchDetector_getPeriodicity(&detector);
127+ if (periodicity > 0.99f)
128+ {
129+ DBG(tPitchDetector_getFrequency(&detector));
130+ DBG(tPitchDetector_getPeriodicity(&detector));
131+ }
128132 // if (firstFrame == 1)
129133 // {
130134 // tBuffer_record(&buff); // starts recording
leaf/Inc/leaf-analysis.h+2−2
@@ -713,8 +713,8 @@ extern "C" { · 712 unmodified lines
713713 @} */
714714
715715 #define PULSE_THRESHOLD 0.6f
716−#define HARMONIC_PERIODICITY_FACTOR 16
717−#define PERIODICITY_DIFF_FACTOR 0.008f
716+#define HARMONIC_PERIODICITY_FACTOR 16 //16
717+#define PERIODICITY_DIFF_FACTOR 0.008f //0.008f
718718
719719 typedef struct _auto_correlation_info
720720 {
leaf/Src/leaf-oscillators.c+4−0
@@ -45,6 +45,8 @@ void tTable_setFreq(tTable* const cy, float freq) · 44 unmodified lines
4545 {
4646 _tTable* c = *cy;
4747
48+ if (!isfinite(freq)) return;
49+
4850 c->freq = freq;
4951 c->inc = freq * leaf.invSampleRate;
5052 }
@@ -110,6 +112,8 @@ void tCycle_setFreq(tCycle* const cy, float freq) · 59 unmodified lines
110112 {
111113 _tCycle* c = *cy;
112114
115+ if (!isfinite(freq)) return;
116+
113117 c->freq = freq;
114118
115119 c->inc = freq * leaf.invSampleRate;

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