Returns the root-mean-square of all voltages. Uses sqrt() which is slow, so use a custom approximation if calling frequently. */
| 146 | Uses sqrt() which is slow, so use a custom approximation if calling frequently. |
| 147 | */ |
| 148 | float getVoltageRMS() const { |
| 149 | if (channels == 0) { |
| 150 | return 0.f; |
| 151 | } |
| 152 | else if (channels == 1) { |
| 153 | return std::fabs(voltages[0]); |
| 154 | } |
| 155 | else { |
| 156 | float sum = 0.f; |
| 157 | for (int c = 0; c < channels; c++) { |
| 158 | sum += std::pow(voltages[c], 2); |
| 159 | } |
| 160 | return std::sqrt(sum); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | template <typename T> |
| 165 | T getVoltageSimd(int firstChannel) const noexcept { |