History

add fidelity threshold to PeriodDetection, Retune, Autotune

Matthew Wang committed 6 years ago

Commit 39c879d1 parent 7e988ac4 files · +61 −31Browse files

Unified · Split

4 files
  1. LEAF/Inc/leaf-analysis.h +6 −2
  2. LEAF/Inc/leaf-effects.h +31 −28
  3. LEAF/Src/leaf-analysis.c +10 −1
  4. LEAF/Src/leaf-effects.c +14 −0
LEAF/Inc/leaf-analysis.h+6−2
@@ -152,6 +152,7 @@ extern "C" { · 151 unmodified lines
152152 //==============================================================================
153153
154154 // tSNAC: period detector
155+ // from Katja Vetters http://www.katjaas.nl/helmholtz/helmholtz.html
155156 #define SNAC_FRAME_SIZE 1024 // default analysis framesize // should be the same as (or smaller than?) PS_FRAME_SIZE
156157 #define DEFOVERLAP 1 // default overlap
157158 #define DEFBIAS 0.2f // default bias
@@ -228,6 +229,8 @@ extern "C" { · 70 unmodified lines
228229 float lastmax;
229230 float deltamax;
230231
232+ float fidelityThreshold;
233+
231234 } _tPeriodDetection;
232235
233236 typedef _tPeriodDetection* tPeriodDetection;
@@ -239,8 +242,9 @@ extern "C" { · 5 unmodified lines
239242
240243 float tPeriodDetection_tick (tPeriodDetection* const, float sample);
241244 float tPeriodDetection_getPeriod (tPeriodDetection* const);
242− void tPeriodDetection_setHopSize (tPeriodDetection* p, int hs);
243− void tPeriodDetection_setWindowSize (tPeriodDetection* p, int ws);
245+ void tPeriodDetection_setHopSize (tPeriodDetection* const, int hs);
246+ void tPeriodDetection_setWindowSize (tPeriodDetection* const, int ws);
247+ void tPeriodDetection_setFidelityThreshold(tPeriodDetection* const, float threshold);
244248
245249 //==============================================================================
246250
LEAF/Inc/leaf-effects.h+31−28
@@ -99,6 +99,7 @@ extern "C" { · 98 unmodified lines
9999 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
100100
101101 /* tSOLAD : pitch shifting algorithm that underlies tRetune etc */
102+ // from Katja Vetters http://www.katjaas.nl/pitchshiftlowlatency/pitchshiftlowlatency.html
102103 #define LOOPSIZE (2048*2) // (4096*2) // loop size must be power of two
103104 #define LOOPMASK (LOOPSIZE - 1)
104105 #define PITCHFACTORDEFAULT 1.0f
@@ -199,20 +200,21 @@ extern "C" { · 94 unmodified lines
199200
200201 typedef _tRetune* tRetune;
201202
202− void tRetune_init (tRetune* const, int numVoices, int bufSize, int frameSize);
203− void tRetune_free (tRetune* const);
204− void tRetune_initToPool (tRetune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
205− void tRetune_freeFromPool (tRetune* const, tMempool* const);
206−
207− float* tRetune_tick (tRetune* const, float sample);
208− void tRetune_setNumVoices (tRetune* const, int numVoices);
209− void tRetune_setPitchFactors (tRetune* const, float pf);
210− void tRetune_setPitchFactor (tRetune* const, float pf, int voice);
211− void tRetune_setTimeConstant (tRetune* const, float tc);
212− void tRetune_setHopSize (tRetune* const, int hs);
213− void tRetune_setWindowSize (tRetune* const, int ws);
214− float tRetune_getInputPeriod (tRetune* const);
215− float tRetune_getInputFreq (tRetune* const);
203+ void tRetune_init (tRetune* const, int numVoices, int bufSize, int frameSize);
204+ void tRetune_free (tRetune* const);
205+ void tRetune_initToPool (tRetune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
206+ void tRetune_freeFromPool (tRetune* const, tMempool* const);
207+
208+ float* tRetune_tick (tRetune* const, float sample);
209+ void tRetune_setNumVoices (tRetune* const, int numVoices);
210+ void tRetune_setPitchFactors (tRetune* const, float pf);
211+ void tRetune_setPitchFactor (tRetune* const, float pf, int voice);
212+ void tRetune_setTimeConstant (tRetune* const, float tc);
213+ void tRetune_setHopSize (tRetune* const, int hs);
214+ void tRetune_setWindowSize (tRetune* const, int ws);
215+ void tRetune_setFidelityThreshold(tRetune* const, float threshold);
216+ float tRetune_getInputPeriod (tRetune* const);
217+ float tRetune_getInputFreq (tRetune* const);
216218
217219 // Autotune
218220 typedef struct _tAutotune
@@ -241,20 +243,21 @@ extern "C" { · 22 unmodified lines
241243
242244 typedef _tAutotune* tAutotune;
243245
244− void tAutotune_init (tAutotune* const, int numVoices, int bufSize, int frameSize);
245− void tAutotune_free (tAutotune* const);
246− void tAutotune_initToPool (tAutotune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
247− void tAutotune_freeFromPool (tAutotune* const, tMempool* const);
248−
249− float* tAutotune_tick (tAutotune* const, float sample);
250− void tAutotune_setNumVoices (tAutotune* const, int numVoices);
251− void tAutotune_setFreqs (tAutotune* const, float f);
252− void tAutotune_setFreq (tAutotune* const, float f, int voice);
253− void tAutotune_setTimeConstant (tAutotune* const, float tc);
254− void tAutotune_setHopSize (tAutotune* const, int hs);
255− void tAutotune_setWindowSize (tAutotune* const, int ws);
256− float tAutotune_getInputPeriod (tAutotune* const);
257− float tAutotune_getInputFreq (tAutotune* const);
246+ void tAutotune_init (tAutotune* const, int numVoices, int bufSize, int frameSize);
247+ void tAutotune_free (tAutotune* const);
248+ void tAutotune_initToPool (tAutotune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
249+ void tAutotune_freeFromPool (tAutotune* const, tMempool* const);
250+
251+ float* tAutotune_tick (tAutotune* const, float sample);
252+ void tAutotune_setNumVoices (tAutotune* const, int numVoices);
253+ void tAutotune_setFreqs (tAutotune* const, float f);
254+ void tAutotune_setFreq (tAutotune* const, float f, int voice);
255+ void tAutotune_setTimeConstant (tAutotune* const, float tc);
256+ void tAutotune_setHopSize (tAutotune* const, int hs);
257+ void tAutotune_setWindowSize (tAutotune* const, int ws);
258+ void tAutotune_setFidelityThreshold (tAutotune* const, float threshold);
259+ float tAutotune_getInputPeriod (tAutotune* const);
260+ float tAutotune_getInputFreq (tAutotune* const);
258261
259262 //==============================================================================
260263
LEAF/Src/leaf-analysis.c+10−1
@@ -872,6 +872,7 @@ void tPeriodDetection_initToPool (tPeriodDetection* const pd, float* in, flo · 871 unmodified lines
872872
873873 p->timeConstant = DEFTIMECONSTANT;
874874 p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
875+ p->fidelityThreshold = 0.95;
875876 }
876877
877878 void tPeriodDetection_freeFromPool (tPeriodDetection* const pd, tMempool* const mp)
@@ -907,7 +908,9 @@ float tPeriodDetection_tick (tPeriodDetection* pd, float sample) · 29 unmodified lines
907908 tEnvPD_processBlock(&p->env, &(p->inBuffer[i]));
908909
909910 tSNAC_ioSamples(&p->snac, &(p->inBuffer[i]), &(p->outBuffer[i]), p->frameSize);
910− p->period = tSNAC_getPeriod(&p->snac);
911+ float fidelity = tSNAC_getFidelity(&p->snac);
912+ // Fidelity threshold recommended by Katja Vetters is 0.95 for most instruments/voices http://www.katjaas.nl/helmholtz/helmholtz.html
913+ if (fidelity > p->fidelityThreshold) p->period = tSNAC_getPeriod(&p->snac);
911914
912915 p->curBlock++;
913916 if (p->curBlock >= p->framesPerBuffer) p->curBlock = 0;
@@ -935,3 +938,9 @@ void tPeriodDetection_setWindowSize(tPeriodDetection* pd, int ws) · 21 unmodified lines
935938 _tPeriodDetection* p = *pd;
936939 p->windowSize = ws;
937940 }
941+
942+void tPeriodDetection_setFidelityThreshold(tPeriodDetection* pd, float threshold)
943+{
944+ _tPeriodDetection* p = *pd;
945+ p->fidelityThreshold = threshold;
946+}
LEAF/Src/leaf-effects.c+14−0
@@ -1206,6 +1206,13 @@ void tRetune_setWindowSize(tRetune* const rt, int ws) · 1205 unmodified lines
12061206 tPeriodDetection_setWindowSize(&r->pd, r->windowSize);
12071207 }
12081208
1209+void tRetune_setFidelityThreshold(tRetune* const rt, float threshold)
1210+{
1211+ _tRetune* r = *rt;
1212+
1213+ tPeriodDetection_setFidelityThreshold(&r->pd, threshold);
1214+}
1215+
12091216 float tRetune_getInputPeriod(tRetune* const rt)
12101217 {
12111218 _tRetune* r = *rt;
@@ -1374,6 +1381,13 @@ void tAutotune_setWindowSize(tAutotune* const rt, int ws) · 162 unmodified lines
13741381 tPeriodDetection_setWindowSize(&r->pd, r->windowSize);
13751382 }
13761383
1384+void tAutotune_setFidelityThreshold(tAutotune* const rt, float threshold)
1385+{
1386+ _tAutotune* r = *rt;
1387+
1388+ tPeriodDetection_setFidelityThreshold(&r->pd, threshold);
1389+}
1390+
13771391 float tAutotune_getInputPeriod(tAutotune* const rt)
13781392 {
13791393 _tAutotune* r = *rt;

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