Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
AudioVU.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Audio.h>
5
7
9
17 public:
31 template <class T>
32 AudioVU(T &level, float gain = 1.0, uint8_t max = 255)
33 : IVU(max, true), level(level), gain(gain) {}
34
50 template <class T>
52 uint8_t max = 255)
53 : IVU(max, true), ballistics(ballistics), level(level), gain(gain) {}
54
60 uint8_t getValue() override {
61 uint16_t value = getFloatValue() * max;
62 return value;
63 }
64
70 float getFloatValue() override {
71 if (!level.available())
72 return 0;
73 float peakLevel = level.read();
74 float value = ballistics(peakLevel) * gain;
75 if (value > 1.0f)
76 value = 1.0f;
77 else if (value < 0.0f)
78 value = 0.0f;
79 return value;
80 }
81
83 bool getOverload() override { return false; }
84
91 void setGain(float gain) { this->gain = gain; }
92
93 private:
95
101 class Analyzer {
102 private:
103 enum { Peak, RMS } type;
104 void *analyzer;
105
106 public:
107 Analyzer(AudioAnalyzePeak &analyzer) //
108 : type(Peak), analyzer(&analyzer) {}
109 Analyzer(AudioAnalyzeRMS &analyzer) //
110 : type(RMS), analyzer(&analyzer) {}
111
112 float read() const {
113 switch (type) {
114 case Peak:
115 return static_cast<AudioAnalyzePeak *>(analyzer)->read();
116 case RMS:
117 return static_cast<AudioAnalyzeRMS *>(analyzer)->read();
118 default: ERROR(F("Error: Invalid type!"), 0x1518); return 0;
119 }
120 }
121
122 bool available() const {
123 switch (type) {
124 case Peak:
125 return static_cast<AudioAnalyzePeak *>(analyzer)
126 ->available();
127 case RMS:
128 return static_cast<AudioAnalyzeRMS *>(analyzer)
129 ->available();
130 default: ERROR(F("Error: Invalid type!"), 0x1519); return false;
131 }
132 }
134
135 float gain;
136};
137
#define ERROR(msg, errc)
Definition Error.hpp:19
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
The AudioAnalyzePeak and AudioAnalyzeRMS classes don't implement a common interface,...
Definition AudioVU.hpp:101
enum AudioVU::Analyzer::@3 type
bool available() const
Definition AudioVU.hpp:122
Analyzer(AudioAnalyzeRMS &analyzer)
Definition AudioVU.hpp:109
float read() const
Definition AudioVU.hpp:112
Analyzer(AudioAnalyzePeak &analyzer)
Definition AudioVU.hpp:107
A VU meter that reads from an Audio stream using the Analyzer class.
Definition AudioVU.hpp:16
MovingCoilBallistics ballistics
Definition AudioVU.hpp:94
uint8_t getValue() override
Get the value of the VU meter.
Definition AudioVU.hpp:60
AudioVU(T &level, MovingCoilBallistics ballistics, float gain=1.0, uint8_t max=255)
Create a new AudioVU object.
Definition AudioVU.hpp:51
class AudioVU::Analyzer level
AudioVU(T &level, float gain=1.0, uint8_t max=255)
Create a new AudioVU object.
Definition AudioVU.hpp:32
bool getOverload() override
Definition AudioVU.hpp:83
float gain
Definition AudioVU.hpp:135
void setGain(float gain)
Set the gain for the VU meter.
Definition AudioVU.hpp:91
float getFloatValue() override
Get the value of the VU meter.
Definition AudioVU.hpp:70
An abstract interface for VU meters.
IVU(uint8_t max, bool alwaysDirty=false)
static MovingCoilBallistics responsiveVU(float Tsfactor=2.0)