From 13237f9c8e3bccca88ac19bf5c9aae3bb195ae61 Mon Sep 17 00:00:00 2001 From: Vesa Date: Tue, 8 Apr 2014 09:48:43 +0300 Subject: [PATCH] Monstro: use phase delta instead of frequency for deciding which wavetable to use --- include/BandLimitedWave.h | 6 ++++++ plugins/monstro/Monstro.cpp | 38 +++++++++++++++++++++++++++++++------ plugins/monstro/Monstro.h | 6 ++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/include/BandLimitedWave.h b/include/BandLimitedWave.h index 9c994a858..9971cf200 100644 --- a/include/BandLimitedWave.h +++ b/include/BandLimitedWave.h @@ -81,6 +81,12 @@ public: { return static_cast( _sr ) / _f; } + + /*! \brief This method converts phase delta to wavelength. It assumes a phase scale of 0 to 1. */ + static inline float pdToLen( float _pd ) + { + return 1.0f / _pd; + } /*! \brief This method provides interpolated samples of bandlimited waveforms. * \param _ph The phase of the sample. diff --git a/plugins/monstro/Monstro.cpp b/plugins/monstro/Monstro.cpp index fc296c115..644bf3168 100644 --- a/plugins/monstro/Monstro.cpp +++ b/plugins/monstro/Monstro.cpp @@ -79,6 +79,11 @@ MonstroSynth::MonstroSynth( MonstroInstrument * _i, NotePlayHandle * _nph, m_osc3l_phase = 0.0f; m_osc3r_phase = 0.0f; + m_ph2l_last = 0.0f; + m_ph2r_last = 0.0f; + m_ph3l_last = 0.0f; + m_ph3r_last = 0.0f; + m_env1_phase = 0.0f; m_env2_phase = 0.0f; @@ -282,6 +287,10 @@ void MonstroSynth::renderOutput( fpp_t _frames, sampleFrame * _buf ) float o3l_p; float o3r_p; float sub; + + // phase delta calculation vars + float pd_l; + float pd_r; // begin for loop for( f_cnt_t f = 0; f < _frames; f++ ) @@ -399,9 +408,15 @@ void MonstroSynth::renderOutput( fpp_t _frames, sampleFrame * _buf ) if( o2l_p < 0 ) o2l_p -= floorf( o2l_p ); if( o2r_p < 0 ) o2r_p -= floorf( o2r_p ); + // phase delta + pd_l = qAbs( o2l_p - m_ph2l_last ); + if( pd_l > 0.5 ) pd_l = 1.0 - pd_l; + pd_r = qAbs( o2r_p - m_ph2r_last ); + if( pd_r > 0.5 ) pd_r = 1.0 - pd_r; + // multi-wave DC Oscillator - sample_t O2L = oscillate( o2w, o2l_p, BandLimitedWave::freqToLen( o2l_f, m_samplerate ) ); - sample_t O2R = oscillate( o2w, o2r_p, BandLimitedWave::freqToLen( o2r_f, m_samplerate ) ); + sample_t O2L = oscillate( o2w, o2l_p, BandLimitedWave::pdToLen( pd_l ) ); + sample_t O2R = oscillate( o2w, o2r_p, BandLimitedWave::pdToLen( pd_r ) ); // do amplitude delta cap O2L = qBound( m_osc2l_last - m_adcap1, O2L, m_osc2l_last + m_adcap1 ); @@ -416,8 +431,11 @@ void MonstroSynth::renderOutput( fpp_t _frames, sampleFrame * _buf ) modulatevol( O2R, o2v ) // update osc2 phases + m_ph2l_last = m_osc2l_phase; + m_ph2r_last = m_osc2r_phase; m_osc2l_phase = fraction( m_osc2l_phase + 1.0f / ( static_cast( m_samplerate ) / o2l_f ) ); m_osc2r_phase = fraction( m_osc2r_phase + 1.0f / ( static_cast( m_samplerate ) / o2r_f ) ); + ///////////////////////////// // // @@ -453,13 +471,19 @@ void MonstroSynth::renderOutput( fpp_t _frames, sampleFrame * _buf ) if( o3l_p < 0 ) o3l_p -= floorf( o3l_p ); if( o3r_p < 0 ) o3r_p -= floorf( o3r_p ); + // phase delta + pd_l = qAbs( o3l_p - m_ph3l_last ); + if( pd_l > 0.5 ) pd_l = 1.0 - pd_l; + pd_r = qAbs( o3r_p - m_ph3r_last ); + if( pd_r > 0.5 ) pd_r = 1.0 - pd_r; + // multi-wave DC Oscillator, sub-osc 1 - sample_t O3AL = oscillate( o3w1, o3l_p, BandLimitedWave::freqToLen( o3l_f, m_samplerate ) ); - sample_t O3AR = oscillate( o3w1, o3r_p, BandLimitedWave::freqToLen( o3r_f, m_samplerate ) ); + sample_t O3AL = oscillate( o3w1, o3l_p, BandLimitedWave::pdToLen( pd_l ) ); + sample_t O3AR = oscillate( o3w1, o3r_p, BandLimitedWave::pdToLen( pd_r ) ); // multi-wave DC Oscillator, sub-osc 2 - sample_t O3BL = oscillate( o3w2, o3l_p, BandLimitedWave::freqToLen( o3l_f, m_samplerate ) ); - sample_t O3BR = oscillate( o3w2, o3r_p, BandLimitedWave::freqToLen( o3r_f, m_samplerate ) ); + sample_t O3BL = oscillate( o3w2, o3l_p, BandLimitedWave::pdToLen( pd_l ) ); + sample_t O3BR = oscillate( o3w2, o3r_p, BandLimitedWave::pdToLen( pd_r ) ); // calc and modulate sub sub = o3sub; @@ -487,6 +511,8 @@ void MonstroSynth::renderOutput( fpp_t _frames, sampleFrame * _buf ) } // update osc3 phases + m_ph3l_last = m_osc3l_phase; + m_ph3r_last = m_osc3r_phase; m_osc3l_phase = fraction( m_osc3l_phase + 1.0f / ( static_cast( m_samplerate ) / o3l_f ) ); m_osc3r_phase = fraction( m_osc3r_phase + 1.0f / ( static_cast( m_samplerate ) / o3r_f ) ); diff --git a/plugins/monstro/Monstro.h b/plugins/monstro/Monstro.h index 2d87b7bd3..4bf5fea0c 100644 --- a/plugins/monstro/Monstro.h +++ b/plugins/monstro/Monstro.h @@ -315,6 +315,12 @@ private: sample_t m_l_last; sample_t m_r_last; + float m_ph2l_last; + float m_ph2r_last; + + float m_ph3l_last; + float m_ph3r_last; + float m_adcap1; float m_adcap2; };