cava test

This commit is contained in:
Zacharias-Brohn
2026-02-26 14:47:46 +01:00
parent f138bf7bdc
commit dd02b2636e
+23
View File
@@ -4,6 +4,7 @@
#include "audioprovider.hpp"
#include <algorithm>
#include <cava/cavacore.h>
#include <cmath>
#include <cstddef>
#include <qdebug.h>
@@ -39,6 +40,28 @@ void CavaProcessor::process() {
values[i] = std::clamp(m_out[i], 0.0, 1.0);
}
// --- spectral contrast (removes the "everything rises together" effect)
QVector<double> tmp = values;
auto* b = tmp.data();
auto* e = b + tmp.size();
auto pct = [&](double p) {
const int k = std::clamp(int(std::chrono::round(p * (tmp.size() - 1))), 0, tmp.size() - 1);
std::nth_element(b, b + k, e);
return b[k];
};
const double floor = pct(0.25);
const double ceil = pct(0.95);
const double range = std::max(1e-6, ceil - floor);
const double gamma = 1.6; // 1.3..2.2 range; higher = more contrast
for (int i = 0; i < m_bars; ++i) {
double x = (values[i] - floor) / range;
x = std::clamp(x, 0.0, 1.0);
values[i] = std::pow(x, gamma);
}
// Left to right pass
// const double inv = 1.0 / 1.5;
// double carry = 0.0;