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.

33 lines
720B

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