changeset 228:cccd314664ac

tristimulus2 correction
author Sean Enderby <sean.enderby@gmail.com>
date Tue, 25 Feb 2014 13:53:39 +0000
parents cabf2f465d1b
children a2f66a305e53
files src/scalar.c
diffstat 1 files changed, 25 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/scalar.c	Tue Feb 25 13:19:04 2014 +0000
+++ b/src/scalar.c	Tue Feb 25 13:53:39 2014 +0000
@@ -436,23 +436,36 @@
 int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result)
 {
 
-    int n = N;
+    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;
 
-    double den, p2, p3, p4, ps, temp;
+    fund = *(double *)argv;
+    freqs = data + n;
 
-    den = p2 = p3 = p4 = ps = temp = 0.0;
-
-    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;
+            }
         }
     }