From a218a033b54f5dab72dabbeae2060724ae8c93f9 Mon Sep 17 00:00:00 2001 From: Vesa Date: Fri, 2 May 2014 21:33:55 +0300 Subject: [PATCH 1/3] Monstro: more bugfixes Fixes a bug caused by fastPow which was causing hangups in very specific situations only --- plugins/monstro/Monstro.cpp | 52 ++++++++++++++++++++++++++++--------- plugins/monstro/Monstro.h | 19 ++++++++------ 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/plugins/monstro/Monstro.cpp b/plugins/monstro/Monstro.cpp index 02cfdceeb..ee8bfb6c6 100644 --- a/plugins/monstro/Monstro.cpp +++ b/plugins/monstro/Monstro.cpp @@ -111,6 +111,7 @@ MonstroSynth::MonstroSynth( MonstroInstrument * _i, NotePlayHandle * _nph, m_counter3l = 0; m_counter3r = 0; m_counterMax = ( m_samplerate * 10 ) / 44100; + } @@ -140,8 +141,8 @@ void MonstroSynth::renderOutput( fpp_t _frames, sampleFrame * _buf ) if( mod##_l2 != 0.0f ) car = qBound( 0.0f, car + mod##_l2 * 0.5f * m_lfo2_buf[f], 1.0f ); #define modulatephs( car, mod ) \ - if( mod##_e1 != 0.0f ) car += ( mod##_e1 * m_env1_buf[f] ); \ - if( mod##_e2 != 0.0f ) car += ( mod##_e2 * m_env2_buf[f] ); \ + if( mod##_e1 != 0.0f ) car += qBound( -1.0f, ( mod##_e1 * m_env1_buf[f] ), 1.0f ); \ + if( mod##_e2 != 0.0f ) car += qBound( -1.0f, ( mod##_e2 * m_env2_buf[f] ), 1.0f ); \ if( mod##_l1 != 0.0f ) car += ( mod##_l1 * 0.5f * m_lfo1_buf[f] ); \ if( mod##_l2 != 0.0f ) car += ( mod##_l2 * 0.5f * m_lfo2_buf[f] ); @@ -863,9 +864,6 @@ void MonstroSynth::renderModulators( fpp_t _frames ) // ///////////////////////////////////////////// - const float env1_s = m_parent-> m_env1Slope.value(); - const float env2_s = m_parent-> m_env2Slope.value(); - const float env1_sus = m_parent-> m_env1Sus.value(); const float env2_sus = m_parent-> m_env2Sus.value(); @@ -890,7 +888,7 @@ void MonstroSynth::renderModulators( fpp_t _frames ) } else if( m_env1_phase < 2.0f ) // attack phase { - m_env1_buf[f] = calcSlope( fraction( m_env1_phase ), env1_s ); + m_env1_buf[f] = calcSlope1( fraction( m_env1_phase ) ); m_env1_phase = qMin( 2.0f, m_env1_phase + m_parent->m_env1_att ); } else if( m_env1_phase < 3.0f ) // hold phase @@ -900,7 +898,7 @@ void MonstroSynth::renderModulators( fpp_t _frames ) } else if( m_env1_phase < 4.0f ) // decay phase { - const sample_t s = calcSlope( 1.0f - fraction( m_env1_phase ), env1_s ); + const sample_t s = calcSlope1( 1.0f - fraction( m_env1_phase ) ); if( s <= env1_sus ) { m_env1_buf[f] = env1_sus; @@ -914,7 +912,7 @@ void MonstroSynth::renderModulators( fpp_t _frames ) } else if( m_env1_phase < 5.0f ) // release phase { - m_env1_buf[f] = calcSlope( 1.0f - fraction( m_env1_phase ), env1_s ); + m_env1_buf[f] = calcSlope1( 1.0f - fraction( m_env1_phase ) ); m_env1_phase += m_parent->m_env1_rel; } else m_env1_buf[f] = 0.0f; @@ -942,7 +940,7 @@ void MonstroSynth::renderModulators( fpp_t _frames ) } else if( m_env2_phase < 2.0f ) // attack phase { - m_env2_buf[f] = calcSlope( fraction( m_env2_phase ), env2_s ); + m_env2_buf[f] = calcSlope2( fraction( m_env2_phase ) ); m_env2_phase = qMin( 2.0f, m_env2_phase + m_parent->m_env2_att ); } else if( m_env2_phase < 3.0f ) // hold phase @@ -952,7 +950,7 @@ void MonstroSynth::renderModulators( fpp_t _frames ) } else if( m_env2_phase < 4.0f ) // decay phase { - const sample_t s = calcSlope( 1.0f - fraction( m_env2_phase ), env2_s ); + const sample_t s = calcSlope2( 1.0f - fraction( m_env2_phase ) ); if( s <= env2_sus ) { m_env2_buf[f] = env2_sus; @@ -966,7 +964,7 @@ void MonstroSynth::renderModulators( fpp_t _frames ) } else if( m_env2_phase < 5.0f ) // release phase { - m_env2_buf[f] = calcSlope( 1.0f - fraction( m_env2_phase), env2_s ); + m_env2_buf[f] = calcSlope2( 1.0f - fraction( m_env2_phase) ); m_env2_phase += m_parent->m_env2_rel; } else m_env2_buf[f] = 0.0f; @@ -976,6 +974,20 @@ void MonstroSynth::renderModulators( fpp_t _frames ) } +inline sample_t MonstroSynth::calcSlope1( sample_t s ) +{ + if( m_parent->m_slope1 == 1.0f ) return s; + if( s == -1.0 || s == 0.0 || s == 1.0 ) return s; + return fastPow( s, m_parent->m_slope1 ); +} + +inline sample_t MonstroSynth::calcSlope2( sample_t s ) +{ + if( m_parent->m_slope2 == 1.0f ) return s; + if( s == -1.0 || s == 0.0 || s == 1.0 ) return s; + return fastPow( s, m_parent->m_slope2 ); +} + MonstroInstrument::MonstroInstrument( InstrumentTrack * _instrument_track ) : Instrument( _instrument_track, &monstro_plugin_descriptor ), @@ -1142,6 +1154,7 @@ MonstroInstrument::MonstroInstrument( InstrumentTrack * _instrument_track ) : connect( &m_env1Hold, SIGNAL( dataChanged() ), this, SLOT( updateEnvelope1() ) ); connect( &m_env1Dec, SIGNAL( dataChanged() ), this, SLOT( updateEnvelope1() ) ); connect( &m_env1Rel, SIGNAL( dataChanged() ), this, SLOT( updateEnvelope1() ) ); + connect( &m_env1Slope, SIGNAL( dataChanged() ), this, SLOT( updateSlope1() ) ); // updateEnvelope2 @@ -1150,7 +1163,8 @@ MonstroInstrument::MonstroInstrument( InstrumentTrack * _instrument_track ) : connect( &m_env2Hold, SIGNAL( dataChanged() ), this, SLOT( updateEnvelope2() ) ); connect( &m_env2Dec, SIGNAL( dataChanged() ), this, SLOT( updateEnvelope2() ) ); connect( &m_env2Rel, SIGNAL( dataChanged() ), this, SLOT( updateEnvelope2() ) ); - + connect( &m_env2Slope, SIGNAL( dataChanged() ), this, SLOT( updateSlope2() ) ); + // updateLFOAtts connect( &m_lfo1Att, SIGNAL( dataChanged() ), this, SLOT( updateLFOAtts() ) ); @@ -1576,6 +1590,20 @@ void MonstroInstrument::updateSamplerate() } +void MonstroInstrument::updateSlope1() +{ + const float slope = m_env1Slope.value(); + m_slope1 = powf( 10.0f, static_cast( slope * -1.0f ) ); +} + + +void MonstroInstrument::updateSlope2() +{ + const float slope = m_env2Slope.value(); + m_slope2 = powf( 10.0f, static_cast( slope * -1.0f ) ); +} + + MonstroView::MonstroView( Instrument * _instrument, QWidget * _parent ) : InstrumentView( _instrument, _parent ) diff --git a/plugins/monstro/Monstro.h b/plugins/monstro/Monstro.h index 45e82e7cc..2b84a1678 100644 --- a/plugins/monstro/Monstro.h +++ b/plugins/monstro/Monstro.h @@ -216,12 +216,10 @@ private: return s1 + ( s2 - s1 ) * x; }*/ // using interpolation.h from now on - inline sample_t calcSlope( sample_t _s, float _slope ) - { - if( _slope == 0.0f ) return _s; - const double exp = fastPow( 10.0, static_cast( _slope * -1.0 ) ); - return fastPow( _s, exp ); - } + inline sample_t calcSlope1( sample_t s ); + + inline sample_t calcSlope2( sample_t s ); + // checks for lower bound for phase, upper bound is already checked by oscillator-functions in both // oscillator.h and bandlimitedwave.h so we save some cpu by only checking lower bound @@ -306,7 +304,7 @@ private: sample_t m_env1_phase; sample_t m_env2_phase; - + float m_lfo1_phase; float m_lfo2_phase; @@ -377,7 +375,9 @@ public slots: void updateEnvelope2(); void updateLFOAtts(); void updateSamplerate(); - + void updateSlope1(); + void updateSlope2(); + protected: float m_osc1l_vol; float m_osc1r_vol; @@ -417,6 +417,9 @@ protected: f_cnt_t m_env1_relF; f_cnt_t m_env2_relF; + float m_slope1; + float m_slope2; + f_cnt_t m_lfo1_att; f_cnt_t m_lfo2_att; From ca36fb141d4d62c32c3299e0769cccf4beb77d6c Mon Sep 17 00:00:00 2001 From: Vesa Date: Fri, 2 May 2014 21:37:49 +0300 Subject: [PATCH 2/3] oops.. --- plugins/monstro/Monstro.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/monstro/Monstro.cpp b/plugins/monstro/Monstro.cpp index ee8bfb6c6..632ed7a45 100644 --- a/plugins/monstro/Monstro.cpp +++ b/plugins/monstro/Monstro.cpp @@ -977,14 +977,14 @@ void MonstroSynth::renderModulators( fpp_t _frames ) inline sample_t MonstroSynth::calcSlope1( sample_t s ) { if( m_parent->m_slope1 == 1.0f ) return s; - if( s == -1.0 || s == 0.0 || s == 1.0 ) return s; + if( s == 0.0f || s == 1.0f ) return s; return fastPow( s, m_parent->m_slope1 ); } inline sample_t MonstroSynth::calcSlope2( sample_t s ) { if( m_parent->m_slope2 == 1.0f ) return s; - if( s == -1.0 || s == 0.0 || s == 1.0 ) return s; + if( s == 0.0f || s == 1.0f ) return s; return fastPow( s, m_parent->m_slope2 ); } From 7a4395aabb76c26f265366426a36ffaeed5ca887 Mon Sep 17 00:00:00 2001 From: Vesa Date: Fri, 2 May 2014 21:40:07 +0300 Subject: [PATCH 3/3] ... oops 2... --- plugins/monstro/Monstro.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/monstro/Monstro.cpp b/plugins/monstro/Monstro.cpp index 632ed7a45..fb6f7d1ad 100644 --- a/plugins/monstro/Monstro.cpp +++ b/plugins/monstro/Monstro.cpp @@ -977,14 +977,14 @@ void MonstroSynth::renderModulators( fpp_t _frames ) inline sample_t MonstroSynth::calcSlope1( sample_t s ) { if( m_parent->m_slope1 == 1.0f ) return s; - if( s == 0.0f || s == 1.0f ) return s; + if( s == 0.0f ) return s; return fastPow( s, m_parent->m_slope1 ); } inline sample_t MonstroSynth::calcSlope2( sample_t s ) { if( m_parent->m_slope2 == 1.0f ) return s; - if( s == 0.0f || s == 1.0f ) return s; + if( s == 0.0f ) return s; return fastPow( s, m_parent->m_slope2 ); }