Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle divisions by 0 in Lb302 and Monstro #7021

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions plugins/Lb302/Lb302.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,20 +585,23 @@ int Lb302Synth::process(sampleFrame *outbuf, const int size)
vco_k = 0.5 * Oscillator::noiseSample( vco_c );
break;

// The next cases all use the BandLimitedWave class which uses the oscillator increment `vco_inc` to compute samples.
// If that oscillator increment is 0 we return a 0 sample because calling BandLimitedWave::pdToLen(0) leads to a
// division by 0 which in turn leads to floating point exceptions.
case VcoShape::BLSawtooth:
vco_k = BandLimitedWave::oscillate( vco_c + 0.5f, BandLimitedWave::pdToLen( vco_inc ), BandLimitedWave::Waveform::BLSaw ) * 0.5f;
vco_k = vco_inc == 0. ? 0. : BandLimitedWave::oscillate(vco_c + 0.5f, BandLimitedWave::pdToLen(vco_inc), BandLimitedWave::Waveform::BLSaw) * 0.5f;
break;

case VcoShape::BLSquare:
vco_k = BandLimitedWave::oscillate( vco_c + 0.5f, BandLimitedWave::pdToLen( vco_inc ), BandLimitedWave::Waveform::BLSquare ) * 0.5f;
vco_k = vco_inc == 0. ? 0. : BandLimitedWave::oscillate(vco_c + 0.5f, BandLimitedWave::pdToLen(vco_inc), BandLimitedWave::Waveform::BLSquare) * 0.5f;
break;

case VcoShape::BLTriangle:
vco_k = BandLimitedWave::oscillate( vco_c + 0.5f, BandLimitedWave::pdToLen( vco_inc ), BandLimitedWave::Waveform::BLTriangle ) * 0.5f;
vco_k = vco_inc == 0. ? 0. : BandLimitedWave::oscillate(vco_c + 0.5f, BandLimitedWave::pdToLen(vco_inc), BandLimitedWave::Waveform::BLTriangle) * 0.5f;
break;

case VcoShape::BLMoog:
vco_k = BandLimitedWave::oscillate( vco_c + 0.5f, BandLimitedWave::pdToLen( vco_inc ), BandLimitedWave::Waveform::BLMoog );
vco_k = vco_inc == 0. ? 0. : BandLimitedWave::oscillate(vco_c + 0.5f, BandLimitedWave::pdToLen(vco_inc), BandLimitedWave::Waveform::BLMoog);
break;
}

Expand Down
72 changes: 55 additions & 17 deletions plugins/Monstro/Monstro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,531 +111,569 @@
}


void MonstroSynth::renderOutput( fpp_t _frames, sampleFrame * _buf )
{
float modtmp; // temp variable for freq modulation
// macros for modulating with env/lfos
#define modulatefreq( car, mod ) \
modtmp = 0.0f; \
if( mod##_e1 != 0.0f ) modtmp += m_env[0][f] * mod##_e1; \
if( mod##_e2 != 0.0f ) modtmp += m_env[1][f] * mod##_e2; \
if( mod##_l1 != 0.0f ) modtmp += m_lfo[0][f] * mod##_l1; \
if( mod##_l2 != 0.0f ) modtmp += m_lfo[1][f] * mod##_l2; \
car = qBound( MIN_FREQ, car * powf( 2.0f, modtmp ), MAX_FREQ );

#define modulateabs( car, mod ) \
if( mod##_e1 != 0.0f ) car += m_env[0][f] * mod##_e1; \
if( mod##_e2 != 0.0f ) car += m_env[1][f] * mod##_e2; \
if( mod##_l1 != 0.0f ) car += m_lfo[0][f] * mod##_l1; \
if( mod##_l2 != 0.0f ) car += m_lfo[1][f] * mod##_l2;

#define modulatephs( car, mod ) \
if( mod##_e1 != 0.0f ) car += m_env[0][f] * mod##_e1; \
if( mod##_e2 != 0.0f ) car += m_env[1][f] * mod##_e2; \
if( mod##_l1 != 0.0f ) car += m_lfo[0][f] * mod##_l1; \
if( mod##_l2 != 0.0f ) car += m_lfo[1][f] * mod##_l2;

#define modulatevol( car, mod ) \
if( mod##_e1 > 0.0f ) car *= ( 1.0f - mod##_e1 + mod##_e1 * m_env[0][f] ); \
if( mod##_e1 < 0.0f ) car *= ( 1.0f + mod##_e1 * m_env[0][f] ); \
if( mod##_e2 > 0.0f ) car *= ( 1.0f - mod##_e2 + mod##_e2 * m_env[1][f] ); \
if( mod##_e2 < 0.0f ) car *= ( 1.0f + mod##_e2 * m_env[1][f] ); \
if( mod##_l1 != 0.0f ) car *= ( 1.0f + mod##_l1 * m_lfo[0][f] ); \
if( mod##_l2 != 0.0f ) car *= ( 1.0f + mod##_l2 * m_lfo[1][f] ); \
car = qBound( -MODCLIP, car, MODCLIP );



////////////////////
// //
// MODULATORS //
// //
////////////////////

// LFO phase offsets
const float lfo1_po = m_parent->m_lfo1Phs.value() / 360.0f;
const float lfo2_po = m_parent->m_lfo2Phs.value() / 360.0f;

// remove cruft from phase counters to prevent overflow, add phase offset
m_lfo_phase[0] = absFraction( m_lfo_phase[0] + lfo1_po );
m_lfo_phase[1] = absFraction( m_lfo_phase[1] + lfo2_po );

// LFO rates and increment
m_lfo_rate[0] = ( m_parent->m_lfo1Rate.value() * 0.001f * m_parent->m_samplerate );
m_lfo_rate[1] = ( m_parent->m_lfo2Rate.value() * 0.001f * m_parent->m_samplerate );
m_lfo_inc[0] = 1.0f / m_lfo_rate[0];
m_lfo_inc[1] = 1.0f / m_lfo_rate[1];

m_env_sus[0] = m_parent-> m_env1Sus.value();
m_env_sus[1] = m_parent-> m_env2Sus.value();

m_lfovalue[0] = m_parent->m_lfo1Wave.value();
m_lfovalue[1] = m_parent->m_lfo2Wave.value();
m_lfoatt[0] = m_parent->m_lfo1_att;
m_lfoatt[1] = m_parent->m_lfo2_att;

m_env_pre[0] = m_parent->m_env1_pre;
m_env_att[0] = m_parent->m_env1_att;
m_env_hold[0] = m_parent->m_env1_hold;
m_env_dec[0] = m_parent->m_env1_dec;
m_env_rel[0] = m_parent->m_env1_rel;
m_env_pre[1] = m_parent->m_env2_pre;
m_env_att[1] = m_parent->m_env2_att;
m_env_hold[1] = m_parent->m_env2_hold;
m_env_dec[1] = m_parent->m_env2_dec;
m_env_rel[1] = m_parent->m_env2_rel;


// get updated osc1 values
// get pulse width
const float pw = ( m_parent->m_osc1Pw.value() * 0.01f );
const float o1pw_e1 = ( m_parent->m_pw1env1.value() );
const float o1pw_e2 = ( m_parent->m_pw1env2.value() );
const float o1pw_l1 = ( m_parent->m_pw1lfo1.value() * 0.5f );
const float o1pw_l2 = ( m_parent->m_pw1lfo2.value() * 0.5f );
const bool o1pw_mod = o1pw_e1 != 0.0f || o1pw_e2 != 0.0f || o1pw_l1 != 0.0f || o1pw_l2 != 0.0f;

// get phases
const float o1lpo = m_parent->m_osc1l_po;
const float o1rpo = m_parent->m_osc1r_po;
const float o1p_e1 = ( m_parent->m_phs1env1.value() );
const float o1p_e2 = ( m_parent->m_phs1env2.value() );
const float o1p_l1 = ( m_parent->m_phs1lfo1.value() * 0.5f );
const float o1p_l2 = ( m_parent->m_phs1lfo2.value() * 0.5f );
const bool o1p_mod = o1p_e1 != 0.0f || o1p_e2 != 0.0f || o1p_l1 != 0.0f || o1p_l2 != 0.0f;

// get pitch
const float o1lfb = ( m_parent->m_osc1l_freq * m_nph->frequency() );
const float o1rfb = ( m_parent->m_osc1r_freq * m_nph->frequency() );
const float o1f_e1 = ( m_parent->m_pit1env1.value() * 2.0f );
const float o1f_e2 = ( m_parent->m_pit1env2.value() * 2.0f );
const float o1f_l1 = ( m_parent->m_pit1lfo1.value() );
const float o1f_l2 = ( m_parent->m_pit1lfo2.value() );
const bool o1f_mod = o1f_e1 != 0.0f || o1f_e2 != 0.0f || o1f_l1 != 0.0f || o1f_l2 != 0.0f;

// get volumes
const float o1lv = m_parent->m_osc1l_vol;
const float o1rv = m_parent->m_osc1r_vol;
const float o1v_e1 = ( m_parent->m_vol1env1.value() );
const float o1v_e2 = ( m_parent->m_vol1env2.value() );
const float o1v_l1 = ( m_parent->m_vol1lfo1.value() );
const float o1v_l2 = ( m_parent->m_vol1lfo2.value() );
const bool o1v_mod = o1v_e1 != 0.0f || o1v_e2 != 0.0f || o1v_l1 != 0.0f || o1v_l2 != 0.0f;

// update osc2
// get waveform
const int o2w = m_parent->m_osc2Wave.value();

// get phases
const float o2lpo = m_parent->m_osc2l_po;
const float o2rpo = m_parent->m_osc2r_po;
const float o2p_e1 = ( m_parent->m_phs2env1.value() );
const float o2p_e2 = ( m_parent->m_phs2env2.value() );
const float o2p_l1 = ( m_parent->m_phs2lfo1.value() * 0.5f );
const float o2p_l2 = ( m_parent->m_phs2lfo2.value() * 0.5f );
const bool o2p_mod = o2p_e1 != 0.0f || o2p_e2 != 0.0f || o2p_l1 != 0.0f || o2p_l2 != 0.0f;

// get pitch
const float o2lfb = ( m_parent->m_osc2l_freq * m_nph->frequency() );
const float o2rfb = ( m_parent->m_osc2r_freq * m_nph->frequency() );
const float o2f_e1 = ( m_parent->m_pit2env1.value() * 2.0f );
const float o2f_e2 = ( m_parent->m_pit2env2.value() * 2.0f );
const float o2f_l1 = ( m_parent->m_pit2lfo1.value() );
const float o2f_l2 = ( m_parent->m_pit2lfo2.value() );
const bool o2f_mod = o2f_e1 != 0.0f || o2f_e2 != 0.0f || o2f_l1 != 0.0f || o2f_l2 != 0.0f;

// get volumes
const float o2lv = m_parent->m_osc2l_vol;
const float o2rv = m_parent->m_osc2r_vol;
const float o2v_e1 = ( m_parent->m_vol2env1.value() );
const float o2v_e2 = ( m_parent->m_vol2env2.value() );
const float o2v_l1 = ( m_parent->m_vol2lfo1.value() );
const float o2v_l2 = ( m_parent->m_vol2lfo2.value() );
const bool o2v_mod = o2v_e1 != 0.0f || o2v_e2 != 0.0f || o2v_l1 != 0.0f || o2v_l2 != 0.0f;


// update osc3
// get waveforms
const int o3w1 = m_parent->m_osc3Wave1.value();
const int o3w2 = m_parent->m_osc3Wave2.value();

// get phases
const float o3lpo = m_parent->m_osc3l_po;
const float o3rpo = m_parent->m_osc3r_po;
const float o3p_e1 = ( m_parent->m_phs3env1.value() );
const float o3p_e2 = ( m_parent->m_phs3env2.value() );
const float o3p_l1 = ( m_parent->m_phs3lfo1.value() * 0.5f );
const float o3p_l2 = ( m_parent->m_phs3lfo2.value() * 0.5f );
const bool o3p_mod = o3p_e1 != 0.0f || o3p_e2 != 0.0f || o3p_l1 != 0.0f || o3p_l2 != 0.0f;

// get pitch modulators
const float o3fb = ( m_parent->m_osc3_freq * m_nph->frequency() );
const float o3f_e1 = ( m_parent->m_pit3env1.value() * 2.0f );
const float o3f_e2 = ( m_parent->m_pit3env2.value() * 2.0f );
const float o3f_l1 = ( m_parent->m_pit3lfo1.value() );
const float o3f_l2 = ( m_parent->m_pit3lfo2.value() );
const bool o3f_mod = o3f_e1 != 0.0f || o3f_e2 != 0.0f || o3f_l1 != 0.0f || o3f_l2 != 0.0f;

// get volumes
const float o3lv = m_parent->m_osc3l_vol;
const float o3rv = m_parent->m_osc3r_vol;
const float o3v_e1 = ( m_parent->m_vol3env1.value() );
const float o3v_e2 = ( m_parent->m_vol3env2.value() );
const float o3v_l1 = ( m_parent->m_vol3lfo1.value() );
const float o3v_l2 = ( m_parent->m_vol3lfo2.value() );
const bool o3v_mod = o3v_e1 != 0.0f || o3v_e2 != 0.0f || o3v_l1 != 0.0f || o3v_l2 != 0.0f;

// get sub
const float o3sub = ( m_parent->m_osc3Sub.value() + 100.0f ) / 200.0f;
const float o3s_e1 = ( m_parent->m_sub3env1.value() );
const float o3s_e2 = ( m_parent->m_sub3env2.value() );
const float o3s_l1 = ( m_parent->m_sub3lfo1.value() * 0.5f );
const float o3s_l2 = ( m_parent->m_sub3lfo2.value() * 0.5f );
const bool o3s_mod = o3s_e1 != 0.0f || o3s_e2 != 0.0f || o3s_l1 != 0.0f || o3s_l2 != 0.0f;


//o2-o3 modulation

const int omod = m_parent->m_o23Mod.value();

// sync information

const bool o1ssr = m_parent->m_osc1SSR.value();
const bool o1ssf = m_parent->m_osc1SSF.value();
const bool o2sync = m_parent->m_osc2SyncH.value();
const bool o3sync = m_parent->m_osc3SyncH.value();
const bool o2syncr = m_parent->m_osc2SyncR.value();
const bool o3syncr = m_parent->m_osc3SyncR.value();

///////////////////////////
// //
// start buffer loop //
// //
///////////////////////////

// declare working variables for for loop

// phase manipulation vars - these can be reused by all oscs
float leftph;
float rightph;
float pd_l;
float pd_r;
float len_l;
float len_r;
float len_l(0.);
float len_r(0.);

// osc1 vars
float o1l_f;
float o1r_f;
float o1l_p = m_osc1l_phase + o1lpo; // we add phase offset here so we don't have to do it every frame
float o1r_p = m_osc1r_phase + o1rpo; // then subtract it again after loop...
float o1_pw;

// osc2 vars
float o2l_f;
float o2r_f;
float o2l_p = m_osc2l_phase + o2lpo;
float o2r_p = m_osc2r_phase + o2rpo;

// osc3 vars
float o3l_f;
float o3r_f;
float o3l_p = m_osc3l_phase + o3lpo;
float o3r_p = m_osc3r_phase + o3rpo;
float sub;

// render modulators: envelopes, lfos
updateModulators( m_env[0].data(), m_env[1].data(), m_lfo[0].data(), m_lfo[1].data(), _frames );

// begin for loop
for( f_cnt_t f = 0; f < _frames; ++f )
{
/* // debug code
if( f % 10 == 0 ) {
qDebug( "env1 %f -- env1 phase %f", m_env1_buf[f], m_env1_phase );
qDebug( "env1 pre %f att %f dec %f rel %f ", m_parent->m_env1_pre, m_parent->m_env1_att,
m_parent->m_env1_dec, m_parent->m_env1_rel );
}*/


/////////////////////////////
// //
// OSC 1 //
// //
/////////////////////////////

// calc and mod frequencies
o1l_f = o1lfb;
o1r_f = o1rfb;
if( o1f_mod )
{
modulatefreq( o1l_f, o1f )
modulatefreq( o1r_f, o1f )
}
// calc and modulate pulse
o1_pw = pw;
if( o1pw_mod )
{
modulateabs( o1_pw, o1pw )
o1_pw = qBound( PW_MIN, o1_pw, PW_MAX );
}

// calc and modulate phase
leftph = o1l_p;
rightph = o1r_p;
if( o1p_mod )
{
modulatephs( leftph, o1p )
modulatephs( rightph, o1p )
}

// pulse wave osc
sample_t O1L = ( absFraction( leftph ) < o1_pw ) ? 1.0f : -1.0f;
sample_t O1R = ( absFraction( rightph ) < o1_pw ) ? 1.0f : -1.0f;

// check for rise/fall, and sync if appropriate
// sync on rise
if( o1ssr )
{
// hard sync
if( o2sync )
{
if( O1L > m_osc1l_last ) { o2l_p = o2lpo; m_counter2l = m_parent->m_counterMax; }
if( O1R > m_osc1r_last ) { o2r_p = o2rpo; m_counter2r = m_parent->m_counterMax; }
}
if( o3sync )
{
if( O1L > m_osc1l_last ) { o3l_p = o3lpo; m_counter3l = m_parent->m_counterMax; }
if( O1R > m_osc1r_last ) { o3r_p = o3rpo; m_counter3r = m_parent->m_counterMax; }
}
// reverse sync
if( o2syncr )
{
if( O1L > m_osc1l_last ) { m_invert2l = !m_invert2l; m_counter2l = m_parent->m_counterMax; }
if( O1R > m_osc1r_last ) { m_invert2r = !m_invert2r; m_counter2r = m_parent->m_counterMax; }
}
if( o3syncr )
{
if( O1L > m_osc1l_last ) { m_invert3l = !m_invert3l; m_counter3l = m_parent->m_counterMax; }
if( O1R > m_osc1r_last ) { m_invert3r = !m_invert3r; m_counter3r = m_parent->m_counterMax; }
}
}
// sync on fall
if( o1ssf )
{
// hard sync
if( o2sync )
{
if( O1L < m_osc1l_last ) { o2l_p = o2lpo; m_counter2l = m_parent->m_counterMax; }
if( O1R < m_osc1r_last ) { o2r_p = o2rpo; m_counter2r = m_parent->m_counterMax; }
}
if( o3sync )
{
if( O1L < m_osc1l_last ) { o3l_p = o3lpo; m_counter3l = m_parent->m_counterMax; }
if( O1R < m_osc1r_last ) { o3r_p = o3rpo; m_counter3r = m_parent->m_counterMax; }
}
// reverse sync
if( o2syncr )
{
if( O1L < m_osc1l_last ) { m_invert2l = !m_invert2l; m_counter2l = m_parent->m_counterMax; }
if( O1R < m_osc1r_last ) { m_invert2r = !m_invert2r; m_counter2r = m_parent->m_counterMax; }
}
if( o3syncr )
{
if( O1L < m_osc1l_last ) { m_invert3l = !m_invert3l; m_counter3l = m_parent->m_counterMax; }
if( O1R < m_osc1r_last ) { m_invert3r = !m_invert3r; m_counter3r = m_parent->m_counterMax; }
}
}

// update last before signal is touched
// also do a very simple amp delta cap
const sample_t tmpl = m_osc1l_last;
const sample_t tmpr = m_osc1r_last;

m_osc1l_last = O1L;
m_osc1r_last = O1R;

if( tmpl != O1L ) O1L = 0.0f;
if( tmpr != O1R ) O1R = 0.0f;

// modulate volume
O1L *= o1lv;
O1R *= o1rv;
if( o1v_mod )
{
modulatevol( O1L, o1v )
modulatevol( O1R, o1v )
}

// update osc1 phase working variable
o1l_p += 1.0f / ( static_cast<float>( m_parent->m_samplerate ) / o1l_f );
o1r_p += 1.0f / ( static_cast<float>( m_parent->m_samplerate ) / o1r_f );

/////////////////////////////
// //
// OSC 2 //
// //
/////////////////////////////

// calc and mod frequencies
o2l_f = o2lfb;
o2r_f = o2rfb;
if( o2f_mod )
{
modulatefreq( o2l_f, o2f )
modulatefreq( o2r_f, o2f )
}

// calc and modulate phase
leftph = o2l_p;
rightph = o2r_p;
if( o2p_mod )
{
modulatephs( leftph, o2p )
modulatephs( rightph, o2p )
}
leftph = absFraction( leftph );
rightph = absFraction( rightph );

// phase delta
pd_l = qAbs( leftph - m_ph2l_last );
if( pd_l > 0.5 ) pd_l = 1.0 - pd_l;
pd_r = qAbs( rightph - m_ph2r_last );
if( pd_r > 0.5 ) pd_r = 1.0 - pd_r;

// multi-wave DC Oscillator
len_l = BandLimitedWave::pdToLen( pd_l );
len_r = BandLimitedWave::pdToLen( pd_r );
if( m_counter2l > 0 ) { len_l /= m_counter2l; m_counter2l--; }
if( m_counter2r > 0 ) { len_r /= m_counter2r; m_counter2r--; }
sample_t O2L = oscillate( o2w, leftph, len_l );
sample_t O2R = oscillate( o2w, rightph, len_r );
sample_t O2L = 0.;
if (pd_l != 0.)
{
len_l = BandLimitedWave::pdToLen(pd_l);
if (m_counter2l > 0)
{
len_l /= m_counter2l; m_counter2l--;
}
O2L = oscillate(o2w, leftph, len_l);
}

sample_t O2R = 0.;
if (len_r != 0.)
{
len_r = BandLimitedWave::pdToLen(pd_r);
if (m_counter2r > 0)
{
len_r /= m_counter2r; m_counter2r--;
}
O2R = oscillate(o2w, rightph, len_r);
}

// modulate volume
O2L *= o2lv;
O2R *= o2rv;
if( o2v_mod )
{
modulatevol( O2L, o2v )
modulatevol( O2R, o2v )
}

// reverse sync - invert waveforms when needed
if( m_invert2l ) O2L *= -1.0;
if( m_invert2r ) O2R *= -1.0;

// update osc2 phases
m_ph2l_last = leftph;
m_ph2r_last = rightph;
o2l_p += 1.0f / ( static_cast<float>( m_parent->m_samplerate ) / o2l_f );
o2r_p += 1.0f / ( static_cast<float>( m_parent->m_samplerate ) / o2r_f );

/////////////////////////////
// //
// OSC 3 //
// //
/////////////////////////////

// calc and mod frequencies
o3l_f = o3fb;
o3r_f = o3fb;
if( o3f_mod )
{
modulatefreq( o3l_f, o3f )
modulatefreq( o3r_f, o3f )
}
// calc and modulate phase
leftph = o3l_p;
rightph = o3r_p;
if( o3p_mod )
{
modulatephs( leftph, o3p )
modulatephs( rightph, o3p )
}

// o2 modulation?
if( omod == MOD_PM )
{
leftph += O2L * 0.5f;
rightph += O2R * 0.5f;
}
leftph = absFraction( leftph );
rightph = absFraction( rightph );

// phase delta
pd_l = qAbs( leftph - m_ph3l_last );
if( pd_l > 0.5 ) pd_l = 1.0 - pd_l;
pd_r = qAbs( rightph - m_ph3r_last );
if( pd_r > 0.5 ) pd_r = 1.0 - pd_r;

// multi-wave DC Oscillator
len_l = BandLimitedWave::pdToLen( pd_l );
len_r = BandLimitedWave::pdToLen( pd_r );
if( m_counter3l > 0 ) { len_l /= m_counter3l; m_counter3l--; }
if( m_counter3r > 0 ) { len_r /= m_counter3r; m_counter3r--; }
// sub-osc 1
sample_t O3AL = oscillate( o3w1, leftph, len_l );
sample_t O3AR = oscillate( o3w1, rightph, len_r );
sample_t O3AL = 0.;
sample_t O3AR = 0.;

// multi-wave DC Oscillator, sub-osc 2
sample_t O3BL = oscillate( o3w2, leftph, len_l );
sample_t O3BR = oscillate( o3w2, rightph, len_r );
sample_t O3BL = 0.;
sample_t O3BR = 0.;

if (pd_l != 0.)
{
len_l = BandLimitedWave::pdToLen(pd_l);
if (m_counter3l > 0)
{
len_l /= m_counter3l; m_counter3l--;
}
// sub-osc 1
O3AL = oscillate(o3w1, leftph, len_l);

// multi-wave DC Oscillator, sub-osc 2
O3BL = oscillate(o3w2, leftph, len_l);
}

if (pd_r != 0.)
{
len_r = BandLimitedWave::pdToLen(pd_r);
if (m_counter3r > 0)
{
len_r /= m_counter3r; m_counter3r--;
}
// sub-osc 1
O3AR = oscillate(o3w1, rightph, len_r);

// multi-wave DC Oscillator, sub-osc 2
O3BR = oscillate(o3w2, rightph, len_r);
}

// calc and modulate sub
sub = o3sub;
if( o3s_mod )
{
modulateabs( sub, o3s )
sub = qBound( 0.0f, sub, 1.0f );
}

sample_t O3L = linearInterpolate( O3AL, O3BL, sub );
sample_t O3R = linearInterpolate( O3AR, O3BR, sub );

// modulate volume
O3L *= o3lv;
O3R *= o3rv;
if( o3v_mod )
{
modulatevol( O3L, o3v )
modulatevol( O3R, o3v )
}
// o2 modulation?
if( omod == MOD_AM )
{
O3L = qBound( -MODCLIP, O3L * qMax( 0.0f, 1.0f + O2L ), MODCLIP );
O3R = qBound( -MODCLIP, O3R * qMax( 0.0f, 1.0f + O2R ), MODCLIP );
}

// reverse sync - invert waveforms when needed
if( m_invert3l ) O3L *= -1.0;
if( m_invert3r ) O3R *= -1.0;

// update osc3 phases
m_ph3l_last = leftph;
m_ph3r_last = rightph;
len_l = 1.0f / ( static_cast<float>( m_parent->m_samplerate ) / o3l_f );
len_r = 1.0f / ( static_cast<float>( m_parent->m_samplerate ) / o3r_f );
// handle FM as PM
if( omod == MOD_FM )
{
len_l += O2L * m_parent->m_fmCorrection;
len_r += O2R * m_parent->m_fmCorrection;
}
o3l_p += len_l;
o3r_p += len_r;

// integrator - very simple filter
sample_t L = O1L + O3L + ( omod == MOD_MIX ? O2L : 0.0f );
sample_t R = O1R + O3R + ( omod == MOD_MIX ? O2R : 0.0f );

_buf[f][0] = linearInterpolate( L, m_l_last, m_parent->m_integrator );
_buf[f][1] = linearInterpolate( R, m_r_last, m_parent->m_integrator );

m_l_last = L;
m_r_last = R;
}

// update phases

Check warning on line 676 in plugins/Monstro/Monstro.cpp

View check run for this annotation

codefactor.io / CodeFactor

plugins/Monstro/Monstro.cpp#L114-L676

Very Complex Method
m_osc1l_phase = absFraction( o1l_p - o1lpo );
m_osc1r_phase = absFraction( o1r_p - o1rpo );
m_osc2l_phase = absFraction( o2l_p - o2lpo );
Expand Down
Loading