You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vumeter.hpp 772B

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include "dsp/common.hpp"
  3. namespace rack {
  4. namespace dsp {
  5. struct VUMeter {
  6. /** Decibel level difference between adjacent meter lights */
  7. float dBInterval = 3.0;
  8. float dBScaled;
  9. /** Value should be scaled so that 1.0 is clipping */
  10. void setValue(float v) {
  11. dBScaled = std::log10(std::abs(v)) * 20.0 / dBInterval;
  12. }
  13. /** Returns the brightness of the light indexed by i
  14. Light 0 is a clip light (red) which is either on or off.
  15. All others are smooth lights which are fully bright at -dBInterval*i and higher, and fully off at -dBInterval*(i-1).
  16. */
  17. float getBrightness(int i) {
  18. if (i == 0) {
  19. return (dBScaled >= 0.0) ? 1.0 : 0.0;
  20. }
  21. else {
  22. return math::clamp(dBScaled + i, 0.0, 1.0);
  23. }
  24. }
  25. };
  26. } // namespace dsp
  27. } // namespace rack