|
@@ -6,6 +6,7 @@ namespace rack { |
|
|
namespace dsp { |
|
|
namespace dsp { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Deprecated. */ |
|
|
struct VUMeter { |
|
|
struct VUMeter { |
|
|
/** Decibel level difference between adjacent meter lights */ |
|
|
/** Decibel level difference between adjacent meter lights */ |
|
|
float dBInterval = 3.0; |
|
|
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 dsp |
|
|
} // namespace rack |
|
|
} // namespace rack |