diff --git a/libs/ardour/ardour/dsp_filter.h b/libs/ardour/ardour/dsp_filter.h index acd6c70799..cc7250cd56 100644 --- a/libs/ardour/ardour/dsp_filter.h +++ b/libs/ardour/ardour/dsp_filter.h @@ -285,7 +285,14 @@ namespace ARDOUR { namespace DSP { double _b0, _b1, _b2; }; - class LIBARDOUR_API FFTSpectrum { + class LIBARDOUR_API SpectrumAnalyzer { + public: + virtual ~SpectrumAnalyzer () {} + virtual float power_at_bin (const uint32_t bin, const float gain, bool pink) const = 0; + virtual float freq_at_bin (const uint32_t bin) const = 0; + }; + + class LIBARDOUR_API FFTSpectrum : public SpectrumAnalyzer { public: FFTSpectrum (uint32_t window_size, double rate); ~FFTSpectrum (); @@ -307,7 +314,7 @@ namespace ARDOUR { namespace DSP { * @param norm gain factor (set equal to \p bin for 1/f normalization) * @return signal power at given bin (in dBFS) */ - float power_at_bin (const uint32_t bin, const float norm = 1.f) const; + float power_at_bin (const uint32_t bin, const float gain = 1.f, bool pink = false) const; float freq_at_bin (const uint32_t bin) const { return bin * _fft_freq_per_bin; @@ -330,7 +337,7 @@ namespace ARDOUR { namespace DSP { fftwf_plan _fftplan; }; - class LIBARDOUR_API PerceptualAnalyzer { + class LIBARDOUR_API PerceptualAnalyzer : public SpectrumAnalyzer { public: PerceptualAnalyzer (double rate, int ipsize = 4096); ~PerceptualAnalyzer (); @@ -386,7 +393,7 @@ namespace ARDOUR { namespace DSP { static double warp_freq (double w, double f); float freq_at_bin (const uint32_t bin) const; - float power_at_bin (const uint32_t bin, const float gain = 1.f, bool flat = false) const; + float power_at_bin (const uint32_t bin, const float gain = 1.f, bool pink = false) const; private: static const int _fftlen = 512; diff --git a/libs/ardour/dsp_filter.cc b/libs/ardour/dsp_filter.cc index 0848c23a6b..0b0ecc1318 100644 --- a/libs/ardour/dsp_filter.cc +++ b/libs/ardour/dsp_filter.cc @@ -562,10 +562,10 @@ FFTSpectrum::execute () } float -FFTSpectrum::power_at_bin (const uint32_t b, const float norm) const +FFTSpectrum::power_at_bin (const uint32_t b, const float gain, bool pink) const { assert (b < _fft_data_size); - const float a = _fft_power[b] * norm; + const float a = _fft_power[b] * gain * (pink ? b : 1.f); return a > 1e-12 ? 10.0 * fast_log10 (a) : -INFINITY; } @@ -863,10 +863,10 @@ PerceptualAnalyzer::freq_at_bin (const uint32_t bin) const } float -PerceptualAnalyzer::power_at_bin (const uint32_t b, float gain, bool flat) const +PerceptualAnalyzer::power_at_bin (const uint32_t b, float gain, bool pink) const { assert (b <= _fftlen); - if (flat) { + if (!pink) { return 10.f * log10f (_power->_data[b] + 1e-30); } else { /* proportional */ diff --git a/share/scripts/spectrogram.lua b/share/scripts/spectrogram.lua index 1395f8accf..9f4791f273 100644 --- a/share/scripts/spectrogram.lua +++ b/share/scripts/spectrogram.lua @@ -298,7 +298,7 @@ function render_inline (ctx, w, max_h) if b1 >= b0 and b1 <= bins and b0 >= 0 then for i = b0, b1 do - local level = gaindb + fft:power_at_bin (i, pink and i or 1) -- pink ? i : 1 + local level = gaindb + fft:power_at_bin (i, 1, pink) if level > -dbrange then local p = (dbrange + level) / dbrange if p > pk then pk = p; end