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
152 //==============================================================================152 //==============================================================================
153 153
154 // tSNAC: period detector154 // tSNAC: period detector
155 // from Katja Vetters http://www.katjaas.nl/helmholtz/helmholtz.html
155#define SNAC_FRAME_SIZE 1024 // default analysis framesize // should be the same as (or smaller than?) PS_FRAME_SIZE156#define SNAC_FRAME_SIZE 1024 // default analysis framesize // should be the same as (or smaller than?) PS_FRAME_SIZE
156#define DEFOVERLAP 1 // default overlap157#define DEFOVERLAP 1 // default overlap
157#define DEFBIAS 0.2f // default bias158#define DEFBIAS 0.2f // default bias
@@ -228,6 +229,8 @@ extern "C" { · 70 unmodified lines
228 float lastmax;229 float lastmax;
229 float deltamax;230 float deltamax;
230 231
232 float fidelityThreshold;
233
231 } _tPeriodDetection;234 } _tPeriodDetection;
232 235
233 typedef _tPeriodDetection* tPeriodDetection;236 typedef _tPeriodDetection* tPeriodDetection;
@@ -239,8 +242,9 @@ extern "C" { · 5 unmodified lines
239 242
240 float tPeriodDetection_tick (tPeriodDetection* const, float sample);243 float tPeriodDetection_tick (tPeriodDetection* const, float sample);
241 float tPeriodDetection_getPeriod (tPeriodDetection* const);244 float tPeriodDetection_getPeriod (tPeriodDetection* const);
242 void tPeriodDetection_setHopSize (tPeriodDetection* p, int hs);245 void tPeriodDetection_setHopSize (tPeriodDetection* const, int hs);
243 void tPeriodDetection_setWindowSize (tPeriodDetection* p, int ws);246 void tPeriodDetection_setWindowSize (tPeriodDetection* const, int ws);
247 void tPeriodDetection_setFidelityThreshold(tPeriodDetection* const, float threshold);
244 248
245 //==============================================================================249 //==============================================================================
246 250
LEAF/Inc/leaf-effects.h+31−28
@@ -99,6 +99,7 @@ extern "C" { · 98 unmodified lines
99 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~99 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
100 100
101 /* tSOLAD : pitch shifting algorithm that underlies tRetune etc */101 /* tSOLAD : pitch shifting algorithm that underlies tRetune etc */
102 // from Katja Vetters http://www.katjaas.nl/pitchshiftlowlatency/pitchshiftlowlatency.html
102#define LOOPSIZE (2048*2) // (4096*2) // loop size must be power of two103#define LOOPSIZE (2048*2) // (4096*2) // loop size must be power of two
103#define LOOPMASK (LOOPSIZE - 1)104#define LOOPMASK (LOOPSIZE - 1)
104#define PITCHFACTORDEFAULT 1.0f105#define PITCHFACTORDEFAULT 1.0f
@@ -199,20 +200,21 @@ extern "C" { · 94 unmodified lines
199 200
200 typedef _tRetune* tRetune;201 typedef _tRetune* tRetune;
201 202
202 void tRetune_init (tRetune* const, int numVoices, int bufSize, int frameSize);203 void tRetune_init (tRetune* const, int numVoices, int bufSize, int frameSize);
203 void tRetune_free (tRetune* const);204 void tRetune_free (tRetune* const);
204 void tRetune_initToPool (tRetune* const, int numVoices, int bufSize, int frameSize, tMempool* const);205 void tRetune_initToPool (tRetune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
205 void tRetune_freeFromPool (tRetune* const, tMempool* const);206 void tRetune_freeFromPool (tRetune* const, tMempool* const);
206 207
207 float* tRetune_tick (tRetune* const, float sample);208 float* tRetune_tick (tRetune* const, float sample);
208 void tRetune_setNumVoices (tRetune* const, int numVoices);209 void tRetune_setNumVoices (tRetune* const, int numVoices);
209 void tRetune_setPitchFactors (tRetune* const, float pf);210 void tRetune_setPitchFactors (tRetune* const, float pf);
210 void tRetune_setPitchFactor (tRetune* const, float pf, int voice);211 void tRetune_setPitchFactor (tRetune* const, float pf, int voice);
211 void tRetune_setTimeConstant (tRetune* const, float tc);212 void tRetune_setTimeConstant (tRetune* const, float tc);
212 void tRetune_setHopSize (tRetune* const, int hs);213 void tRetune_setHopSize (tRetune* const, int hs);
213 void tRetune_setWindowSize (tRetune* const, int ws);214 void tRetune_setWindowSize (tRetune* const, int ws);
214 float tRetune_getInputPeriod (tRetune* const);215 void tRetune_setFidelityThreshold(tRetune* const, float threshold);
215 float tRetune_getInputFreq (tRetune* const);216 float tRetune_getInputPeriod (tRetune* const);
217 float tRetune_getInputFreq (tRetune* const);
216 218
217 // Autotune219 // Autotune
218 typedef struct _tAutotune220 typedef struct _tAutotune
@@ -241,20 +243,21 @@ extern "C" { · 22 unmodified lines
241 243
242 typedef _tAutotune* tAutotune;244 typedef _tAutotune* tAutotune;
243 245
244 void tAutotune_init (tAutotune* const, int numVoices, int bufSize, int frameSize);246 void tAutotune_init (tAutotune* const, int numVoices, int bufSize, int frameSize);
245 void tAutotune_free (tAutotune* const);247 void tAutotune_free (tAutotune* const);
246 void tAutotune_initToPool (tAutotune* const, int numVoices, int bufSize, int frameSize, tMempool* const);248 void tAutotune_initToPool (tAutotune* const, int numVoices, int bufSize, int frameSize, tMempool* const);
247 void tAutotune_freeFromPool (tAutotune* const, tMempool* const);249 void tAutotune_freeFromPool (tAutotune* const, tMempool* const);
248 250
249 float* tAutotune_tick (tAutotune* const, float sample);251 float* tAutotune_tick (tAutotune* const, float sample);
250 void tAutotune_setNumVoices (tAutotune* const, int numVoices);252 void tAutotune_setNumVoices (tAutotune* const, int numVoices);
251 void tAutotune_setFreqs (tAutotune* const, float f);253 void tAutotune_setFreqs (tAutotune* const, float f);
252 void tAutotune_setFreq (tAutotune* const, float f, int voice);254 void tAutotune_setFreq (tAutotune* const, float f, int voice);
253 void tAutotune_setTimeConstant (tAutotune* const, float tc);255 void tAutotune_setTimeConstant (tAutotune* const, float tc);
254 void tAutotune_setHopSize (tAutotune* const, int hs);256 void tAutotune_setHopSize (tAutotune* const, int hs);
255 void tAutotune_setWindowSize (tAutotune* const, int ws);257 void tAutotune_setWindowSize (tAutotune* const, int ws);
256 float tAutotune_getInputPeriod (tAutotune* const);258 void tAutotune_setFidelityThreshold (tAutotune* const, float threshold);
257 float tAutotune_getInputFreq (tAutotune* const);259 float tAutotune_getInputPeriod (tAutotune* const);
260 float tAutotune_getInputFreq (tAutotune* const);
258 261
259 //==============================================================================262 //==============================================================================
260 263
LEAF/Src/leaf-analysis.c+10−1
@@ -872,6 +872,7 @@ void tPeriodDetection_initToPool (tPeriodDetection* const pd, float* in, flo · 871 unmodified lines
872 872
873 p->timeConstant = DEFTIMECONSTANT;873 p->timeConstant = DEFTIMECONSTANT;
874 p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);874 p->radius = expf(-1000.0f * p->hopSize * leaf.invSampleRate / p->timeConstant);
875 p->fidelityThreshold = 0.95;
875}876}
876 877
877void tPeriodDetection_freeFromPool (tPeriodDetection* const pd, tMempool* const mp)878void tPeriodDetection_freeFromPool (tPeriodDetection* const pd, tMempool* const mp)
@@ -907,7 +908,9 @@ float tPeriodDetection_tick (tPeriodDetection* pd, float sample) · 29 unmodified lines
907 tEnvPD_processBlock(&p->env, &(p->inBuffer[i]));908 tEnvPD_processBlock(&p->env, &(p->inBuffer[i]));
908 909
909 tSNAC_ioSamples(&p->snac, &(p->inBuffer[i]), &(p->outBuffer[i]), p->frameSize);910 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);
911 914
912 p->curBlock++;915 p->curBlock++;
913 if (p->curBlock >= p->framesPerBuffer) p->curBlock = 0;916 if (p->curBlock >= p->framesPerBuffer) p->curBlock = 0;
@@ -935,3 +938,9 @@ void tPeriodDetection_setWindowSize(tPeriodDetection* pd, int ws) · 21 unmodified lines
935 _tPeriodDetection* p = *pd;938 _tPeriodDetection* p = *pd;
936 p->windowSize = ws;939 p->windowSize = ws;
937}940}
941
942void 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
1206 tPeriodDetection_setWindowSize(&r->pd, r->windowSize);1206 tPeriodDetection_setWindowSize(&r->pd, r->windowSize);
1207}1207}
1208 1208
1209void tRetune_setFidelityThreshold(tRetune* const rt, float threshold)
1210{
1211 _tRetune* r = *rt;
1212
1213 tPeriodDetection_setFidelityThreshold(&r->pd, threshold);
1214}
1215
1209float tRetune_getInputPeriod(tRetune* const rt)1216float tRetune_getInputPeriod(tRetune* const rt)
1210{1217{
1211 _tRetune* r = *rt;1218 _tRetune* r = *rt;
@@ -1374,6 +1381,13 @@ void tAutotune_setWindowSize(tAutotune* const rt, int ws) · 162 unmodified lines
1374 tPeriodDetection_setWindowSize(&r->pd, r->windowSize);1381 tPeriodDetection_setWindowSize(&r->pd, r->windowSize);
1375}1382}
1376 1383
1384void tAutotune_setFidelityThreshold(tAutotune* const rt, float threshold)
1385{
1386 _tAutotune* r = *rt;
1387
1388 tPeriodDetection_setFidelityThreshold(&r->pd, threshold);
1389}
1390
1377float tAutotune_getInputPeriod(tAutotune* const rt)1391float tAutotune_getInputPeriod(tAutotune* const rt)
1378{1392{
1379 _tAutotune* r = *rt;1393 _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