float EqEffect::peakBand( float minF, float maxF, EqAnalyser *fft, int sr ) { float peak = -60; float * b = fft->m_bands; float h = 0; for(int x = 0; x < MAX_BANDS; x++, b++) { if( bandToFreq( x ,sr) >= minF && bandToFreq( x,sr ) <= maxF ) { h = 20*( log10( *b / fft->m_energy ) ); peak = h > peak ? h : peak; } } return (peak+100)/100; }
void EqSpectrumView::paintEvent(QPaintEvent *event) { //only analyse if the view is visible m_analyser->setActive( isVisible() ); const float energy = m_analyser->getEnergy(); if( energy <= 0 && m_peakSum <= 0 ) { //dont draw anything return; } const int fh = height(); const int LOWER_Y = -36; // dB QPainter painter( this ); painter.setPen( QPen( m_color, 1, Qt::SolidLine, Qt::RoundCap, Qt::BevelJoin ) ); if( m_analyser->getInProgress() || m_periodicalUpdate == false ) { //only paint the cached path painter.fillPath( m_path, QBrush( m_color ) ); return; } m_periodicalUpdate = false; //Now we calculate the path m_path = QPainterPath(); float *bands = m_analyser->m_bands; float peak; m_path.moveTo( 0, height() ); m_peakSum = 0; float fallOff = 1.2; for( int x = 0; x < MAX_BANDS; ++x, ++bands ) { peak = ( fh * 2.0 / 3.0 * ( 20 * ( log10( *bands / energy ) ) - LOWER_Y ) / ( - LOWER_Y ) ); if( peak < 0 ) { peak = 0; } else if( peak >= fh ) { continue; } if ( peak > m_bandHeight[x] ) { m_bandHeight[x] = peak; } else { m_bandHeight[x] = m_bandHeight[x] / fallOff; } if( m_bandHeight[x] < 0 ) { m_bandHeight[x] = 0; } m_path.lineTo( EqHandle::freqToXPixel( bandToFreq( x ), width() ), fh - m_bandHeight[x] ); m_peakSum += m_bandHeight[x]; } m_path.lineTo( width(), height() ); m_path.closeSubpath(); painter.fillPath( m_path, QBrush( m_color ) ); painter.drawPath( m_path ); }