summaryrefslogtreecommitdiffhomepage
path: root/src/lingot-yin.c
diff options
context:
space:
mode:
authorpp <pp@455248ca-bdda-0310-9134-f4ebb693071a>2008-03-23 17:38:12 +0000
committerpp <pp@455248ca-bdda-0310-9134-f4ebb693071a>2008-03-23 17:38:12 +0000
commit6e38dfa629db5d34071c7d891633fe5dae52a2f1 (patch)
treea50eb805497e4bf77dc2d349c7745186daa3a7f7 /src/lingot-yin.c
parent8c1d9e64746debf06465fb5213f37159e69b1592 (diff)
- YIN estimator improvements:master
- minimum detection now operates on interpolated values - period calculation now interpolates raw difference function, as interpolation of the normalized function is said to be slightly biased - added high threshold parameter, above which the result is ignored (no note detected) git-svn-id: https://lampka.siedziba.pl:790/svn/repos/lingot-win32@314 455248ca-bdda-0310-9134-f4ebb693071a
Diffstat (limited to 'src/lingot-yin.c')
-rw-r--r--src/lingot-yin.c58
1 files changed, 38 insertions, 20 deletions
diff --git a/src/lingot-yin.c b/src/lingot-yin.c
index 05eaa59..42e478e 100644
--- a/src/lingot-yin.c
+++ b/src/lingot-yin.c
@@ -34,41 +34,59 @@ inline FLT yin_sqr(FLT x)
return x*x;
}
-inline FLT yin_interpolate_tau(FLT y1, FLT y2, FLT y3)
+inline FLT yin_interpolate_x(FLT y1, FLT y2, FLT y3)
{
+ if ((y1 == y2) && (y2 == y3)) return 0;
return ((y1 - y3)/(2.0*(y3 + y1 - (2.0*y2))));
}
-FLT yin(LingotCore* core) {
- FLT dt_tau;
+inline FLT yin_interpolate_y(FLT y1, FLT y2, FLT y3)
+{
+ if ((y1 == y2) && (y2 == y3)) return y1;
+ return (((6.0 * y2) - y1 + (3.0 * y3) - (4.0 * yin_sqr(y2 - y3) / (y3 - (2.0 * y2) + y1))) / 8.0);
+}
+
+void yin(LingotCore* core) {
+ FLT dt_tau[3];
FLT dt_tau_sum = 0;
- FLT dpt_right = 1.0/0.0, dpt_center, dpt_left;
- FLT thr = core->conf->yin_threshold;
+ FLT dpt[3];
+ FLT thr_low = core->conf->yin_threshold_low;
+ FLT thr_high = core->conf->yin_threshold_high;
FLT dpt_min = 1.0/0.0;
- FLT dpt_min_left, dpt_min_right;
- int j, tau, tau_min;
+ FLT dpt_interpolated;
+ FLT tau_min;
+ int j, tau;
int len = core->conf->temporal_buffer_size / 2;
- for (tau = 1; (tau < len) && ((dpt_center > thr) || (dpt_right < dpt_center) || (tau <= 2)); tau++)
+ for (tau = 1; tau < len; tau++)
{
- dt_tau = 0;
+ dt_tau[0] = dt_tau[1];
+ dt_tau[1] = dt_tau[2];
+ dt_tau[2] = 0;
for (j = 0; j < len ; j++)
{
- dt_tau += yin_sqr(core->temporal_buffer[j] - core->temporal_buffer[j+tau]);
+ dt_tau[2] += yin_sqr(core->temporal_buffer[j] - core->temporal_buffer[j+tau]);
}
- dt_tau_sum += dt_tau;
+ dt_tau_sum += dt_tau[2];
- dpt_left = dpt_center;
- dpt_center = dpt_right;
- dpt_right = dt_tau / ( 1.0 / tau * dt_tau_sum );
+ dpt[0] = dpt[1];
+ dpt[1] = dpt[2];
+ dpt[2] = dt_tau[2] / ( 1.0 / tau * dt_tau_sum );
- if (dpt_center < dpt_min)
+ if (tau >= 3)
{
- dpt_min_left = dpt_left;
- dpt_min = dpt_center;
- dpt_min_right = dpt_right;
- tau_min = tau - 1;
+ if ((dpt[1] <= dpt[0]) && (dpt[1] <= dpt[2]))
+ {
+// we have local minimum
+ dpt_interpolated = yin_interpolate_y(dpt[0], dpt[1], dpt[2]);
+ if (dpt_interpolated < dpt_min)
+ {
+ dpt_min = dpt_interpolated;
+ tau_min = (FLT)tau - 1 + yin_interpolate_x(dt_tau[0], dt_tau[1], dt_tau[2]);
+ if (dpt_min < thr_low) break;
+ }
+ }
}
}
- return (FLT)tau_min + yin_interpolate_tau(dpt_min_left, dpt_min, dpt_min_right);
+ if ((tau_min > 1) && (dpt_min < thr_high)) core->freq = core->conf->sample_rate / (FLT)core->conf->oversampling / tau_min; else core->freq = 0;
}