From 5fe601c3f693ee4ac1569ba93e3614fd9a0f7501 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Wed, 2 Jan 2008 02:26:13 +0000 Subject: - Re-factoring in xtract_spectrum and fixed normalisation bug - Fixed bug in xtract_lnorm --- src/delta.c | 10 +++--- src/helper.c | 2 +- src/vector.c | 101 ++++++++++++++++++++++++++++++----------------------------- 3 files changed, 58 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/delta.c b/src/delta.c index 1591db3..25d380b 100644 --- a/src/delta.c +++ b/src/delta.c @@ -35,21 +35,21 @@ int xtract_lnorm(const float *data, const int N, const void *argv , float *resul int n, type; - float order, - temp = 0.f; + float order; order = *(float *)argv; - type = (int)*(float *)argv+1; + type = *((float *)argv+1); order = order > 0 ? order : 2.f; + *result = 0.f; + switch(type){ case XTRACT_POSITIVE_SLOPE: for(n = 0; n < N; n++){ - temp = powf(data[n], order); if(data[n] > 0) - *result += temp; + *result += powf(data[n], order); } break; default: diff --git a/src/helper.c b/src/helper.c index eceb290..60b3af7 100644 --- a/src/helper.c +++ b/src/helper.c @@ -45,7 +45,7 @@ int xtract_features_from_subframes(const float *data, const int N, const int fea float *result1, *result2; - int n, + int n, i, rv; n = N >> 1; diff --git a/src/vector.c b/src/vector.c index 0ffd8ae..c721be7 100644 --- a/src/vector.c +++ b/src/vector.c @@ -47,7 +47,8 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res float *input, *rfft, q, temp, max; size_t bytes; - int n, + int n, + m, NxN, M, vector, @@ -91,36 +92,37 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res temp = log(sqrt(temp) / N); else temp = XTRACT_LOG_LIMIT_DB; - if(withDC) { - result[n] = - /*Normalise*/ - (temp + XTRACT_DB_SCALE_OFFSET) / - XTRACT_DB_SCALE_OFFSET; - result[M + n + 1] = n * q; - } - else { - result[n - 1] = - (temp + XTRACT_DB_SCALE_OFFSET) / - XTRACT_DB_SCALE_OFFSET; - result[M + n - 1] = n * q; - } - max = result[n] > max ? result[n] : max; + + if(withDC){ + m = n; + result[M + m + 1] = n * q; + } + else{ + m = n - 1; + result[M + m] = n * q; + } + + result[m] = + /* Scaling */ + (temp + XTRACT_DB_SCALE_OFFSET) / + XTRACT_DB_SCALE_OFFSET; + + max = result[m] > max ? result[m] : max; } break; case XTRACT_POWER_SPECTRUM: for(n = 1; n < M; n++){ - if(withDC){ - result[n] = (XTRACT_SQ(rfft[n]) + XTRACT_SQ(rfft[N - n])) - / NxN; - result[M + n + 1] = n * q; - } - else { - result[n - 1] = - (XTRACT_SQ(rfft[n]) + XTRACT_SQ(rfft[N - n])) / NxN; - result[M + n - 1] = n * q; - } - max = result[n] > max ? result[n] : max; + if(withDC){ + m = n; + result[M + m + 1] = n * q; + } + else{ + m = n - 1; + result[M + m] = n * q; + } + result[m] = (XTRACT_SQ(rfft[n]) + XTRACT_SQ(rfft[N - n])) / NxN; + max = result[m] > max ? result[m] : max; } break; @@ -131,34 +133,37 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res temp = log(temp / NxN); else temp = XTRACT_LOG_LIMIT_DB; - if(withDC){ - result[n] = (temp + XTRACT_DB_SCALE_OFFSET) / - XTRACT_DB_SCALE_OFFSET; - result[M + n + 1] = n * q; - } - else { - result[n - 1] = (temp + XTRACT_DB_SCALE_OFFSET) / + + if(withDC){ + m = n; + result[M + m + 1] = n * q; + } + else{ + m = n - 1; + result[M + m] = n * q; + } + + result[m] = (temp + XTRACT_DB_SCALE_OFFSET) / XTRACT_DB_SCALE_OFFSET; - result[M + n - 1] = n * q; - } - max = result[n] > max ? result[n] : max; + max = result[m] > max ? result[m] : max; } break; default: /* MAGNITUDE_SPECTRUM */ for(n = 1; n < M; n++){ - if(withDC){ - result[n] = sqrt(XTRACT_SQ(rfft[n]) + - XTRACT_SQ(rfft[N - n])) / N; - result[M + n + 1] = n * q; - } - else { - result[n - 1] = sqrt(XTRACT_SQ(rfft[n]) + - XTRACT_SQ(rfft[N - n])) / N; - result[M + n - 1] = n * q; - } - max = result[n] > max ? result[n] : max; + if(withDC){ + m = n; + result[M + m + 1] = n * q; + } + else{ + m = n - 1; + result[M + m] = n * q; + } + + result[m] = sqrt(XTRACT_SQ(rfft[n]) + + XTRACT_SQ(rfft[N - n])) / N; + max = result[m] > max ? result[m] : max; } break; } @@ -172,7 +177,6 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res result[M] = XTRACT_SQ(rfft[M]); result[N + 1] = q * M; max = result[M] > max ? result[M] : max; - M++; /* So we normalise the Nyquist (below) */ } else { /* The Nyquist */ @@ -180,7 +184,6 @@ int xtract_spectrum(const float *data, const int N, const void *argv, float *res result[N - 1] = q * M; max = result[M - 1] > max ? result[M - 1] : max; } - if(normalise){ for(n = 0; n < M; n++) -- cgit v1.2.3