History

getting new pitch detection working in retune and autotune

Matthew Wang committed 6 years ago

Commit 11c878e1 parent 17430886 files · +157 −531Browse files

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

Unified · Split

TestPlugin/Source/MyTest.cpp+14−86
@@ -18,7 +18,8 @@ tMBSaw bsaw; · 17 unmodified lines
18tMBTriangle btri;18tMBTriangle btri;
19tMBPulse bpulse;19tMBPulse bpulse;
20 20
21tDualPitchDetector detector;21tRetune retune;
22tAutotune autotune;
22 23
23tCompressor compressor;24tCompressor compressor;
24 25
@@ -54,33 +55,8 @@ void LEAFTest_init (float sampleRate, int blockSize) · 29 unmodified lines
54{55{
55 LEAF_init(&leaf, sampleRate, blockSize, memory, MSIZE, &getRandomFloat);56 LEAF_init(&leaf, sampleRate, blockSize, memory, MSIZE, &getRandomFloat);
56 57
57 tMBSaw_init(&bsaw, &leaf);58 tRetune_init(&retune, 1, 1024, &leaf);
58 tMBTriangle_init(&btri, &leaf);59 tAutotune_init(&autotune, 1, 1024, &leaf);
59 tMBPulse_init(&bpulse, &leaf);
60
61 bufIn = (float*) leaf_alloc(&leaf, sizeof(float) * 4096);
62 bufOut = (float*) leaf_alloc(&leaf, sizeof(float) * 4096);
63
64 tDualPitchDetector_init(&detector, mtof(48), mtof(84), &leaf);
65
66 tCompressor_init(&compressor, &leaf);
67
68 tSVF_init(&lp, SVFTypeLowpass, mtof(84) * 2.0f, 1.0f, &leaf);
69 tSVF_init(&hp, SVFTypeHighpass, mtof(48) * 0.5f, 1.0f, &leaf);
70
71 tPeriodDetection_init(&pd, bufIn, bufOut, 4096, 1024, &leaf);
72
73 tZeroCrossingCounter_init(&zc, 128, &leaf);
74 tEnvelopeFollower_init(&ef, 0.02f, 0.9999f, &leaf);
75
76 tTriangle_init(&tri, &leaf);
77 tTriangle_setFreq(&tri, 100);
78
79 tBuffer_init(&samp, 5.0f * leaf.sampleRate, &leaf);
80 tMBSampler_init(&sampler, &samp, &leaf);
81
82 tMBSampler_setMode(&sampler, PlayLoop);
83 tMBSampler_setEnd(&sampler, samp->bufferLength);
84}60}
85 61
86inline double getSawFall(double angle) {62inline double getSawFall(double angle) {
@@ -94,72 +70,24 @@ inline double getSawFall(double angle) { · 7 unmodified lines
94 70
95float LEAFTest_tick (float input)71float LEAFTest_tick (float input)
96{72{
97 tBuffer_tick(&samp, input);73// return tRetune_tick(&retune, input);
98 74 return tAutotune_tick(&autotune, input);
99 return tMBSampler_tick(&sampler);
100
101
102// tMBSaw_setFreq(&bsaw, x);
103// tMBTriangle_setFreq(&btri, x);
104// tMBPulse_setFreq(&bpulse, x);
105//
106// tMBTriangle_setWidth(&btri, y);
107// tMBPulse_setWidth(&bpulse, y);
108//
109//// return tMBSaw_tick(&bsaw);
110//// return tMBTriangle_tick(&btri);
111// return tMBPulse_tick(&bpulse);
112
113// input = tSVF_tick(&hp, tSVF_tick(&lp, tCompressor_tick(&compressor, input)));
114//
115//// float freq = 1.0f/tPeriodDetection_tick(&pd, input) * leaf.sampleRate;
116// tDualPitchDetector_tick(&detector, input);
117// float altFreq = tDualPitchDetector_getFrequency(&detector);
118//
119//// if (fabsf(1.0f - (freq / altFreq)) < 0.05f)
120//// if (tZeroCrossingCounter_tick(&zc, input) < 0.05 && freq > 0.0f)
121// if (altFreq > 0.0f)
122// {
123// tTriangle_setFreq(&tri, altFreq);
124// }
125//
126// float g = tEnvelopeFollower_tick(&ef, input);
127//
128// return tTriangle_tick(&tri) * g;
129}75}
130 76
131int firstFrame = 1;77int firstFrame = 1;
132bool lastState = false, lastPlayState = false;78bool lastState = false, lastPlayState = false;
133void LEAFTest_block (void)79void LEAFTest_block (void)
134{80{
135 float periodicity = tDualPitchDetector_getPeriodicity(&detector);81 float val = getSliderValue("slider1");
136 if (periodicity > 0.99f)82// tRetune_setPitchFactor(&retune, val * 3.0f + 0.5f, 0);
137 {83 tAutotune_setFreq(&autotune, 300, 0);
138 DBG(tDualPitchDetector_getFrequency(&detector));
139 DBG(tDualPitchDetector_getPeriodicity(&detector));
140 }
141
142 float val = getSliderValue("on/off");
143
144 if (val > 0.5f && !sampler->active)
145 {
146 tBuffer_record(&samp);
147 tMBSampler_play(&sampler);
148 }
149 else if (val < 0.5f && sampler->active)
150 {
151 tMBSampler_stop(&sampler);
152 }
153
154 val = getSliderValue("mod freq");
155
156 tMBSampler_setStart(&sampler, val * 5.0f * leaf.sampleRate);
157 84
85 val = getSliderValue("slider2");
86// tRetune_setPitchFactor(&retune, val * 3.0f + 0.5f, 1);
158 87
159 val = getSliderValue("mod depth");88 val = getSliderValue("slider3");
160 89// tRetune_setPitchFactor(&retune, val * 3.0f + 0.5f, 2);
161 tMBSampler_setRate(&sampler, val * 8.0f - 4.0f);90
162
163}91}
164 92
165void LEAFTest_controllerInput (int cnum, float cval)93void LEAFTest_controllerInput (int cnum, float cval)

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