From 4710360ce5d5299ee271ce890c87fefd17316711 Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 10 Dec 2014 23:47:07 +0000 Subject: [PATCH 1/4] updated Fader to use setHintText enables setting of the display text. --- include/Fader.h | 6 ++++++ src/gui/widgets/Fader.cpp | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/Fader.h b/include/Fader.h index f8048e98cfe..96c3ae732f6 100644 --- a/include/Fader.h +++ b/include/Fader.h @@ -82,6 +82,12 @@ class Fader : public QWidget, public FloatModelView { m_displayConversion = b; } + inline void setHintText( const QString & _txt_before, + const QString & _txt_after ) + { + setDescription( _txt_before ); + setUnit( _txt_after ); + } private: virtual void contextMenuEvent( QContextMenuEvent * _me ); diff --git a/src/gui/widgets/Fader.cpp b/src/gui/widgets/Fader.cpp index 7f1352a578d..1af7bb04056 100644 --- a/src/gui/widgets/Fader.cpp +++ b/src/gui/widgets/Fader.cpp @@ -107,6 +107,7 @@ Fader::Fader( FloatModel * _model, const QString & _name, QWidget * _parent ) : setMaximumSize( 23, 116); resize( 23, 116 ); setModel( _model ); + setHintText( "Volume:","%"); } @@ -141,6 +142,7 @@ Fader::Fader( FloatModel * model, const QString & name, QWidget * parent, QPixma setMaximumSize( m_back->width(), m_back->height() ); resize( m_back->width(), m_back->height() ); setModel( model ); + setHintText( "Volume:","%"); } @@ -324,7 +326,7 @@ void Fader::updateTextFloat() } else { - s_textFloat->setText( QString("Volume: %1 %").arg( m_displayConversion ? m_model->value() * 100 : m_model->value() ) ); + s_textFloat->setText( m_description + " " + QString("%1 ").arg( m_displayConversion ? m_model->value() * 100 : m_model->value() ) + " " + m_unit ); } s_textFloat->moveGlobal( this, QPoint( width() - ( *m_knob ).width() - 5, knobPosY() - 46 ) ); } From 1ad5ef22d7c99dd171c80c21395d28c378d4b1fd Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 13 Dec 2014 11:26:15 +0200 Subject: [PATCH 2/4] Bitcrush: small improvement, also add some stuff to math & constants Constants: - calculate all in long double so as to improve the accuracy of our pre-calculated constants - add some possibly useful constants: reciprocal of pi, square of pi, and reciprocal of e Math: - new math convenience functions: absMax, absMin --- include/lmms_constants.h | 29 +++++++++++++++++++++-------- include/lmms_math.h | 14 ++++++++++++++ plugins/Bitcrush/Bitcrush.cpp | 6 ++++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/include/lmms_constants.h b/include/lmms_constants.h index 629db886c3d..6f50c6f8e07 100644 --- a/include/lmms_constants.h +++ b/include/lmms_constants.h @@ -25,15 +25,28 @@ #ifndef LMMS_CONSTANTS_H #define LMMS_CONSTANTS_H -const double D_PI = 3.14159265358979323846; -const double D_2PI = D_PI * 2.0; -const double D_PI_2 = D_PI * 0.5; -const double D_E = 2.71828182845904523536; +const long double LD_PI = 3.14159265358979323846264338327950288419716939937510; +const long double LD_2PI = LD_PI * 2.0; +const long double LD_PI_2 = LD_PI * 0.5; +const long double LD_PI_R = 1.0 / LD_PI; +const long double LD_PI_SQR = LD_PI * LD_PI; +const long double LD_E = 2.71828182845904523536028747135266249775724709369995; +const long double LD_E_R = 1.0 / LD_E; -const float F_PI = (float) D_PI; -const float F_2PI = (float) D_2PI; -const float F_PI_2 = (float) D_PI_2; -const float F_E = (float) D_E; +const double D_PI = (double) LD_PI; +const double D_2PI = (double) LD_2PI; +const double D_PI_2 = (double) LD_PI_2; +const double D_PI_R = (double) LD_PI_R; +const double D_PI_SQR = (double) LD_PI_SQR; +const double D_E = (double) LD_E; +const double D_E_R = (double) LD_E_R; +const float F_PI = (float) LD_PI; +const float F_2PI = (float) LD_2PI; +const float F_PI_2 = (float) LD_PI_2; +const float F_PI_R = (float) LD_PI_R; +const float F_PI_SQR = (float) LD_PI_SQR; +const float F_E = (float) LD_E; +const float F_E_R = (float) LD_E_R; #endif diff --git a/include/lmms_math.h b/include/lmms_math.h index 016e1a49fb7..7cde2915361 100644 --- a/include/lmms_math.h +++ b/include/lmms_math.h @@ -289,4 +289,18 @@ static inline float fastSqrt( float n ) return u.f; } +//! returns value furthest from zero +template +static inline T absMax( T a, T b ) +{ + return qAbs(a) > qAbs(b) ? a : b; +} + +//! returns value nearest to zero +template +static inline T absMin( T a, T b ) +{ + return qAbs(a) < qAbs(b) ? a : b; +} + #endif diff --git a/plugins/Bitcrush/Bitcrush.cpp b/plugins/Bitcrush/Bitcrush.cpp index e9ab9639a75..8a2822d608f 100644 --- a/plugins/Bitcrush/Bitcrush.cpp +++ b/plugins/Bitcrush/Bitcrush.cpp @@ -30,6 +30,8 @@ const int OS_RATE = 5; const float OS_RATIO = 1.0f / OS_RATE; const float CUTOFF_RATIO = 0.353553391f; const int SILENCEFRAMES = 10; +const float OS_RESAMPLE [5] = { 0.0001490062883964112, 0.1645978376763992, 0.6705063120704088, + 0.1645978376763992, 0.0001490062883964112 }; extern "C" { @@ -219,8 +221,8 @@ bool BitcrushEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames ) float rsum = 0.0f; for( int o = 0; o < OS_RATE; ++o ) { - lsum += m_buffer[f * OS_RATE + o][0] * OS_RATIO; - rsum += m_buffer[f * OS_RATE + o][1] * OS_RATIO; + lsum += m_buffer[f * OS_RATE + o][0] * OS_RESAMPLE[o]; + rsum += m_buffer[f * OS_RATE + o][1] * OS_RESAMPLE[o]; } buf[f][0] = d * buf[f][0] + w * qBound( -m_outClip, lsum, m_outClip ) * m_outGain; buf[f][1] = d * buf[f][1] + w * qBound( -m_outClip, rsum, m_outClip ) * m_outGain; From 73cad09968d35ee6c7f2bb11dcad7e8428cb7188 Mon Sep 17 00:00:00 2001 From: Vesa V Date: Sat, 13 Dec 2014 13:05:50 +0200 Subject: [PATCH 3/4] Update FxMixer.cpp prevent double adding of jobs --- src/core/FxMixer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 7a21acb9290..7f78afc9f35 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -99,7 +99,7 @@ inline void FxChannel::processed() void FxChannel::incrementDeps() { m_dependenciesMet.ref(); - if( m_dependenciesMet >= m_receives.size() ) + if( m_dependenciesMet >= m_receives.size() && ! m_queued ) { m_queued = true; MixerWorkerThread::addJob( this ); From 4266de78304ce5c6ffbde34601216f0878935ef9 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 13 Dec 2014 16:28:44 +0200 Subject: [PATCH 4/4] More fixes (Bitcrush, Linkwitz-Riley filter) --- include/BasicFilters.h | 20 ++++++++++---------- plugins/Bitcrush/Bitcrush.cpp | 7 ++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/BasicFilters.h b/include/BasicFilters.h index 98c69474ab9..e09d40c425f 100644 --- a/include/BasicFilters.h +++ b/include/BasicFilters.h @@ -75,34 +75,34 @@ class LinkwitzRiley inline void setCoeffs( float freq ) { // wc - const float wc = F_2PI * freq; + const float wc = F_2PI * freq / m_sampleRate; const float wc2 = wc * wc; const float wc3 = wc2 * wc; m_wc4 = wc2 * wc2; // k - const float k = wc / tanf( F_PI * freq / m_sampleRate ); + const float k = wc / tan( wc * 0.5 ); const float k2 = k * k; const float k3 = k2 * k; m_k4 = k2 * k2; // a - static const float sqrt2 = sqrtf( 2.0f ); + static const double sqrt2 = sqrt( 2.0 ); const float sq_tmp1 = sqrt2 * wc3 * k; const float sq_tmp2 = sqrt2 * wc * k3; - m_a = 4.0f * wc2 * k2 + 2.0f * sq_tmp1 + m_k4 + 2.0f * sq_tmp2 + m_wc4; + m_a = 1.0f / ( 4.0f * wc2 * k2 + 2.0f * sq_tmp1 + m_k4 + 2.0f * sq_tmp2 + m_wc4 ); // b - m_b1 = ( 4.0f * ( m_wc4 + sq_tmp1 - m_k4 - sq_tmp2 ) ) / m_a; - m_b2 = ( 6.0f * m_wc4 - 8.0f * wc2 * k2 + 6.0f * m_k4 ) / m_a; - m_b3 = ( 4.0f * ( m_wc4 - sq_tmp1 + sq_tmp2 - m_k4 ) ) / m_a; - m_b4 = ( m_k4 - 2.0f * sq_tmp1 + m_wc4 - 2.0f * sq_tmp2 + 4.0f * wc2 * k2 ) / m_a; + m_b1 = ( 4.0f * ( m_wc4 + sq_tmp1 - m_k4 - sq_tmp2 ) ) * m_a; + m_b2 = ( 6.0f * m_wc4 - 8.0f * wc2 * k2 + 6.0f * m_k4 ) * m_a; + m_b3 = ( 4.0f * ( m_wc4 - sq_tmp1 + sq_tmp2 - m_k4 ) ) * m_a; + m_b4 = ( m_k4 - 2.0f * sq_tmp1 + m_wc4 - 2.0f * sq_tmp2 + 4.0f * wc2 * k2 ) * m_a; } inline void setLowpass( float freq ) { setCoeffs( freq ); - m_a0 = m_wc4 / m_a; + m_a0 = m_wc4 * m_a; m_a1 = 4.0f * m_a0; m_a2 = 6.0f * m_a0; } @@ -110,7 +110,7 @@ class LinkwitzRiley inline void setHighpass( float freq ) { setCoeffs( freq ); - m_a0 = m_k4 / m_a; + m_a0 = m_k4 * m_a; m_a1 = 4.0f * m_a0; m_a2 = 6.0f * m_a0; } diff --git a/plugins/Bitcrush/Bitcrush.cpp b/plugins/Bitcrush/Bitcrush.cpp index 8a2822d608f..84f5b45ba0c 100644 --- a/plugins/Bitcrush/Bitcrush.cpp +++ b/plugins/Bitcrush/Bitcrush.cpp @@ -80,7 +80,7 @@ void BitcrushEffect::sampleRateChanged() { m_sampleRate = Engine::mixer()->processingSampleRate(); m_filter.setSampleRate( m_sampleRate ); - m_filter.setLowpass( m_sampleRate * CUTOFF_RATIO ); + m_filter.setLowpass( m_sampleRate * ( CUTOFF_RATIO * OS_RATIO ) ); m_needsUpdate = true; } @@ -97,6 +97,11 @@ inline float BitcrushEffect::noise( float amt ) bool BitcrushEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames ) { + if( !isEnabled() || !isRunning () ) + { + return( false ); + } + // update values if( m_needsUpdate || m_controls.m_rateEnabled.isValueChanged() ) {