Browse Source

Add VUMeter class to dsp library

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
1b893fb96b
1 changed files with 32 additions and 0 deletions
  1. +32
    -0
      include/dsp/vumeter.hpp

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

@@ -0,0 +1,32 @@
#pragma once

#include "math.hpp"


namespace rack {


struct VUMeter {
/** Decibel level difference between adjacent meter lights */
float dBInterval = 3.0;
float dBScaled;
/** Value should be scaled so that 1.0 is clipping */
void setValue(float v) {
dBScaled = log10f(fabsf(v)) * 20.0 / dBInterval;
}
/** Returns the brightness of the light indexed by i
Light 0 is a clip light (red) which is either on or off.
All others are smooth lights which are fully bright at -dBInterval*i and higher, and fully off at -dBInterval*(i-1).
*/
float getBrightness(int i) {
if (i == 0) {
return (dBScaled >= 0.0) ? 1.0 : 0.0;
}
else {
return clampf(dBScaled + i, 0.0, 1.0);
}
}
};


} // namespace rack

Loading…
Cancel
Save