Skip to content

Commit

Permalink
dont unscale, apparently its intentional
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB authored and m0dB committed Dec 28, 2023
1 parent 99598ed commit f453326
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
12 changes: 9 additions & 3 deletions src/analyzer/analyzerwaveform.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ inline CSAMPLE scaleSignal(CSAMPLE invalue, FilterIndex index = FilterCount) {
return std::pow(invalue, 2.0f * 0.316f);
}

// TODO this function needs an explanation of why this scaling is applied.
// Note that in the allshader waveform-renderers, this scaling is undone for
// the filtered.all band.
// According to this discussion
// https://github.com/mixxxdj/mixxx/issues/6352
// it looks like this scaling is done to accentuate
// low level information.

// This scaling can be undone with a function in
// waveform/renderers/waveformrenderersignalbase.h
// but arguable it would be better not to do this scaling here at all
// and do it (or not) at the waveform renderer side.
}

struct WaveformStride {
Expand Down
5 changes: 3 additions & 2 deletions src/waveform/renderers/allshader/waveformrendererhsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ void WaveformRendererHSV::paintGL() {
maxLow[chn] = static_cast<float>(u8maxLow);
maxMid[chn] = static_cast<float>(u8maxMid);
maxHigh[chn] = static_cast<float>(u8maxHigh);
// Undo scaling with pow(value, 2.0f * 0.316f) done in analyzerwaveform.h
maxAll[chn] = unscale(u8maxAll);
maxAll[chn] = static_cast<float>(u8maxAll);
// Uncomment to undo scaling with pow(value, 2.0f * 0.316f) done in analyzerwaveform.h
// maxAll[chn] = unscale(u8maxAll);
}

float total{};
Expand Down
5 changes: 3 additions & 2 deletions src/waveform/renderers/allshader/waveformrendererlrrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ void WaveformRendererLRRGB::paintGL() {
float maxLow = static_cast<float>(u8maxLow);
float maxMid = static_cast<float>(u8maxMid);
float maxHigh = static_cast<float>(u8maxHigh);
// Undo scaling with pow(value, 2.0f * 0.316f) done in analyzerwaveform.h
float maxAll = unscale(u8maxAll);
float maxAll = static_cast<float>(u8maxAll);
// Uncomment to undo scaling with pow(value, 2.0f * 0.316f) done in analyzerwaveform.h
// float maxAll = unscale(u8maxAll);

// Calculate the squared magnitude of the maxLow, maxMid and maxHigh values.
// We take the square root to get the magnitude below.
Expand Down
5 changes: 3 additions & 2 deletions src/waveform/renderers/allshader/waveformrendererrgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ void WaveformRendererRGB::paintGL() {
float maxLow = static_cast<float>(u8maxLow);
float maxMid = static_cast<float>(u8maxMid);
float maxHigh = static_cast<float>(u8maxHigh);
// Undo scaling with pow(value, 2.0f * 0.316f) done in analyzerwaveform.h
float maxAllChn[2]{unscale(u8maxAllChn[0]), unscale(u8maxAllChn[1])};
float maxAllChn[2]{static_cast<float>(u8maxAllChn[0]), static_cast<float>(u8maxAllChn[1])};
// Uncomment to undo scaling with pow(value, 2.0f * 0.316f) done in analyzerwaveform.h
// float maxAllChn[2]{unscale(u8maxAllChn[0]), unscale(u8maxAllChn[1])};

// Calculate the squared magnitude of the maxLow, maxMid and maxHigh values.
// We take the square root to get the magnitude below.
Expand Down
6 changes: 4 additions & 2 deletions src/waveform/renderers/allshader/waveformrenderersimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ void WaveformRendererSimple::paintGL() {
// data is interleaved left / right
for (int i = visualIndexStart + chn; i < visualIndexStop + chn; i += 2) {
const WaveformData& waveformData = data[i];
// Undo scaling with pow(value, 2.0f * 0.316f) done in analyzerwaveform.h
const float filteredAll = unscale(waveformData.filtered.all);
const float filteredAll = static_cast<float>(waveformData.filtered.all);
// Uncomment to undo scaling with pow(value, 2.0f * 0.316f) done
// in analyzerwaveform.h const float filteredAll =
// unscale(waveformData.filtered.all);

max[chn] = math_max(max[chn], filteredAll);
}
Expand Down
4 changes: 3 additions & 1 deletion src/waveform/renderers/waveformrenderersignalbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class WaveformRendererSignalBase : public WaveformRendererAbstract {
void getGains(float* pAllGain, float* pLowGain, float* pMidGain,
float* highGain);

// To undo scaling with pow(value, 2.0f * 0.316f) done in analyzerwaveform.h
static float* unscaleTable();
inline float unscale(unsigned char value) {
// The all and hi components of the waveform data are scaled with pow(value, 2.0f * 0.316f)
// (see analyzerwaveform.h). This function can be used to undo that scaling,
// but apparently it is intentional.
static const float* table = unscaleTable();
return table[value];
}
Expand Down

0 comments on commit f453326

Please sign in to comment.