Browse Source

Add VUMeter2.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
e954d4e38d
2 changed files with 47 additions and 1 deletions
  1. +47
    -0
      include/dsp/vumeter.hpp
  2. +0
    -1
      src/window.cpp

+ 47
- 0
include/dsp/vumeter.hpp View File

@@ -6,6 +6,7 @@ namespace rack {
namespace dsp {


/** Deprecated. */
struct VUMeter {
/** Decibel level difference between adjacent meter lights */
float dBInterval = 3.0;
@@ -29,5 +30,51 @@ struct VUMeter {
};


struct VUMeter2 {
enum Mode {
PEAK,
RMS
};
Mode mode = PEAK;
float v = 0.f;
/** Inverse time constant in 1/seconds */
float lambda = 0.f;

void reset() {
v = 0.f;
}

void process(float deltaTime, float value) {
if (mode == PEAK) {
value = std::abs(value);
if (value >= v) {
v = value;
}
else {
v += (value - v) * lambda * deltaTime;
}
}
else {
value = std::pow(value, 2);
v += (value - v) * lambda * deltaTime;
}
}

/** Returns the LED brightness measuring tick marks between dbMin and dbMax.
Set dbMin == dbMax == 0.f for a clip indicator.
Expensive, so call this infrequently.
*/
float getBrightness(float dbMin, float dbMax) {
float db = amplitudeToDb((mode == RMS) ? std::sqrt(v) : v);
if (db > dbMax)
return 1.f;
else if (db < dbMin)
return 0.f;
else
return math::rescale(db, dbMin, dbMax, 0.f, 1.f);
}
};


} // namespace dsp
} // namespace rack

+ 0
- 1
src/window.cpp View File

@@ -208,7 +208,6 @@ Window::Window() {
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);

internal->lastWindowTitle = "";


Loading…
Cancel
Save