Skip to content

Commit

Permalink
Merge pull request #245 from daschuer/wnumberdb
Browse files Browse the repository at this point in the history
WNumberDb a dB Display
  • Loading branch information
rryan committed Apr 28, 2014
2 parents 97c19f1 + 46d6c69 commit 5d8a971
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 27 deletions.
1 change: 1 addition & 0 deletions build/depends.py
Expand Up @@ -685,6 +685,7 @@ def sources(self, build):
"widget/wlabel.cpp",
"widget/wtracktext.cpp",
"widget/wnumber.cpp",
"widget/wnumberdb.cpp",
"widget/wnumberpos.cpp",
"widget/wnumberrate.cpp",
"widget/wknob.cpp",
Expand Down
2 changes: 1 addition & 1 deletion src/analyserrg.cpp
Expand Up @@ -76,7 +76,7 @@ void AnalyserGain::finalise(TrackPointer tio) {
return;
}

float fReplayGain_Result = pow(10.0f, ReplayGainOutput / 20.0f);
float fReplayGain_Result = db2ratio(ReplayGainOutput);

//qDebug() << "ReplayGain result is" << ReplayGainOutput << "pow:" << fReplayGain_Result;
//qDebug()<<"ReplayGain outputs "<< ReplayGainOutput << "db for track "<< tio->getFilename();
Expand Down
2 changes: 1 addition & 1 deletion src/dlgprefreplaygain.cpp
Expand Up @@ -97,7 +97,7 @@ void DlgPrefReplayGain::slotUpdate() {

void DlgPrefReplayGain::slotApply() {
double replayGainBoostDb = SliderBoost->value();
m_COTReplayGainBoost.set(pow(10.0, replayGainBoostDb / 20.0));
m_COTReplayGainBoost.set(db2ratio(replayGainBoostDb));
int iRGenabled = 0;
if (EnableGain->isChecked()) {
iRGenabled = 1;
Expand Down
7 changes: 0 additions & 7 deletions src/sampleutil.h
Expand Up @@ -154,13 +154,6 @@ class SampleUtil {
static void mixStereoToMono(CSAMPLE* pDest, const CSAMPLE* pSrc,
int iNumSamples);

// Convert 0-1.0 range gain from linear to log value.
static CSAMPLE linearToLog(CSAMPLE linear) {
linear = math_clamp(linear, 0.0f, 1.0f);
static const CSAMPLE dB = log10(2.0f) / 1.0f;
return log10(linear + 1.0f) / dB;
}

// Include auto-generated methods (e.g. copyXWithGain, copyXWithRampingGain,
// etc.)
#include "sampleutil_autogen.h"
Expand Down
3 changes: 3 additions & 0 deletions src/skin/legacyskinparser.cpp
Expand Up @@ -44,6 +44,7 @@
#include "widget/wtracktext.h"
#include "widget/wtrackproperty.h"
#include "widget/wnumber.h"
#include "widget/wnumberdb.h"
#include "widget/wnumberpos.h"
#include "widget/wnumberrate.h"
#include "widget/weffectchain.h"
Expand Down Expand Up @@ -424,6 +425,8 @@ QList<QWidget*> LegacySkinParser::parseNode(QDomElement node) {
} else if (nodeName == "Number" || nodeName == "NumberBpm") {
// NumberBpm is deprecated, and is now the same as a Number
result = wrapWidget(parseLabelWidget<WNumber>(node));
} else if (nodeName == "NumberDb") {
result = wrapWidget(parseLabelWidget<WNumberDb>(node));
} else if (nodeName == "Label") {
result = wrapWidget(parseLabelWidget<WLabel>(node));
} else if (nodeName == "Knob") {
Expand Down
6 changes: 3 additions & 3 deletions src/soundsource.cpp
Expand Up @@ -287,9 +287,9 @@ bool SoundSource::processTaglibFile(TagLib::File& f) {

void SoundSource::parseReplayGainString (QString sReplayGain) {
QString ReplayGainstring = sReplayGain.remove( " dB" );
float fReplayGain = pow(10.0f, ReplayGainstring.toFloat() / 20.0f);
//I found some mp3s of mine with replaygain tag set to 0dB even if not normalized.
//This is because of Rapid Evolution 3, I suppose. I prefer to rescan them by setting value to 0 (i.e. rescan via analyserrg)
float fReplayGain = db2ratio(ReplayGainstring.toFloat());
// I found some mp3s of mine with replaygain tag set to 0dB even if not normalized.
// This is because of Rapid Evolution 3, I suppose. I prefer to rescan them by setting value to 0 (i.e. rescan via analyserrg)
if (fReplayGain == 1.0f) {
fReplayGain = 0.0f;
}
Expand Down
10 changes: 10 additions & 0 deletions src/util/math.h
Expand Up @@ -69,4 +69,14 @@ inline int round(double x){
}
#endif

template <typename T>
inline const T ratio2db(const T a) {
return log10(a) * 20;
}

template <typename T>
inline const T db2ratio(const T a) {
return pow(10, a / 20);
}

#endif /* MATH_H */
17 changes: 6 additions & 11 deletions src/widget/wnumber.cpp
Expand Up @@ -19,8 +19,7 @@

WNumber::WNumber(QWidget* pParent)
: WLabel(pParent),
m_iNoDigits(2),
m_dConstFactor(0.0) {
m_iNoDigits(2) {
}

WNumber::~WNumber() {
Expand All @@ -33,12 +32,6 @@ void WNumber::setup(QDomNode node, const SkinContext& context) {
if (context.hasNode(node, "NumberOfDigits")) {
m_iNoDigits = context.selectInt(node, "NumberOfDigits");
}

// Constant factor
if (context.hasNode(node, "ConstFactor")) {
m_dConstFactor = context.selectString(node, "ConstFactor").toDouble();
}

setValue(0.);
}

Expand All @@ -49,7 +42,9 @@ void WNumber::onConnectedControlChanged(double dParameter, double dValue) {
}

void WNumber::setValue(double dValue) {
double v = dValue + m_dConstFactor;

setText(QString(m_qsText).append(QString::number(v, 'f', m_iNoDigits)));
if (m_qsText.contains("%1")) {
setText(m_qsText.arg(QString::number(dValue, 'f', m_iNoDigits)));
} else {
setText(m_qsText + QString::number(dValue, 'f', m_iNoDigits));
}
}
5 changes: 1 addition & 4 deletions src/widget/wnumber.h
Expand Up @@ -26,7 +26,7 @@
class WNumber : public WLabel {
Q_OBJECT
public:
WNumber(QWidget* pParent=NULL);
WNumber(QWidget* pParent = NULL);
virtual ~WNumber();

virtual void setup(QDomNode node, const SkinContext& context);
Expand All @@ -39,9 +39,6 @@ class WNumber : public WLabel {
protected:
// Number of digits to round to.
int m_iNoDigits;

// Constant factor added to value.
double m_dConstFactor;
};

#endif
31 changes: 31 additions & 0 deletions src/widget/wnumberdb.cpp
@@ -0,0 +1,31 @@

#include "widget/wnumberdb.h"

#include "util/math.h"
#include <QVBoxLayout>

#include "widget/wskincolor.h"

WNumberDb::WNumberDb(QWidget* pParent)
: WNumber(pParent) {
}

WNumberDb::~WNumberDb() {
}


void WNumberDb::setValue(double dValue) {
QString strDb;
if (dValue != 0.0) {
double v = ratio2db(dValue);
strDb = QString::number(v, 'f', m_iNoDigits);
} else {
strDb = "-" + QString(QChar(0x221E));
}

if (m_qsText.contains("%1")) {
setText(m_qsText.arg(strDb));
} else {
setText(m_qsText + strDb + " dB");
}
}
20 changes: 20 additions & 0 deletions src/widget/wnumberdb.h
@@ -0,0 +1,20 @@

#ifndef WNUMBERDB_H
#define WNUMBERDB_H

#include <QLabel>

#include "widget/wnumber.h"
#include "skin/skincontext.h"

class WNumberDb : public WNumber {
Q_OBJECT
public:
WNumberDb(QWidget* pParent = NULL);
virtual ~WNumberDb();

public slots:
virtual void setValue(double dValue);
};

#endif // WNUMBERDB_H

0 comments on commit 5d8a971

Please sign in to comment.