Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
1324:d4a28d1479a8 | 1527:710e6250a401 |
---|---|
47 ColumnOp::normalize(const Column &in, ColumnNormalization n) { | 47 ColumnOp::normalize(const Column &in, ColumnNormalization n) { |
48 | 48 |
49 if (n == ColumnNormalization::None || in.empty()) { | 49 if (n == ColumnNormalization::None || in.empty()) { |
50 return in; | 50 return in; |
51 } | 51 } |
52 | 52 |
53 float shift = 0.f; | |
53 float scale = 1.f; | 54 float scale = 1.f; |
54 | 55 |
55 if (n == ColumnNormalization::Sum1) { | 56 if (n == ColumnNormalization::Range01) { |
57 | |
58 float min = 0.f; | |
59 float max = 0.f; | |
60 bool have = false; | |
61 for (auto v: in) { | |
62 if (v < min || !have) { | |
63 min = v; | |
64 } | |
65 if (v > max || !have) { | |
66 max = v; | |
67 } | |
68 have = true; | |
69 } | |
70 if (min != 0.f) { | |
71 shift = -min; | |
72 max -= min; | |
73 } | |
74 if (max != 0.f) { | |
75 scale = 1.f / max; | |
76 } | |
77 | |
78 } else if (n == ColumnNormalization::Sum1) { | |
56 | 79 |
57 float sum = 0.f; | 80 float sum = 0.f; |
58 | 81 |
59 for (auto v: in) { | 82 for (auto v: in) { |
60 sum += fabsf(v); | 83 sum += fabsf(v); |
84 scale = log10f(max + 1.f) / max; | 107 scale = log10f(max + 1.f) / max; |
85 } | 108 } |
86 } | 109 } |
87 } | 110 } |
88 | 111 |
89 return applyGain(in, scale); | 112 return applyGain(applyShift(in, shift), scale); |
90 } | 113 } |
91 | 114 |
92 ColumnOp::Column | 115 ColumnOp::Column |
93 ColumnOp::distribute(const Column &in, | 116 ColumnOp::distribute(const Column &in, |
94 int h, | 117 int h, |