aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Enderby <sean.enderby@gmail.com>2014-02-25 13:53:39 +0000
committerSean Enderby <sean.enderby@gmail.com>2014-02-25 13:53:39 +0000
commit1e53c1ea582a5927f8e6d900b2a06165962b77b5 (patch)
tree8e59ef839f97227f8d5bff49b68953d06336baa2 /src
parent08de2740a76f38d50adaa326c8c6c2f0988316b9 (diff)
downloadLibXtract-1e53c1ea582a5927f8e6d900b2a06165962b77b5.tar.gz
LibXtract-1e53c1ea582a5927f8e6d900b2a06165962b77b5.tar.bz2
LibXtract-1e53c1ea582a5927f8e6d900b2a06165962b77b5.zip
tristimulus2 correction
Diffstat (limited to 'src')
-rw-r--r--src/scalar.c37
1 files 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;
+ }
}
}