EQ
Clean up of code
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
#include <QtXml/QDomElement>
|
||||
|
||||
#include "eqcontrols.h"
|
||||
#include "eqeffect.h"
|
||||
|
||||
@@ -72,8 +71,8 @@ EqControls::EqControls( EqEffect *effect ) :
|
||||
m_hp24Model( false, this , tr( "HP 24" ) ),
|
||||
m_hp48Model( false, this , tr( "HP 48" ) ),
|
||||
m_analyzeModel( true, this , tr( "Analyze enable" ) ),
|
||||
m_lpTypeModel(0,0,2,this, tr( "low pass type") ) ,
|
||||
m_hpTypeModel(0,0,2,this, tr( "high pass type") )
|
||||
m_lpTypeModel( 0,0,2,this, tr( "low pass type") ) ,
|
||||
m_hpTypeModel( 0,0,2,this, tr( "high pass type") )
|
||||
{
|
||||
m_hpFeqModel.setScaleLogarithmic( true );
|
||||
m_lowShelfFreqModel.setScaleLogarithmic( true );
|
||||
@@ -83,7 +82,6 @@ EqControls::EqControls( EqEffect *effect ) :
|
||||
m_para4FreqModel.setScaleLogarithmic( true );
|
||||
m_highShelfFreqModel.setScaleLogarithmic( true );
|
||||
m_lpFreqModel.setScaleLogarithmic( true );
|
||||
|
||||
m_para1GainModel.setScaleLogarithmic( true );
|
||||
m_inPeakL = 0;
|
||||
m_inPeakR = 0;
|
||||
@@ -94,7 +92,6 @@ EqControls::EqControls( EqEffect *effect ) :
|
||||
m_para4PeakL = 0; m_para4PeakR = 0;
|
||||
m_highShelfPeakL = 0; m_highShelfPeakR = 0;
|
||||
m_inProgress = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +107,6 @@ void EqControls::loadSettings( const QDomElement &_this )
|
||||
m_para3GainModel.loadSettings( _this, "Peak3gain" );
|
||||
m_para4GainModel.loadSettings( _this, "Peak4gain" );
|
||||
m_highShelfGainModel.loadSettings( _this , "HighShelfgain");
|
||||
|
||||
m_hpResModel.loadSettings( _this ,"HPres");
|
||||
m_lowShelfResModel.loadSettings( _this, "LowShelfres" );
|
||||
m_para1ResModel.loadSettings( _this ,"Peak1res" );
|
||||
@@ -119,7 +115,6 @@ void EqControls::loadSettings( const QDomElement &_this )
|
||||
m_para4ResModel.loadSettings( _this ,"Peak4res" );
|
||||
m_highShelfResModel.loadSettings( _this, "HighShelfres" );
|
||||
m_lpResModel.loadSettings( _this, "LPres");
|
||||
|
||||
m_hpFeqModel.loadSettings( _this, "HPfreq" );
|
||||
m_lowShelfFreqModel.loadSettings( _this, "LowShelffreq" );
|
||||
m_para1FreqModel.loadSettings( _this, "Peak1freq" );
|
||||
@@ -128,7 +123,6 @@ void EqControls::loadSettings( const QDomElement &_this )
|
||||
m_para4FreqModel.loadSettings( _this, "Peak4freq" );
|
||||
m_highShelfFreqModel.loadSettings( _this, "Highshelffreq" );
|
||||
m_lpFreqModel.loadSettings( _this, "LPfreq" );
|
||||
|
||||
m_hpActiveModel.loadSettings( _this, "HPactive" );
|
||||
m_lowShelfActiveModel.loadSettings( _this, "Lowshelfactive" );
|
||||
m_para1ActiveModel.loadSettings( _this, "Peak1active");
|
||||
@@ -137,16 +131,13 @@ void EqControls::loadSettings( const QDomElement &_this )
|
||||
m_para4ActiveModel.loadSettings( _this, "Peak4active");
|
||||
m_highShelfActiveModel.loadSettings( _this, "Highshelfactive" );
|
||||
m_lpActiveModel.loadSettings( _this, "LPactive" );
|
||||
|
||||
m_lp12Model.loadSettings( _this , "LP12" );
|
||||
m_lp24Model.loadSettings( _this , "LP24" );
|
||||
m_lp48Model.loadSettings( _this , "LP48" );
|
||||
|
||||
m_hp12Model.loadSettings( _this , "HP12" );
|
||||
m_hp24Model.loadSettings( _this , "HP24" );
|
||||
m_hp48Model.loadSettings( _this , "HP48" );
|
||||
m_analyzeModel.loadSettings( _this, "Analyzeenable");
|
||||
|
||||
m_lpTypeModel.loadSettings( _this, "LP" );
|
||||
m_hpTypeModel.loadSettings( _this, "HP" );
|
||||
}
|
||||
@@ -165,7 +156,6 @@ void EqControls::saveSettings( QDomDocument &doc, QDomElement &parent )
|
||||
m_para3GainModel.saveSettings( doc, parent, "Peak3gain" );
|
||||
m_para4GainModel.saveSettings( doc, parent, "Peak4gain" );
|
||||
m_highShelfGainModel.saveSettings( doc, parent, "HighShelfgain");
|
||||
|
||||
m_hpResModel.saveSettings( doc, parent ,"HPres");
|
||||
m_lowShelfResModel.saveSettings( doc, parent, "LowShelfres" );
|
||||
m_para1ResModel.saveSettings( doc, parent,"Peak1res" );
|
||||
@@ -174,7 +164,6 @@ void EqControls::saveSettings( QDomDocument &doc, QDomElement &parent )
|
||||
m_para4ResModel.saveSettings( doc, parent,"Peak4res" );
|
||||
m_highShelfResModel.saveSettings( doc, parent, "HighShelfres" );
|
||||
m_lpResModel.saveSettings( doc, parent, "LPres");
|
||||
|
||||
m_hpFeqModel.saveSettings( doc, parent, "HPfreq" );
|
||||
m_lowShelfFreqModel.saveSettings( doc, parent, "LowShelffreq" );
|
||||
m_para1FreqModel.saveSettings( doc, parent, "Peak1freq" );
|
||||
@@ -183,7 +172,6 @@ void EqControls::saveSettings( QDomDocument &doc, QDomElement &parent )
|
||||
m_para4FreqModel.saveSettings( doc, parent, "Peak4freq" );
|
||||
m_highShelfFreqModel.saveSettings( doc, parent, "Highshelffreq" );
|
||||
m_lpFreqModel.saveSettings( doc, parent, "LPfreq" );
|
||||
|
||||
m_hpActiveModel.saveSettings( doc, parent, "HPactive" );
|
||||
m_lowShelfActiveModel.saveSettings( doc, parent, "Lowshelfactive" );
|
||||
m_para1ActiveModel.saveSettings( doc, parent, "Peak1active" );
|
||||
@@ -192,16 +180,13 @@ void EqControls::saveSettings( QDomDocument &doc, QDomElement &parent )
|
||||
m_para4ActiveModel.saveSettings( doc, parent, "Peak4active" );
|
||||
m_highShelfActiveModel.saveSettings( doc, parent, "Highshelfactive" );
|
||||
m_lpActiveModel.saveSettings( doc, parent, "LPactive" );
|
||||
|
||||
m_lp12Model.saveSettings( doc, parent, "LP12" );
|
||||
m_lp24Model.saveSettings( doc, parent, "LP24" );
|
||||
m_lp48Model.saveSettings( doc, parent, "LP48" );
|
||||
|
||||
m_hp12Model.saveSettings( doc, parent, "HP12" );
|
||||
m_hp24Model.saveSettings( doc, parent, "HP24" );
|
||||
m_hp48Model.saveSettings( doc, parent, "HP48" );
|
||||
m_analyzeModel.saveSettings( doc, parent, "Analyzeenable");
|
||||
|
||||
m_lpTypeModel.saveSettings( doc, parent, "LP" );
|
||||
m_hpTypeModel.saveSettings( doc, parent, "HP" );
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
|
||||
|
||||
EqControlsDialog::EqControlsDialog(EqControls *controls) :
|
||||
EqControlsDialog::EqControlsDialog( EqControls *controls ) :
|
||||
EffectControlDialog( controls )
|
||||
|
||||
{
|
||||
@@ -94,10 +94,10 @@ EqControlsDialog::EqControlsDialog(EqControls *controls) :
|
||||
m_resKnob = new Knob( knobBright_26, this );
|
||||
if(i ==0 || i == 7)
|
||||
{
|
||||
m_resKnob->move(cw * i + ko , 190 );
|
||||
m_resKnob->move( cw * i + ko , 190 );
|
||||
} else
|
||||
{
|
||||
m_resKnob->move(cw * i + ko , 205 );
|
||||
m_resKnob->move( cw * i + ko , 205 );
|
||||
}
|
||||
m_resKnob->setVolumeKnob(false);
|
||||
m_resKnob->setModel( m_parameterWidget->getBandModels( i )->res );
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "MainWindow.h"
|
||||
#include "qpushbutton.h"
|
||||
#include "eqspectrumview.h"
|
||||
#include "qlist.h"
|
||||
|
||||
|
||||
class EqControls;
|
||||
|
||||
@@ -66,9 +66,7 @@ private:
|
||||
LedCheckBox* m_hp12Box;
|
||||
LedCheckBox* m_hp24Box;
|
||||
LedCheckBox* m_hp48Box;
|
||||
|
||||
LedCheckBox* m_analyzeBox;
|
||||
|
||||
EqParameterWidget* m_parameterWidget;
|
||||
EqSpectrumView* m_inSpec;
|
||||
EqSpectrumView* m_outSpec;
|
||||
|
||||
@@ -30,12 +30,6 @@
|
||||
#include "Engine.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
//TODO
|
||||
//re write to store data from each filter(models,name, storeage name ) in a class, stored in array
|
||||
//then just loop ever array for each section
|
||||
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
@@ -52,7 +46,7 @@ Plugin::Descriptor PLUGIN_EXPORT eq_plugin_descriptor =
|
||||
NULL
|
||||
} ;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
EqEffect::EqEffect(Model *parent, const Plugin::Descriptor::SubPluginFeatures::Key *key) :
|
||||
@@ -74,7 +68,6 @@ EqEffect::EqEffect(Model *parent, const Plugin::Descriptor::SubPluginFeatures::K
|
||||
|
||||
EqEffect::~EqEffect()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -100,10 +93,7 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames)
|
||||
{
|
||||
m_eqControls.m_inFftBands.clear();
|
||||
}
|
||||
|
||||
//TODO UPSAMPLE
|
||||
upsample( buf, frames );
|
||||
|
||||
gain(m_upBuf , m_upBufFrames, m_eqControls.m_inGainModel.value(), &m_inPeak );
|
||||
m_eqControls.m_inPeakL = m_eqControls.m_inPeakL < m_inPeak[0] ? m_inPeak[0] : m_eqControls.m_inPeakL;
|
||||
m_eqControls.m_inPeakR = m_eqControls.m_inPeakR < m_inPeak[1] ? m_inPeak[0] : m_eqControls.m_inPeakR;
|
||||
@@ -222,21 +212,16 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames)
|
||||
gain( m_upBuf , m_upBufFrames, outGain, &outPeak );
|
||||
m_eqControls.m_outPeakL = m_eqControls.m_outPeakL < outPeak[0] ? outPeak[0] : m_eqControls.m_outPeakL;
|
||||
m_eqControls.m_outPeakR = m_eqControls.m_outPeakR < outPeak[1] ? outPeak[0] : m_eqControls.m_outPeakR;
|
||||
|
||||
//TODO lp filter before downsample
|
||||
for( int i =0; i < m_dFilterCount; i++)
|
||||
{
|
||||
m_downsampleFilters[i].processBuffer(m_upBuf , m_upBufFrames );
|
||||
}
|
||||
|
||||
downSample( buf, frames );
|
||||
|
||||
for( fpp_t f = 0; f < frames; ++f )
|
||||
{
|
||||
outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];
|
||||
}
|
||||
checkGate( outSum / frames );
|
||||
|
||||
if(m_eqControls.m_analyzeModel.value() )
|
||||
{
|
||||
m_eqControls.m_outFftBands.analyze( buf, frames );
|
||||
@@ -245,7 +230,7 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames)
|
||||
{
|
||||
m_eqControls.m_outFftBands.clear();
|
||||
}
|
||||
setBandPeaks( &m_eqControls.m_outFftBands , (int)(sampleRate * 0.5));
|
||||
setBandPeaks( &m_eqControls.m_outFftBands , ( int )( sampleRate * 0.5 ) );
|
||||
m_eqControls.m_inProgress = false;
|
||||
return isRunning();
|
||||
}
|
||||
@@ -253,7 +238,7 @@ bool EqEffect::processAudioBuffer(sampleFrame *buf, const fpp_t frames)
|
||||
|
||||
|
||||
|
||||
void EqEffect::gain(sampleFrame *buf, const fpp_t frames, float scale, sampleFrame* peak)
|
||||
void EqEffect::gain( sampleFrame *buf, const fpp_t frames, float scale, sampleFrame* peak )
|
||||
{
|
||||
peak[0][0] = 0.0f; peak[0][1] = 0.0f;
|
||||
for( fpp_t f = 0; f < frames; ++f )
|
||||
@@ -273,11 +258,15 @@ void EqEffect::gain(sampleFrame *buf, const fpp_t frames, float scale, sampleFra
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sampleFrame m_lastUpFrame;
|
||||
void EqEffect::upsample(sampleFrame *buf, const fpp_t frames)
|
||||
void EqEffect::upsample( sampleFrame *buf, const fpp_t frames )
|
||||
{
|
||||
|
||||
if(m_upBufFrames != frames * 2 )
|
||||
if( m_upBufFrames != frames * 2 )
|
||||
{
|
||||
if( m_upBuf )
|
||||
{
|
||||
@@ -286,21 +275,19 @@ void EqEffect::upsample(sampleFrame *buf, const fpp_t frames)
|
||||
m_upBuf = new sampleFrame[frames * 2];
|
||||
m_upBufFrames = frames * 2;
|
||||
}
|
||||
|
||||
for( int f = 0, f2 = 0; f < frames; ++f, f2 += 2 )
|
||||
{
|
||||
m_upBuf[f2][0] = linearInterpolate(m_lastUpFrame[0],buf[f][0], 0.5);
|
||||
m_upBuf[f2][1] = linearInterpolate(m_lastUpFrame[1],buf[f][1], 0.5);
|
||||
m_upBuf[f2][0] = linearInterpolate( m_lastUpFrame[0],buf[f][0], 0.5 );
|
||||
m_upBuf[f2][1] = linearInterpolate( m_lastUpFrame[1],buf[f][1], 0.5 );
|
||||
m_upBuf[f2+1][0] = buf[f][0];
|
||||
m_upBuf[f2+1][1] = buf[f][1];
|
||||
|
||||
m_lastUpFrame[0] = buf[f][0];
|
||||
m_lastUpFrame[1] = buf[f][1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EqEffect::downSample(sampleFrame *buf, const fpp_t frames)
|
||||
|
||||
void EqEffect::downSample( sampleFrame *buf, const fpp_t frames )
|
||||
{
|
||||
for( int f = 0, f2 = 0; f < frames; ++f, f2 += 2 )
|
||||
{
|
||||
@@ -309,49 +296,10 @@ void EqEffect::downSample(sampleFrame *buf, const fpp_t frames)
|
||||
}
|
||||
}
|
||||
|
||||
void EqEffect::analyze(sampleFrame *buf, const fpp_t frames, EqAnalyser* fft)
|
||||
{
|
||||
if(m_eqControls.m_analyzeModel.value() )
|
||||
{
|
||||
const int FFT_BUFFER_SIZE = 2048;
|
||||
fpp_t f = 0;
|
||||
if( frames > FFT_BUFFER_SIZE )
|
||||
{
|
||||
fft->m_framesFilledUp = 0;
|
||||
f = frames - FFT_BUFFER_SIZE;
|
||||
}
|
||||
// meger channels
|
||||
for( ; f < frames; ++f )
|
||||
{
|
||||
fft->m_buffer[fft->m_framesFilledUp] =
|
||||
( buf[f][0] + buf[f][1] ) * 0.5;
|
||||
++fft->m_framesFilledUp;
|
||||
}
|
||||
|
||||
if( fft->m_framesFilledUp < FFT_BUFFER_SIZE )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fft->m_sr = Engine::mixer()->processingSampleRate();
|
||||
const int LOWEST_FREQ = 0;
|
||||
const int HIGHEST_FREQ = fft->m_sr / 2;
|
||||
|
||||
fftwf_execute( fft->m_fftPlan );
|
||||
absspec( fft->m_specBuf, fft->m_absSpecBuf, FFT_BUFFER_SIZE+1 );
|
||||
|
||||
compressbands( fft->m_absSpecBuf, fft->m_bands, FFT_BUFFER_SIZE+1,
|
||||
MAX_BANDS,
|
||||
(int)(LOWEST_FREQ*(FFT_BUFFER_SIZE+1)/(float)(fft->m_sr /2)),
|
||||
(int)(HIGHEST_FREQ*(FFT_BUFFER_SIZE+1)/(float)(fft->m_sr /2)));
|
||||
fft->m_energy = maximum( fft->m_bands, MAX_BANDS ) / maximum( fft->m_buffer, FFT_BUFFER_SIZE );
|
||||
fft->m_framesFilledUp = 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float EqEffect::peakBand(float minF, float maxF, EqAnalyser *fft, int sr)
|
||||
|
||||
float EqEffect::peakBand( float minF, float maxF, EqAnalyser *fft, int sr )
|
||||
{
|
||||
float peak = -60;
|
||||
float * b = fft->m_bands;
|
||||
@@ -377,25 +325,29 @@ void EqEffect::setBandPeaks(EqAnalyser *fft, int samplerate )
|
||||
peakBand( m_eqControls.m_para1FreqModel.value()
|
||||
- (m_eqControls.m_para1FreqModel.value() / m_eqControls.m_para1ResModel.value() * 0.5),
|
||||
m_eqControls.m_para1FreqModel.value()
|
||||
+ (m_eqControls.m_para1FreqModel.value() / m_eqControls.m_para1ResModel.value() * 0.5), fft , samplerate );
|
||||
+ (m_eqControls.m_para1FreqModel.value() / m_eqControls.m_para1ResModel.value() * 0.5),
|
||||
fft , samplerate );
|
||||
|
||||
m_eqControls.m_para2PeakL = m_eqControls.m_para2PeakR =
|
||||
peakBand( m_eqControls.m_para2FreqModel.value()
|
||||
- (m_eqControls.m_para2FreqModel.value() / m_eqControls.m_para2ResModel.value() * 0.5),
|
||||
m_eqControls.m_para2FreqModel.value()
|
||||
+ (m_eqControls.m_para2FreqModel.value() / m_eqControls.m_para2ResModel.value() * 0.5), fft , samplerate );
|
||||
+ (m_eqControls.m_para2FreqModel.value() / m_eqControls.m_para2ResModel.value() * 0.5),
|
||||
fft , samplerate );
|
||||
|
||||
m_eqControls.m_para3PeakL = m_eqControls.m_para3PeakR =
|
||||
peakBand( m_eqControls.m_para3FreqModel.value()
|
||||
- (m_eqControls.m_para3FreqModel.value() / m_eqControls.m_para3ResModel.value() * 0.5),
|
||||
m_eqControls.m_para3FreqModel.value()
|
||||
+ (m_eqControls.m_para3FreqModel.value() / m_eqControls.m_para3ResModel.value() * 0.5), fft , samplerate );
|
||||
+ (m_eqControls.m_para3FreqModel.value() / m_eqControls.m_para3ResModel.value() * 0.5),
|
||||
fft , samplerate );
|
||||
|
||||
m_eqControls.m_para4PeakL = m_eqControls.m_para4PeakR =
|
||||
peakBand( m_eqControls.m_para4FreqModel.value()
|
||||
- (m_eqControls.m_para4FreqModel.value() / m_eqControls.m_para4ResModel.value() * 0.5),
|
||||
m_eqControls.m_para4FreqModel.value()
|
||||
+ (m_eqControls.m_para4FreqModel.value() / m_eqControls.m_para4ResModel.value() * 0.5), fft , samplerate );
|
||||
+ (m_eqControls.m_para4FreqModel.value() / m_eqControls.m_para4ResModel.value() * 0.5),
|
||||
fft , samplerate );
|
||||
|
||||
m_eqControls.m_highShelfPeakL = m_eqControls.m_highShelfPeakR =
|
||||
peakBand( m_eqControls.m_highShelfFreqModel.value(),
|
||||
|
||||
@@ -71,7 +71,6 @@ private:
|
||||
sampleFrame* m_upBuf;
|
||||
fpp_t m_upBufFrames;
|
||||
|
||||
// const static int MAX_BANDS = 249;
|
||||
void upsample( sampleFrame *buf, const fpp_t frames );
|
||||
void downSample( sampleFrame *buf, const fpp_t frames );
|
||||
void analyze( sampleFrame *buf, const fpp_t frames, EqAnalyser* fft );
|
||||
@@ -83,8 +82,7 @@ private:
|
||||
}
|
||||
|
||||
void setBandPeaks( EqAnalyser *fft , int);
|
||||
// float m_bands[MAX_BANDS];
|
||||
// float m_energy;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -43,6 +43,9 @@ public:
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual inline void setSampleRate( int sampleRate )
|
||||
{
|
||||
if( sampleRate != m_sampleRate )
|
||||
@@ -52,6 +55,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual inline void setFrequency( float freq ){
|
||||
if ( freq != m_freq )
|
||||
{
|
||||
@@ -60,6 +66,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void setQ( float res )
|
||||
{
|
||||
if ( res != m_res )
|
||||
@@ -69,6 +78,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void setGain( float gain )
|
||||
{
|
||||
if ( gain != m_gain )
|
||||
@@ -78,6 +90,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///
|
||||
/// \brief processBuffer
|
||||
/// \param buf Audio Buffer
|
||||
@@ -153,6 +168,8 @@ public :
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
///
|
||||
/// \brief The EqLp12Filter class.
|
||||
/// A 2 pole low pass filter
|
||||
@@ -236,6 +253,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class EqLowShelfFilter : public EqFilter
|
||||
{
|
||||
public :
|
||||
@@ -309,6 +329,9 @@ public :
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class EqLinkwitzRiley : public StereoLinkwitzRiley
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "QPainter"
|
||||
#include "qwidget.h"
|
||||
#include "lmms_math.h"
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "QMouseEvent"
|
||||
|
||||
@@ -47,7 +46,6 @@ EqParameterWidget::EqParameterWidget( QWidget *parent ) :
|
||||
m_pixelsPerUnitHeight = (height() - 4) / ( totalHeight );
|
||||
m_scale = 1.5;
|
||||
m_pixelsPerOctave = freqToXPixel( 10000 ) - freqToXPixel( 5000 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +53,6 @@ EqParameterWidget::EqParameterWidget( QWidget *parent ) :
|
||||
|
||||
EqParameterWidget::~EqParameterWidget()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -83,8 +80,7 @@ void EqParameterWidget::paintEvent( QPaintEvent *event )
|
||||
|
||||
for( int i = 0 ; i < bandCount() ; i++ )
|
||||
{
|
||||
|
||||
m_bands[i].color.setAlpha(m_bands[i].active->value() ? activeAplha() : inactiveAlpha());
|
||||
m_bands[i].color.setAlpha( m_bands[i].active->value() ? activeAplha() : inactiveAlpha() );
|
||||
painter.setPen( QPen( m_bands[i].color, 10, Qt::SolidLine, Qt::RoundCap, Qt::BevelJoin ) );
|
||||
float x = freqToXPixel( m_bands[i].freq->value() );
|
||||
float y = height() * 0.5;
|
||||
@@ -98,7 +94,8 @@ void EqParameterWidget::paintEvent( QPaintEvent *event )
|
||||
m_bands[i].x = x; m_bands[i].y = y;
|
||||
painter.drawPoint( x, y );
|
||||
painter.setPen( QPen( m_bands[i].color, 3, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin ) );
|
||||
if(i == 0 || i == bandCount() - 1 ){
|
||||
if( i == 0 || i == bandCount() - 1 )
|
||||
{
|
||||
painter.drawLine(x, y, x, y - (m_bands[i].res->value() * 4 ) );
|
||||
}
|
||||
else
|
||||
@@ -112,7 +109,7 @@ void EqParameterWidget::paintEvent( QPaintEvent *event )
|
||||
{
|
||||
m_bands[i].color.setAlpha( 255 );
|
||||
painter.setPen( QPen( m_bands[i].color, 3, Qt::SolidLine, Qt::RoundCap, Qt::BevelJoin ) );
|
||||
painter.drawLine(sectionLength * i , 1, sectionLength * (i+1) , 1);
|
||||
painter.drawLine( sectionLength * i , 1, sectionLength * (i+1) , 1 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,15 +181,15 @@ EqBand* EqParameterWidget::selectNearestHandle( const int x, const int y )
|
||||
EqBand* selectedModel = 0;
|
||||
float* distanceToHandles = new float[bandCount()];
|
||||
//calc distance to each handle
|
||||
for( int i = 0 ; i < bandCount() ; i++)
|
||||
for( int i = 0 ; i < bandCount() ; i++ )
|
||||
{
|
||||
int xOffset = m_bands[i].x - x;
|
||||
int yOffset = m_bands[i].y - y;
|
||||
distanceToHandles[i] = fabs(sqrt((xOffset * xOffset ) + ( yOffset * yOffset ) ) );
|
||||
distanceToHandles[i] = fabs( sqrt( ( xOffset * xOffset ) + ( yOffset * yOffset ) ) );
|
||||
}
|
||||
//select band
|
||||
int shortestBand = 0;
|
||||
for (int i = 1 ; i < bandCount() ; i++ )
|
||||
for ( int i = 1 ; i < bandCount() ; i++ )
|
||||
{
|
||||
if ( distanceToHandles [i] < distanceToHandles[shortestBand] ){
|
||||
shortestBand = i;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/* eqspectrumview.h - defination of EqSpectrumView class.
|
||||
*
|
||||
* Copyright (c) 2014 David French <dave/dot/french3/at/googlemail/dot/com>
|
||||
@@ -38,12 +37,10 @@ class EqAnalyser
|
||||
public:
|
||||
|
||||
fftwf_plan m_fftPlan;
|
||||
|
||||
fftwf_complex * m_specBuf;
|
||||
float m_absSpecBuf[FFT_BUFFER_SIZE+1];
|
||||
float m_buffer[FFT_BUFFER_SIZE*2];
|
||||
int m_framesFilledUp;
|
||||
|
||||
float m_bands[MAX_BANDS];
|
||||
float m_energy;
|
||||
int m_sr;
|
||||
@@ -77,7 +74,7 @@ public:
|
||||
|
||||
|
||||
|
||||
void analyze(sampleFrame *buf, const fpp_t frames )
|
||||
void analyze( sampleFrame *buf, const fpp_t frames )
|
||||
{
|
||||
m_inProgress=true;
|
||||
const int FFT_BUFFER_SIZE = 2048;
|
||||
@@ -110,8 +107,8 @@ public:
|
||||
|
||||
compressbands( m_absSpecBuf, m_bands, FFT_BUFFER_SIZE+1,
|
||||
MAX_BANDS,
|
||||
(int)(LOWEST_FREQ*(FFT_BUFFER_SIZE+1)/(float)(m_sr /2)),
|
||||
(int)(HIGHEST_FREQ*(FFT_BUFFER_SIZE+1)/(float)(m_sr /2)));
|
||||
( int )( LOWEST_FREQ * ( FFT_BUFFER_SIZE + 1 ) / ( float )( m_sr / 2 ) ),
|
||||
( int )( HIGHEST_FREQ * ( FFT_BUFFER_SIZE + 1) / ( float )( m_sr / 2 ) ) );
|
||||
m_energy = maximum( m_bands, MAX_BANDS ) / maximum( m_buffer, FFT_BUFFER_SIZE );
|
||||
m_framesFilledUp = 0;
|
||||
m_inProgress = false;
|
||||
@@ -125,12 +122,11 @@ class EqSpectrumView : public QWidget
|
||||
{
|
||||
|
||||
public:
|
||||
explicit EqSpectrumView( EqAnalyser * b, QWidget * _parent = 0) :
|
||||
explicit EqSpectrumView( EqAnalyser * b, QWidget * _parent = 0 ):
|
||||
QWidget( _parent ),
|
||||
m_sa( b )
|
||||
{
|
||||
setFixedSize( 250, 116 );
|
||||
// connect( Engine::mainWindow(), SIGNAL( periodicUpdate() ), this, SLOT( update() ) );
|
||||
QTimer *timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
|
||||
timer->start(2000);
|
||||
@@ -140,12 +136,18 @@ public:
|
||||
m_pixelsPerUnitWidth = width( ) / totalLength ;
|
||||
m_scale = 1.5;
|
||||
color = QColor( 255, 255, 255, 255 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual ~EqSpectrumView()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
QColor color;
|
||||
EqAnalyser *m_sa;
|
||||
QPainterPath pp;
|
||||
@@ -171,13 +173,13 @@ public:
|
||||
pp.moveTo( 0,height() );
|
||||
for( int x = 0; x < MAX_BANDS; ++x, ++b )
|
||||
{
|
||||
h = (int)( fh * 2.0 / 3.0 * (20*(log10( *b / e ) ) - LOWER_Y ) / (-LOWER_Y ) );
|
||||
h = (int)( fh * 2.0 / 3.0 * ( 20 * ( log10 ( *b / e ) ) - LOWER_Y ) / (-LOWER_Y ) );
|
||||
if( h < 0 ) h = 0; else if( h >= fh ) continue;
|
||||
pp.lineTo( freqToXPixel(bandToFreq(x ) ), fh-h );
|
||||
pp.lineTo( freqToXPixel(bandToFreq( x ) ), fh-h );
|
||||
}
|
||||
pp.lineTo(width(), height() );
|
||||
pp.lineTo( width(), height() );
|
||||
pp.closeSubpath();
|
||||
p.fillPath( pp ,QBrush( color ) );
|
||||
p.fillPath( pp, QBrush( color ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -190,7 +192,7 @@ public:
|
||||
|
||||
inline float bandToFreq ( int index )
|
||||
{
|
||||
return index * m_sa->m_sr / (MAX_BANDS * 2);
|
||||
return index * m_sa->m_sr / (MAX_BANDS * 2 );
|
||||
}
|
||||
|
||||
|
||||
@@ -202,10 +204,6 @@ private:
|
||||
float m_pixelsPerUnitWidth;
|
||||
float m_scale;
|
||||
int m_skipBands;
|
||||
|
||||
|
||||
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user