aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJamie Bullock <jamie@postlude.co.uk>2006-10-09 09:22:03 +0000
committerJamie Bullock <jamie@postlude.co.uk>2006-10-09 09:22:03 +0000
commitc6e4f6421b2a72e33e21b53ee2838532d8958a8d (patch)
treec650474cd5f53e515f77d32ce961ed322dec960d /src
parent9bcdb2f6cb48da938975f618e36ebd54f67766cb (diff)
downloadLibXtract-c6e4f6421b2a72e33e21b53ee2838532d8958a8d.tar.gz
LibXtract-c6e4f6421b2a72e33e21b53ee2838532d8958a8d.tar.bz2
LibXtract-c6e4f6421b2a72e33e21b53ee2838532d8958a8d.zip
Added f0 estimation (based on AMDF)
Diffstat (limited to 'src')
-rw-r--r--src/scalar.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/scalar.c b/src/scalar.c
index 111c300..95c77a0 100644
--- a/src/scalar.c
+++ b/src/scalar.c
@@ -436,6 +436,25 @@ int xtract_hps(float *data, int N, void *argv, float *result){
int xtract_f0(float *data, int N, void *argv, float *result){
- NOT_IMPLEMENTED;
-
+ int M, sr, tau, n;
+ float f0, err_tau_1, err_tau_x;
+
+ sr = *(float*)argv;
+ M = N >> 1;
+ err_tau_1 = 0;
+ for (n = 1; n < M; n++){
+ err_tau_1 = err_tau_1 + fabs(data[n] - data[n+1]);
+ }
+ for (tau = 2; tau < M; tau++){
+ err_tau_x = 0;
+ for (n = 1; n < M; n++){
+ err_tau_x = err_tau_x + fabs(data[n] - data[n+tau]);
+ }
+ if (err_tau_x < err_tau_1) {
+ f0 = sr / (tau + (err_tau_x / err_tau_1));
+ *result = f0;
+ return SUCCESS;
+ }
+ }
+ return NO_RESULT;
}