SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Slots | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | List of all members
LevelMeter Class Referenceabstract

#include <levelmeter.h>

+ Inheritance diagram for LevelMeter:
+ Collaboration diagram for LevelMeter:

Public Slots

void reset ()
 
void levelChanged (qreal rmsLevel, qreal peakLevel, int numSamples)
 

Public Member Functions

 LevelMeter (QWidget *parent=0)
 
virtual ~LevelMeter ()
 
void paintEvent (QPaintEvent *event)
 
void resizeEvent (QResizeEvent *event)
 
void setAverageSmoothing (uint32_t smoothingFactor)
 

Protected Slots

void redrawTimerExpired ()
 

Protected Member Functions

virtual void render (QPainter *painter)=0
 
virtual void resized ()=0
 
int shiftx (int val, int width)
 

Protected Attributes

qreal m_avgLevel
 
qreal m_peakLevel
 
qreal m_decayedPeakLevel
 
QTime m_peakLevelChanged
 
qreal m_peakDecayRate
 
qreal m_peakHoldLevel
 
QTime m_peakHoldLevelChanged
 
uint32_t m_avgSmoothing
 
QTimer * m_redrawTimer
 
QColor m_avgColor
 
QColor m_peakColor
 
QColor m_decayedPeakColor
 
ScaleEngine m_scaleEngine
 
QPixmap * m_backgroundPixmap
 

Detailed Description

Widget which displays a vertical audio level meter, indicating the RMS and peak levels of the window of audio samples most recently analyzed by the Engine.

Definition at line 62 of file levelmeter.h.

Constructor & Destructor Documentation

◆ LevelMeter()

LevelMeter::LevelMeter ( QWidget *  parent = 0)

Definition at line 60 of file levelmeter.cpp.

References m_redrawTimer, RedrawInterval, and redrawTimerExpired().

61  : QWidget(parent)
62  , m_avgLevel(0.0)
63  , m_peakLevel(0.0)
64  , m_decayedPeakLevel(0.0)
66  , m_peakHoldLevel(0.0)
67  , m_avgSmoothing(256)
68  , m_redrawTimer(new QTimer(this))
69  , m_avgColor(0xff, 0x8b, 0x00, 128) // color mapper foreground
70  , m_peakColor(Qt::red) // just red 100% opaque
71  , m_decayedPeakColor(0x97, 0x54, 0x00, 128) // color mapper 59%
73 {
74  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
75  setMinimumWidth(30);
76 
77  connect(m_redrawTimer, SIGNAL(timeout()), this, SLOT(redrawTimerExpired()));
79 }
qreal m_avgLevel
Definition: levelmeter.h:87
QPixmap * m_backgroundPixmap
Definition: levelmeter.h:136
void redrawTimerExpired()
Definition: levelmeter.cpp:115
qreal m_peakHoldLevel
Definition: levelmeter.h:117
QColor m_avgColor
Definition: levelmeter.h:131
uint32_t m_avgSmoothing
Definition: levelmeter.h:127
const qreal PeakDecayRate
Definition: levelmeter.cpp:57
QColor m_peakColor
Definition: levelmeter.h:132
qreal m_peakLevel
Definition: levelmeter.h:93
qreal m_peakDecayRate
Definition: levelmeter.h:111
QColor m_decayedPeakColor
Definition: levelmeter.h:133
const int RedrawInterval
Definition: levelmeter.cpp:56
QTimer * m_redrawTimer
Definition: levelmeter.h:129
qreal m_decayedPeakLevel
Definition: levelmeter.h:100
+ Here is the call graph for this function:

◆ ~LevelMeter()

LevelMeter::~LevelMeter ( )
virtual

Definition at line 81 of file levelmeter.cpp.

References m_backgroundPixmap.

82 {
83  if (m_backgroundPixmap) {
84  delete m_backgroundPixmap;
85  }
86 }
QPixmap * m_backgroundPixmap
Definition: levelmeter.h:136

Member Function Documentation

◆ levelChanged

void LevelMeter::levelChanged ( qreal  rmsLevel,
qreal  peakLevel,
int  numSamples 
)
slot

Definition at line 95 of file levelmeter.cpp.

References m_avgLevel, m_avgSmoothing, m_decayedPeakLevel, m_peakHoldLevel, m_peakHoldLevelChanged, m_peakLevel, and m_peakLevelChanged.

96 {
97  // Smooth the RMS signal
98  const qreal smooth = pow(qreal(0.9), static_cast<qreal>(numSamples) / m_avgSmoothing);
99  m_avgLevel = (m_avgLevel * smooth) + (avgLevel * (1.0 - smooth));
100 
101  if (peakLevel > m_decayedPeakLevel) {
102  m_peakLevel = peakLevel;
103  m_decayedPeakLevel = peakLevel;
104  m_peakLevelChanged.start();
105  }
106 
107  if (peakLevel > m_peakHoldLevel) {
108  m_peakHoldLevel = peakLevel;
109  m_peakHoldLevelChanged.start();
110  }
111 
112  update();
113 }
qreal m_avgLevel
Definition: levelmeter.h:87
qreal m_peakHoldLevel
Definition: levelmeter.h:117
QTime m_peakLevelChanged
Definition: levelmeter.h:105
QTime m_peakHoldLevelChanged
Definition: levelmeter.h:122
uint32_t m_avgSmoothing
Definition: levelmeter.h:127
qreal m_peakLevel
Definition: levelmeter.h:93
qreal m_decayedPeakLevel
Definition: levelmeter.h:100

◆ paintEvent()

void LevelMeter::paintEvent ( QPaintEvent *  event)

Definition at line 132 of file levelmeter.cpp.

References render().

133 {
134  Q_UNUSED(event)
135 
136  QPainter painter(this);
137  render(&painter);
138 }
virtual void render(QPainter *painter)=0
+ Here is the call graph for this function:

◆ redrawTimerExpired

void LevelMeter::redrawTimerExpired ( )
protectedslot

Definition at line 115 of file levelmeter.cpp.

References m_decayedPeakLevel, m_peakDecayRate, m_peakHoldLevel, m_peakHoldLevelChanged, m_peakLevel, m_peakLevelChanged, and PeakHoldLevelDuration.

Referenced by LevelMeter().

116 {
117  // Decay the peak signal
118  const int elapsedMs = m_peakLevelChanged.elapsed();
119  const qreal decayAmount = m_peakDecayRate * elapsedMs;
120  if (decayAmount < m_peakLevel)
121  m_decayedPeakLevel = m_peakLevel - decayAmount;
122  else
123  m_decayedPeakLevel = 0.0;
124 
125  // Check whether to clear the peak hold level
127  m_peakHoldLevel = 0.0;
128 
129  update();
130 }
qreal m_peakHoldLevel
Definition: levelmeter.h:117
QTime m_peakLevelChanged
Definition: levelmeter.h:105
QTime m_peakHoldLevelChanged
Definition: levelmeter.h:122
const int PeakHoldLevelDuration
Definition: levelmeter.cpp:58
qreal m_peakLevel
Definition: levelmeter.h:93
qreal m_peakDecayRate
Definition: levelmeter.h:111
qreal m_decayedPeakLevel
Definition: levelmeter.h:100
+ Here is the caller graph for this function:

◆ render()

virtual void LevelMeter::render ( QPainter *  painter)
protectedpure virtual

Implemented in LevelMeterSignalDB, and LevelMeterVU.

Referenced by paintEvent().

+ Here is the caller graph for this function:

◆ reset

void LevelMeter::reset ( )
slot

Definition at line 88 of file levelmeter.cpp.

References m_avgLevel, and m_peakLevel.

89 {
90  m_avgLevel = 0.0;
91  m_peakLevel = 0.0;
92  update();
93 }
qreal m_avgLevel
Definition: levelmeter.h:87
qreal m_peakLevel
Definition: levelmeter.h:93

◆ resized()

virtual void LevelMeter::resized ( )
protectedpure virtual

Implemented in LevelMeterSignalDB, and LevelMeterVU.

Referenced by resizeEvent().

+ Here is the caller graph for this function:

◆ resizeEvent()

void LevelMeter::resizeEvent ( QResizeEvent *  event)

Definition at line 140 of file levelmeter.cpp.

References resized().

141 {
142  Q_UNUSED(event)
143 
144  resized();
145 }
virtual void resized()=0
+ Here is the call graph for this function:

◆ setAverageSmoothing()

void LevelMeter::setAverageSmoothing ( uint32_t  smoothingFactor)

Definition at line 147 of file levelmeter.cpp.

References m_avgSmoothing.

148 {
149  m_avgSmoothing = smoothingFactor < 1 ? 1 : smoothingFactor > 256 ? 256 : smoothingFactor;
150 }
uint32_t m_avgSmoothing
Definition: levelmeter.h:127

◆ shiftx()

int LevelMeter::shiftx ( int  val,
int  width 
)
inlineprotected

Shift the x coordinate so it does not fall right on 0 or width-1

Definition at line 142 of file levelmeter.h.

Referenced by LevelMeterVU::resized(), and LevelMeterSignalDB::resized().

143  {
144  return val == 0 ? 1 : val == width-1 ? width-2 : val;
145  }
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_avgColor

QColor LevelMeter::m_avgColor
protected

Definition at line 131 of file levelmeter.h.

Referenced by LevelMeterVU::render().

◆ m_avgLevel

qreal LevelMeter::m_avgLevel
protected

Height of RMS level bar. Range 0.0 - 1.0.

Definition at line 87 of file levelmeter.h.

Referenced by levelChanged(), LevelMeterVU::render(), LevelMeterSignalDB::render(), and reset().

◆ m_avgSmoothing

uint32_t LevelMeter::m_avgSmoothing
protected

Average smoothing factor (between 1: fast and 256: slow)

Definition at line 127 of file levelmeter.h.

Referenced by levelChanged(), and setAverageSmoothing().

◆ m_backgroundPixmap

QPixmap* LevelMeter::m_backgroundPixmap
protected

◆ m_decayedPeakColor

QColor LevelMeter::m_decayedPeakColor
protected

Definition at line 133 of file levelmeter.h.

Referenced by LevelMeterVU::render().

◆ m_decayedPeakLevel

qreal LevelMeter::m_decayedPeakLevel
protected

Height of peak level bar. This is calculated by decaying m_peakLevel depending on the elapsed time since m_peakLevelChanged, and the value of m_decayRate.

Definition at line 100 of file levelmeter.h.

Referenced by levelChanged(), redrawTimerExpired(), LevelMeterVU::render(), and LevelMeterSignalDB::render().

◆ m_peakColor

QColor LevelMeter::m_peakColor
protected

Definition at line 132 of file levelmeter.h.

Referenced by LevelMeterVU::render().

◆ m_peakDecayRate

qreal LevelMeter::m_peakDecayRate
protected

Rate at which peak level bar decays. Expressed in level units / millisecond.

Definition at line 111 of file levelmeter.h.

Referenced by redrawTimerExpired().

◆ m_peakHoldLevel

qreal LevelMeter::m_peakHoldLevel
protected

High watermark of peak level. Range 0.0 - 1.0.

Definition at line 117 of file levelmeter.h.

Referenced by levelChanged(), redrawTimerExpired(), LevelMeterVU::render(), and LevelMeterSignalDB::render().

◆ m_peakHoldLevelChanged

QTime LevelMeter::m_peakHoldLevelChanged
protected

Time at which m_peakHoldLevel was last changed.

Definition at line 122 of file levelmeter.h.

Referenced by levelChanged(), and redrawTimerExpired().

◆ m_peakLevel

qreal LevelMeter::m_peakLevel
protected

Most recent peak level. Range 0.0 - 1.0.

Definition at line 93 of file levelmeter.h.

Referenced by levelChanged(), redrawTimerExpired(), and reset().

◆ m_peakLevelChanged

QTime LevelMeter::m_peakLevelChanged
protected

Time at which m_peakLevel was last changed.

Definition at line 105 of file levelmeter.h.

Referenced by levelChanged(), and redrawTimerExpired().

◆ m_redrawTimer

QTimer* LevelMeter::m_redrawTimer
protected

Definition at line 129 of file levelmeter.h.

Referenced by LevelMeter().

◆ m_scaleEngine

ScaleEngine LevelMeter::m_scaleEngine
protected

The documentation for this class was generated from the following files: