diff base/ColumnOp.cpp @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents 9ef1cc26024c
children 1b688ab5f1b3
line wrap: on
line diff
--- a/base/ColumnOp.cpp	Mon Dec 12 15:18:52 2016 +0000
+++ b/base/ColumnOp.cpp	Mon Sep 17 13:51:14 2018 +0100
@@ -49,10 +49,33 @@
     if (n == ColumnNormalization::None || in.empty()) {
         return in;
     }
+    
+    float shift = 0.f;
+    float scale = 1.f;
 
-    float scale = 1.f;
-        
-    if (n == ColumnNormalization::Sum1) {
+    if (n == ColumnNormalization::Range01) {
+
+        float min = 0.f;
+        float max = 0.f;
+        bool have = false;
+        for (auto v: in) {
+            if (v < min || !have) {
+                min = v;
+            }
+            if (v > max || !have) {
+                max = v;
+            }
+            have = true;
+        }
+        if (min != 0.f) {
+            shift = -min;
+            max -= min;
+        }
+        if (max != 0.f) {
+            scale = 1.f / max;
+        }
+
+    } else if (n == ColumnNormalization::Sum1) {
 
         float sum = 0.f;
 
@@ -86,7 +109,7 @@
         }
     }
 
-    return applyGain(in, scale);
+    return applyGain(applyShift(in, shift), scale);
 }
 
 ColumnOp::Column