From e4ec6cf645cde04c282c138eaf1ed5856d5db3b3 Mon Sep 17 00:00:00 2001 From: Sean Enderby Date: Mon, 24 Feb 2014 13:00:25 +0000 Subject: correction to xtract_spectral_inharmonicicty --- src/scalar.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/scalar.c b/src/scalar.c index 2e93934..47d3a8f 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -623,7 +623,7 @@ int xtract_rms_amplitude(const double *data, const int N, const void *argv, doub int xtract_spectral_inharmonicity(const double *data, const int N, const void *argv, double *result) { - int n = N >> 1; + int n = N >> 1, h = 0; double num = 0.0, den = 0.0, fund; const double *freqs, *amps; @@ -635,7 +635,8 @@ int xtract_spectral_inharmonicity(const double *data, const int N, const void *a { if(amps[n]) { - num += fabs(freqs[n] - n * fund) * XTRACT_SQ(amps[n]); + h = round(freqs[n] / fund); + num += fabs(freqs[n] - h * fund) * XTRACT_SQ(amps[n]); den += XTRACT_SQ(amps[n]); } } -- cgit v1.2.3 From 2b976e4bce32413fc3e76dc81a48178f4d871270 Mon Sep 17 00:00:00 2001 From: Sean Enderby Date: Mon, 24 Feb 2014 14:32:04 +0000 Subject: correction to xtract_odd_even_ratio --- src/scalar.c | 14 ++++++++------ xtract/xtract_scalar.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/scalar.c b/src/scalar.c index 47d3a8f..3a9abdf 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -622,7 +622,6 @@ int xtract_rms_amplitude(const double *data, const int N, const void *argv, doub int xtract_spectral_inharmonicity(const double *data, const int N, const void *argv, double *result) { - int n = N >> 1, h = 0; double num = 0.0, den = 0.0, fund; const double *freqs, *amps; @@ -656,16 +655,19 @@ int xtract_power(const double *data, const int N, const void *argv, double *resu int xtract_odd_even_ratio(const double *data, const int N, const void *argv, double *result) { + int n = N >> 1, h = 0; + double odd = 0.0, even = 0.0, fund, temp; + const double *freqs; - int M = (N >> 1), n; - - double odd = 0.0, even = 0.0, temp; + fund = *(double *)argv; + freqs = data + n; - for(n = 0; n < M; n++) + while(n--) { if((temp = data[n])) { - if(XTRACT_IS_ODD(n)) + h = round(freqs[n] / fund); + if(XTRACT_IS_ODD(h)) { odd += temp; } diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h index e18aea6..48b8f9e 100644 --- a/xtract/xtract_scalar.h +++ b/xtract/xtract_scalar.h @@ -324,9 +324,9 @@ int xtract_power(const double *data, const int N, const void *argv, double *resu /* Odd to even harmonic ratio */ /** \brief Extract the Odd to even harmonic ratio of an input vector * - * \param *data: a pointer to the first element in an array of doubles representing the amplitudes of the harmonic spectrum of an audio vector. It is sufficient to pass in a pointer to the first half of the array pointed to by *result from xtract_harmonic_spectrum(). + * \param *data: a pointer to the first element in an array of doubles representing the amplitudes of the harmonic spectrum of an audio vector. It is sufficient to pass in a pointer to array pointed to by *result from xtract_harmonic_spectrum(). * \param N: the number of elements to be considered. If using the array pointed to by *result from xtract_harmonics, N should equal half the total array size i.e., just the amplitudes of the peaks. - * \param *argv: a pointer to NULL + * \param *argv: a pointer to a double representing the fundamental frequency of the input vector. * \param *result: the even/odd harmonic ratio of N values from the array pointed to by *data */ int xtract_odd_even_ratio(const double *data, const int N, const void *argv, double *result); -- cgit v1.2.3 From ee2b29b3b5a0de5e1ed1026ebe5d753469e43201 Mon Sep 17 00:00:00 2001 From: Sean Enderby Date: Mon, 24 Feb 2014 14:57:02 +0000 Subject: documentation update --- xtract/xtract_scalar.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h index 48b8f9e..2bbf0ec 100644 --- a/xtract/xtract_scalar.h +++ b/xtract/xtract_scalar.h @@ -324,8 +324,8 @@ int xtract_power(const double *data, const int N, const void *argv, double *resu /* Odd to even harmonic ratio */ /** \brief Extract the Odd to even harmonic ratio of an input vector * - * \param *data: a pointer to the first element in an array of doubles representing the amplitudes of the harmonic spectrum of an audio vector. It is sufficient to pass in a pointer to array pointed to by *result from xtract_harmonic_spectrum(). - * \param N: the number of elements to be considered. If using the array pointed to by *result from xtract_harmonics, N should equal half the total array size i.e., just the amplitudes of the peaks. + * \param *data: a pointer to the first element in an array of doubles representing a harmonic spectrum of size N/2, and a frequency spectrum of size N/2 (This is the output format of xtract_harmonic_spectrum()) + * \param N: the number of elements to be considered. * \param *argv: a pointer to a double representing the fundamental frequency of the input vector. * \param *result: the even/odd harmonic ratio of N values from the array pointed to by *data */ -- cgit v1.2.3 From 08de2740a76f38d50adaa326c8c6c2f0988316b9 Mon Sep 17 00:00:00 2001 From: Sean Enderby Date: Tue, 25 Feb 2014 13:19:04 +0000 Subject: tristimulus1 correction --- src/scalar.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 9 deletions(-) diff --git a/src/scalar.c b/src/scalar.c index 3a9abdf..84c3900 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -298,22 +298,126 @@ int xtract_irregularity_j(const double *data, const int N, const void *argv, dou return XTRACT_SUCCESS; } +/* + *int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result) + *{ + * + * int n = N; + * + * double den, p1, temp; + * + * den = p1 = temp = 0.0; + * + * for(n = 0; n < N; n++) + * { + * if((temp = data[n])) + * { + * den += temp; + * if(!p1) + * p1 = temp; + * } + * } + * + * if(den == 0.0 || p1 == 0.0) + * { + * *result = 0.0; + * return XTRACT_NO_RESULT; + * } + * else + * { + * *result = p1 / den; + * return XTRACT_SUCCESS; + * } + *} + * + *int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result) + *{ + * + * int n = N; + * + * double den, p2, p3, p4, ps, temp; + * + * den = p2 = p3 = p4 = ps = temp = 0.0; + * + * for(n = 0; n < N; n++) + * { + * if((temp = data[n])) + * { + * den += temp; + * if(!p2) + * p2 = temp; + * else if(!p3) + * p3 = temp; + * else if(!p4) + * p4 = temp; + * } + * } + * + * ps = p2 + p3 + p4; + * + * if(den == 0.0 || ps == 0.0) + * { + * *result = 0.0; + * return XTRACT_NO_RESULT; + * } + * else + * { + * *result = ps / den; + * return XTRACT_SUCCESS; + * } + * + *} + * + *int xtract_tristimulus_3(const double *data, const int N, const void *argv, double *result) + *{ + * + * int n = N, count = 0; + * + * double den, num, temp; + * + * den = num = temp = 0.0; + * + * for(n = 0; n < N; n++) + * { + * if((temp = data[n])) + * { + * den += temp; + * if(count >= 5) + * num += temp; + * count++; + * } + * } + * + * if(den == 0.0 || num == 0.0) + * { + * *result = 0.0; + * return XTRACT_NO_RESULT; + * } + * else + * { + * *result = num / den; + * return XTRACT_SUCCESS; + * } + *} + */ + int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result) { + int n = N >> 1, h = 0, i; + double den = 0.0, p1 = 0.0, fund = 0.0, temp = 0.0; + const double *freqs; - int n = N; - - double den, p1, temp; - - den = p1 = temp = 0.0; + fund = *(double *)argv; + freqs = data + n; - for(n = 0; n < N; n++) + for(i = 0; i < n; i++) { - if((temp = data[n])) + if((temp = data[i])) { den += temp; - if(!p1) - p1 = temp; + h = round(freqs[i] / fund); + if(h == 1) + p1 += temp; } } -- cgit v1.2.3 From 1e53c1ea582a5927f8e6d900b2a06165962b77b5 Mon Sep 17 00:00:00 2001 From: Sean Enderby Date: Tue, 25 Feb 2014 13:53:39 +0000 Subject: tristimulus2 correction --- src/scalar.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/scalar.c b/src/scalar.c index 84c3900..d064840 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -436,23 +436,36 @@ int xtract_tristimulus_1(const double *data, const int N, const void *argv, doub int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result) { - int n = N; - - double den, p2, p3, p4, ps, temp; + int n = N >> 1, h = 0, i; + double den, p2, p3, p4, ps, fund, temp; + den = p2 = p3 = p4 = ps = fund = temp = 0.0; + const double *freqs; - den = p2 = p3 = p4 = ps = temp = 0.0; + fund = *(double *)argv; + freqs = data + n; - for(n = 0; n < N; n++) + for(i = 0; i < n; i++) { - if((temp = data[n])) + if((temp = data[i])) { den += temp; - if(!p2) - p2 = temp; - else if(!p3) - p3 = temp; - else if(!p4) - p4 = temp; + h = round(freqs[i] / fund); + switch (h) + { + case 2: + p2 += temp; + break; + + case 3: + p3 += temp; + break; + + case 4: + p4 += temp; + + default: + break; + } } } -- cgit v1.2.3 From 8fad3a92195af9f58d008ec82c267c7a992456cc Mon Sep 17 00:00:00 2001 From: Sean Enderby Date: Tue, 25 Feb 2014 14:12:29 +0000 Subject: tristimulus3 correction --- src/scalar.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/scalar.c b/src/scalar.c index d064840..ba662f2 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -486,21 +486,21 @@ int xtract_tristimulus_2(const double *data, const int N, const void *argv, doub int xtract_tristimulus_3(const double *data, const int N, const void *argv, double *result) { + int n = N >> 1, h = 0, i; + double den = 0.0, num = 0.0, fund = 0.0, temp = 0.0; + const double *freqs; - int n = N, count = 0; - - double den, num, temp; - - den = num = temp = 0.0; + fund = *(double *)argv; + freqs = data + n; - for(n = 0; n < N; n++) + for(i = 0; i < n; i++) { - if((temp = data[n])) + if((temp = data[i])) { den += temp; - if(count >= 5) + h = round(freqs[i] / fund); + if(h >= 5) num += temp; - count++; } } -- cgit v1.2.3 From 71ae0bc782330606c03cd01f31aa22211ff8c857 Mon Sep 17 00:00:00 2001 From: Sean Enderby Date: Tue, 25 Feb 2014 14:27:25 +0000 Subject: updated docs and removed commented out code --- src/scalar.c | 103 ------------------------------------------------- xtract/xtract_scalar.h | 4 +- 2 files changed, 2 insertions(+), 105 deletions(-) diff --git a/src/scalar.c b/src/scalar.c index ba662f2..becf341 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -298,109 +298,6 @@ int xtract_irregularity_j(const double *data, const int N, const void *argv, dou return XTRACT_SUCCESS; } -/* - *int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result) - *{ - * - * int n = N; - * - * double den, p1, temp; - * - * den = p1 = temp = 0.0; - * - * for(n = 0; n < N; n++) - * { - * if((temp = data[n])) - * { - * den += temp; - * if(!p1) - * p1 = temp; - * } - * } - * - * if(den == 0.0 || p1 == 0.0) - * { - * *result = 0.0; - * return XTRACT_NO_RESULT; - * } - * else - * { - * *result = p1 / den; - * return XTRACT_SUCCESS; - * } - *} - * - *int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result) - *{ - * - * int n = N; - * - * double den, p2, p3, p4, ps, temp; - * - * den = p2 = p3 = p4 = ps = temp = 0.0; - * - * for(n = 0; n < N; n++) - * { - * if((temp = data[n])) - * { - * den += temp; - * if(!p2) - * p2 = temp; - * else if(!p3) - * p3 = temp; - * else if(!p4) - * p4 = temp; - * } - * } - * - * ps = p2 + p3 + p4; - * - * if(den == 0.0 || ps == 0.0) - * { - * *result = 0.0; - * return XTRACT_NO_RESULT; - * } - * else - * { - * *result = ps / den; - * return XTRACT_SUCCESS; - * } - * - *} - * - *int xtract_tristimulus_3(const double *data, const int N, const void *argv, double *result) - *{ - * - * int n = N, count = 0; - * - * double den, num, temp; - * - * den = num = temp = 0.0; - * - * for(n = 0; n < N; n++) - * { - * if((temp = data[n])) - * { - * den += temp; - * if(count >= 5) - * num += temp; - * count++; - * } - * } - * - * if(den == 0.0 || num == 0.0) - * { - * *result = 0.0; - * return XTRACT_NO_RESULT; - * } - * else - * { - * *result = num / den; - * return XTRACT_SUCCESS; - * } - *} - */ - int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result) { int n = N >> 1, h = 0, i; diff --git a/xtract/xtract_scalar.h b/xtract/xtract_scalar.h index 2bbf0ec..4461623 100644 --- a/xtract/xtract_scalar.h +++ b/xtract/xtract_scalar.h @@ -182,9 +182,9 @@ int xtract_irregularity_j(const double *data, const int N, const void *argv, dou /** \brief Calculate the Tristimulus of an input vector using a method described by Pollard and Jansson (1982) * - * \param *data: a pointer to the first element in an array of doubles representing the magnitude coefficients of the harmonic spectrum of an audio vector e.g. a pointer to the first half of the array pointed to by *result from xtract_harmonics(). The amplitudes of the peak spectrum (e.g. *result from xtract_peak_spectrum()) can be used if one wishes to consider all partials not just harmonics. + * \param *data: a pointer to the first element in an array of doubles representing a harmonic spectrum of size N/2, and a frequency spectrum of size N/2 (This is the output format of xtract_harmonic_spectrum()) * \param N: the number of elements to be considered - * \param *argv: a pointer to NULL + * \param *argv: a pointer to a double representing the fundamental frequency of the input vector. * \param *result: the tristimulus of N values from the array pointed to by *data * * These three functions provide the first, second and third order tristimulus formulae -- cgit v1.2.3