Browse Source

Add Port::getVoltageRMS().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
8c5b0ba9ff
1 changed files with 17 additions and 0 deletions
  1. +17
    -0
      include/engine/Port.hpp

+ 17
- 0
include/engine/Port.hpp View File

@@ -103,6 +103,23 @@ struct Port {
return sum; return sum;
} }


/** Returns the root-mean-square of all voltages. */
float getVoltageRMS() {
if (channels == 0) {
return 0.f;
}
else if (channels == 1) {
return std::fabs(voltages[0]);
}
else {
float sum = 0.f;
for (int c = 0; c < channels; c++) {
sum += std::pow(voltages[c], 2);
}
return std::sqrt(sum);
}
}

template <typename T> template <typename T>
T getVoltageSimd(int firstChannel) { T getVoltageSimd(int firstChannel) {
return T::load(&voltages[firstChannel]); return T::load(&voltages[firstChannel]);


Loading…
Cancel
Save