void EqHandle::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) { painter->setRenderHint( QPainter::Antialiasing, true ); if ( m_mousePressed ) { emit positionChanged(); } QString fileName = "handle" + QString::number(m_numb+1); if ( !isActiveHandle() ) { fileName = fileName + "inactive"; } QPixmap circlePixmap = PLUGIN_NAME::getIconPixmap( fileName.toLatin1() ); painter->drawPixmap( -12, -12, circlePixmap ); // on mouse hover draw an info box and change the pixmap of the handle if ( isMouseHover() ) { // keeps the info box in view float rectX = -40; float rectY = -40; if ( EqHandle::y() < 40 ) { rectY = rectY + 40 - EqHandle::y(); } if ( EqHandle::x() < 40 ) { rectX = rectX + 40 - EqHandle::x(); } if ( EqHandle::x() > m_width - 40 ) { rectX = rectX - ( 40 - ( m_width - EqHandle::x() ) ); } painter->drawPixmap( -12, -12, PLUGIN_NAME::getIconPixmap( "handlehover" ) ); QRectF textRect = QRectF ( rectX, rectY, 80, 30 ); QRectF textRect2 = QRectF ( rectX+1, rectY+1, 80, 30 ); QString freq = QString::number( xPixelToFreq( EqHandle::x(), m_width ) ); QString res; if ( getType() != para ) { res = tr( "Reso: ") + QString::number( getResonance() ); } else { res = tr( "BW: " ) + QString::number( getResonance() ); } painter->setPen( QColor( 255, 255, 255 ) ); painter->drawRect( textRect ); painter->fillRect( textRect, QBrush( QColor( 128, 128, 255 , 64 ) ) ); painter->setPen ( QColor( 0, 0, 0 ) ); painter->drawText( textRect2, Qt::AlignCenter, QString( tr( "Freq: " ) + freq + "\n" + res ) ); painter->setPen( QColor( 255, 255, 255 ) ); painter->drawText( textRect, Qt::AlignCenter, QString( tr( "Freq: " ) + freq + "\n" + res ) ); } }
void BandPassFilter2::step(Signal* inout) { sample* samples = inout->samples; sample* f = getFrequency().samples; sample* m = getResonance().samples; const float pi_2 = 3.1415f*2.f; const float te = 1.f/(float)Signal::frequency; for (unsigned int i=0;i < Signal::size;i++) { const float w0=f[i]*pi_2; const float w0te=w0*te; const float mw0te=w0te*2.f*m[i]; const float w0te2=w0te*w0te; const float d=1.f+mw0te+w0te2; const float a0=mw0te/d; const float b1=(2.f + mw0te)/d; const float b2=1.f/d; const float save_x_1 = samples[i]; const float k=1.f/0.7f; samples[i] = k*a0*samples[i]-k*a0*_x_1+b1*_y_1-b2*_y_2; _y_2 = _y_1; _y_1 = samples[i]; _x_1 = save_x_1; } }
void HighPassFilter2::step(Signal* inout) { sample* samples = inout->samples; sample* f = getFrequency().samples; sample* m = getResonance().samples; const float pi_2 = 3.1415f*2.f; const float te = 1.f/(float)Signal::frequency; const float _2te=te*2.f; for (unsigned int i=0; i<Signal::size;i++) { const float w0=f[i]*pi_2; const float w0te=w0*te; const float w02te=w0*_2te; const float w02te2=w0te*w0te; const float _2mw0te=m[i]*w02te; float a=w02te2+_2mw0te+1.f; a=1.f/a; const float b=_2mw0te+2.f; const float _2_x_1=2*_x_1; const float save_x_1=samples[i]; samples[i]=a*(_y_1*b-_y_2+samples[i]-_2_x_1+_x_2); //std::cout << samples[i]<<std::endl; _y_2=_y_1; _y_1=samples[i]; _x_2=_x_1; _x_1=save_x_1; } }
float EqHandle::getPeakCurve( float x ) { double freqZ = xPixelToFreq( EqHandle::x(), m_width ); const int SR = Engine::mixer()->processingSampleRate(); double w0 = 2 * LD_PI * freqZ / SR ; double c = cosf( w0 ); double s = sinf( w0 ); double Q = getResonance(); double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 40 ); double alpha = s * sinh( log( 2 ) / 2 * Q * w0 / sinf( w0 ) ); double a0, a1, a2, b0, b1, b2; // coeffs to calculate //calc coefficents b0 = 1 + alpha * A; b1 = -2 * c; b2 = 1 - alpha * A; a0 = 1 + alpha / A; a1 = -2 * c; a2 = 1 - alpha / A; //normalise b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; a0 = 1; double freq = xPixelToFreq( x, m_width ); double gain = calculateGain( freq, a1, a2, b0, b1, b2 ); float y = gainToYPixel( gain, m_heigth, m_pixelsPerUnitHeight ); return y; }
void FilterAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { this->initializing(buffer); processBlockwise<FilterConstants::blockSize>(buffer, internalBuffer, [this](size_t samples, size_t offset) { switch (filterType) { case High: filter->processHigh(internalBuffer, samples, getFrequency(), getResonance()); break; case Low: filter->processLow(internalBuffer, samples, getFrequency(), getResonance()); break; case Band: filter->processBand(internalBuffer, samples, getFrequency(), getResonance()); break; case Notch: filter->processNotch(internalBuffer, samples, getFrequency(), getResonance()); break; } }); this->meteringBuffer(buffer); this->finalizing(buffer); }
void Rejector::step(Signal* inout) { sample* samples = inout->samples; sample* f = getFrequency().samples; sample* m = getResonance().samples; const float te = 1.f/(float)Signal::frequency; for (unsigned int i=0; i<Signal::size; i++) { const float w0te=f[i]*te; const float w02te2=w0te*w0te; const float mw0te=m[i]*w0te; const float a=1.f/(w02te2+2.f*mw0te+1.f); const float b=2.f*mw0te+2.f; const float c=w02te2+1.f; const float save_x_1=samples[i]; samples[i]=a*(_y_1*b-_y_2+samples[i]*c-2.f*_x_1+_x_2); _y_2=_y_1; _y_1=samples[i]; _x_2=_x_1; _x_1=save_x_1; } }
float EqHandle::getHighCutCurve( float x ) { double freqZ = xPixelToFreq( EqHandle::x(), m_width ); const int SR = Engine::mixer()->processingSampleRate(); double w0 = 2 * LD_PI * freqZ / SR ; double c = cosf( w0 ); double s = sinf( w0 ); double resonance = getResonance(); double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 20 ); double alpha = s / 2 * sqrt ( ( A + 1 / A ) * ( 1 / resonance -1 ) +2 ); double a0, a1, a2, b0, b1, b2; // coeffs to calculate b0 = ( 1 - c ) * 0.5; b1 = 1 - c; b2 = ( 1 - c ) * 0.5; a0 = 1 + alpha; a1 = -2 * c; a2 = 1 - alpha; //normalise b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; a0 = 1; double freq = xPixelToFreq( x, m_width ); double gain = calculateGain( freq, a1, a2, b0, b1, b2 ); if ( m_lp24 ) { gain = gain * 2; } if ( m_lp48 ) { gain = gain * 3; } float y = gainToYPixel( gain, m_heigth, m_pixelsPerUnitHeight ); return y; }
double TopPairCandidateTutorial::mttbar() const { return getResonance()->mass(); }