Skip to content

Commit

Permalink
made gain compensation optional
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB authored and m0dB committed Dec 30, 2023
1 parent f453326 commit 366d74b
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void WaveformRendererFiltered::paintGL() {
// Per-band gain from the EQ knobs.
float allGain{1.0};
float bandGain[3] = {1.0, 1.0, 1.0};
getGains(&allGain, &bandGain[0], &bandGain[1], &bandGain[2]);
getGains(&allGain, true, &bandGain[0], &bandGain[1], &bandGain[2]);

const float breadth = static_cast<float>(m_waveformRenderer->getBreadth()) * devicePixelRatio;
const float halfBreadth = breadth / 2.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/allshader/waveformrendererhsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void WaveformRendererHSV::paintGL() {
(lastVisualFrame - firstVisualFrame) / static_cast<double>(length);

float allGain(1.0);
getGains(&allGain, nullptr, nullptr, nullptr);
getGains(&allGain, false, nullptr, nullptr, nullptr);

// Get base color of waveform in the HSV format (s and v isn't use)
float h, s, v;
Expand Down
3 changes: 2 additions & 1 deletion src/waveform/renderers/allshader/waveformrendererlrrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void WaveformRendererLRRGB::paintGL() {

// Per-band gain from the EQ knobs.
float allGain(1.0), lowGain(1.0), midGain(1.0), highGain(1.0);
getGains(&allGain, &lowGain, &midGain, &highGain);
// applyCompensation = false, as we scale to match filtered.all
getGains(&allGain, false, &lowGain, &midGain, &highGain);

const float breadth = static_cast<float>(m_waveformRenderer->getBreadth()) * devicePixelRatio;
const float halfBreadth = breadth / 2.0f;
Expand Down
3 changes: 2 additions & 1 deletion src/waveform/renderers/allshader/waveformrendererrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void WaveformRendererRGB::paintGL() {

// Per-band gain from the EQ knobs.
float allGain(1.0), lowGain(1.0), midGain(1.0), highGain(1.0);
getGains(&allGain, &lowGain, &midGain, &highGain);
// applyCompensation = false, as we scale to match filtered.all
getGains(&allGain, false, &lowGain, &midGain, &highGain);

const float breadth = static_cast<float>(m_waveformRenderer->getBreadth()) * devicePixelRatio;
const float halfBreadth = breadth / 2.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void WaveformRendererSimple::paintGL() {
// Per-band gain from the EQ knobs.
float allGain{1.0};
float bandGain[3] = {1.0, 1.0, 1.0};
getGains(&allGain, &bandGain[0], &bandGain[1], &bandGain[2]);
getGains(&allGain, false, &bandGain[0], &bandGain[1], &bandGain[2]);

const float breadth = static_cast<float>(m_waveformRenderer->getBreadth()) * devicePixelRatio;
const float halfBreadth = breadth / 2.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/glslwaveformrenderersignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/)

// Per-band gain from the EQ knobs.
float lowGain(1.0), midGain(1.0), highGain(1.0), allGain(1.0);
getGains(&allGain, &lowGain, &midGain, &highGain);
getGains(&allGain, true, &lowGain, &midGain, &highGain);

const auto firstVisualIndex = static_cast<GLfloat>(
m_waveformRenderer->getFirstDisplayedPosition() * trackSamples /
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void GLWaveformRendererFilteredSignal::draw(QPainter* painter, QPaintEvent* /*ev

// Per-band gain from the EQ knobs.
float allGain(1.0), lowGain(1.0), midGain(1.0), highGain(1.0);
getGains(&allGain, &lowGain, &midGain, &highGain);
getGains(&allGain, true, &lowGain, &midGain, &highGain);

if (m_alignment == Qt::AlignCenter) {
glMatrixMode(GL_PROJECTION);
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/glwaveformrendererrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void GLWaveformRendererRGB::draw(QPainter* painter, QPaintEvent* /*event*/) {

// Per-band gain from the EQ knobs.
float allGain(1.0), lowGain(1.0), midGain(1.0), highGain(1.0);
getGains(&allGain, &lowGain, &midGain, &highGain);
getGains(&allGain, true, &lowGain, &midGain, &highGain);

if (m_alignment == Qt::AlignCenter) {
glMatrixMode(GL_PROJECTION);
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/glwaveformrenderersimplesignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void GLWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*even
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

float allGain(1.0);
getGains(&allGain, nullptr, nullptr, nullptr);
getGains(&allGain, false, nullptr, nullptr, nullptr);

if (m_alignment == Qt::AlignCenter) {
glMatrixMode(GL_PROJECTION);
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/waveformrendererfilteredsignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void WaveformRendererFilteredSignal::draw(QPainter* painter,

// Per-band gain from the EQ knobs.
float allGain(1.0), lowGain(1.0), midGain(1.0), highGain(1.0);
getGains(&allGain, &lowGain, &midGain, &highGain);
getGains(&allGain, true, &lowGain, &midGain, &highGain);

const float breadth = m_waveformRenderer->getBreadth();
const float halfBreadth = breadth / 2.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/waveformrendererhsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void WaveformRendererHSV::draw(
(double)m_waveformRenderer->getLength();

float allGain(1.0);
getGains(&allGain, nullptr, nullptr, nullptr);
getGains(&allGain, false, nullptr, nullptr, nullptr);

// Get base color of waveform in the HSV format (s and v isn't use)
float h, s, v;
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/waveformrendererrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void WaveformRendererRGB::draw(

// Per-band gain from the EQ knobs.
float allGain(1.0), lowGain(1.0), midGain(1.0), highGain(1.0);
getGains(&allGain, &lowGain, &midGain, &highGain);
getGains(&allGain, true, &lowGain, &midGain, &highGain);

QColor color;

Expand Down
9 changes: 6 additions & 3 deletions src/waveform/renderers/waveformrenderersignalbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ void WaveformRendererSignalBase::setup(const QDomNode& node,
onSetup(node);
}

void WaveformRendererSignalBase::getGains(float* pAllGain, float* pLowGain,
float* pMidGain, float* pHighGain) {
void WaveformRendererSignalBase::getGains(float* pAllGain,
bool applyCompensation,
float* pLowGain,
float* pMidGain,
float* pHighGain) {
WaveformWidgetFactory* factory = WaveformWidgetFactory::instance();
if (pAllGain) {
*pAllGain = static_cast<CSAMPLE_GAIN>(m_waveformRenderer->getGain()) *
*pAllGain = static_cast<CSAMPLE_GAIN>(m_waveformRenderer->getGain(applyCompensation)) *
static_cast<CSAMPLE_GAIN>(factory->getVisualGain(WaveformWidgetFactory::All));
;
}
Expand Down
7 changes: 5 additions & 2 deletions src/waveform/renderers/waveformrenderersignalbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class WaveformRendererSignalBase : public WaveformRendererAbstract {
protected:
void deleteControls();

void getGains(float* pAllGain, float* pLowGain, float* pMidGain,
float* highGain);
void getGains(float* pAllGain,
bool applyCompensation,
float* pLowGain,
float* pMidGain,
float* highGain);

static float* unscaleTable();
inline float unscale(unsigned char value) {
Expand Down
17 changes: 15 additions & 2 deletions src/waveform/renderers/waveformwidgetrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,21 @@ class WaveformWidgetRenderer {
double getZoomFactor() const {
return m_zoomFactor;
}
double getGain() const {
return m_gain;
double getGain(bool applyCompensation) const {
// m_gain was always multiplied by 2.0, according to a comment:
//
// "This gain adjustment compensates for an arbitrary /2 gain chop in
// EnginePregain. See the comment there."
//
// However, no comment there seems to explain this, and it resulted
// in renderers that use the filtered.all data for the amplitude, to
// be twice the expected value.
// But without this compensation, renderers that use the combined
// lo, mid, hi values became much lower than expected. By making this
// optional we move the decision to each renderer whether to apply the
// compensation or not, in order to have a more similar amplitude across
// waveform renderers
return applyCompensation ? m_gain * 2.f : m_gain;
}
double getTrackSamples() const {
return m_trackSamples;
Expand Down

0 comments on commit 366d74b

Please sign in to comment.