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
40tZeroCrossingCounter zc;40tZeroCrossingCounter zc;
41tEnvelopeFollower ef;41tEnvelopeFollower ef;
42 42
43tCycle sine;
44
43float gain;45float gain;
44float dtime;46float dtime;
45bool buttonState;47bool 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
76inline double getSawFall(double angle) {81inline 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
122int firstFrame = 1;122int firstFrame = 1;
123bool lastState = false, lastPlayState = false;123bool lastState = false, lastPlayState = false;
124void LEAFTest_block (void)124void 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 recording134 // tBuffer_record(&buff); // starts recording
leaf/Inc/leaf-analysis.h+2−2
@@ -713,8 +713,8 @@ extern "C" { · 712 unmodified lines
713 @} */713 @} */
714 714
715#define PULSE_THRESHOLD 0.6f715#define PULSE_THRESHOLD 0.6f
716#define HARMONIC_PERIODICITY_FACTOR 16716#define HARMONIC_PERIODICITY_FACTOR 16 //16
717#define PERIODICITY_DIFF_FACTOR 0.008f717#define PERIODICITY_DIFF_FACTOR 0.008f //0.008f
718 718
719 typedef struct _auto_correlation_info719 typedef struct _auto_correlation_info
720 {720 {
leaf/Src/leaf-oscillators.c+4−0
@@ -45,6 +45,8 @@ void tTable_setFreq(tTable* const cy, float freq) · 44 unmodified lines
45{45{
46 _tTable* c = *cy;46 _tTable* c = *cy;
47 47
48 if (!isfinite(freq)) return;
49
48 c->freq = freq;50 c->freq = freq;
49 c->inc = freq * leaf.invSampleRate;51 c->inc = freq * leaf.invSampleRate;
50}52}
@@ -110,6 +112,8 @@ void tCycle_setFreq(tCycle* const cy, float freq) · 59 unmodified lines
110{112{
111 _tCycle* c = *cy;113 _tCycle* c = *cy;
112 114
115 if (!isfinite(freq)) return;
116
113 c->freq = freq;117 c->freq = freq;
114 118
115 c->inc = freq * leaf.invSampleRate;119 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