From a850c1dd43d8ff75c24baa32233860fd273b9047 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sat, 21 Mar 2009 10:20:32 +0100 Subject: [PATCH] Oscillator: fixed samplerate dependence of FM/PM When doing FM/PM, the value of sub-oscillator is globally/locally added to phase. However when doing this, a ratio between fixed default samplerate and actual samplerate needs to be taken into account in the phase calculation. This commit fixes missounding render output when rendering projects with FM/PM inside at higher samplerates. (Thanks to Skiessi for his ladspa2.mmpz which clearly brought up this bug) (cherry picked from commit acaaea82046df9c9f7cc3dab792f809b7cd4753e) --- src/core/oscillator.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/oscillator.cpp b/src/core/oscillator.cpp index bf47d1ce6..7bbdecab1 100644 --- a/src/core/oscillator.cpp +++ b/src/core/oscillator.cpp @@ -375,10 +375,13 @@ void oscillator::updatePM( sampleFrame * _ab, const fpp_t _frames, m_subOsc->update( _ab, _frames, _chnl ); recalcPhase(); const float osc_coeff = m_freq * m_detuning; + const float sampleRateCorrection = 44100.0f / + engine::getMixer()->processingSampleRate(); for( fpp_t frame = 0; frame < _frames; ++frame ) { - _ab[frame][_chnl] = getSample( m_phase + _ab[frame][_chnl] ) + _ab[frame][_chnl] = getSample( m_phase + + _ab[frame][_chnl]*sampleRateCorrection ) * m_volume; m_phase += osc_coeff; } @@ -457,10 +460,12 @@ void oscillator::updateFM( sampleFrame * _ab, const fpp_t _frames, m_subOsc->update( _ab, _frames, _chnl ); recalcPhase(); const float osc_coeff = m_freq * m_detuning; + const float sampleRateCorrection = 44100.0f / + engine::getMixer()->processingSampleRate(); for( fpp_t frame = 0; frame < _frames; ++frame ) { - m_phase += _ab[frame][_chnl]; + m_phase += _ab[frame][_chnl] * sampleRateCorrection; _ab[frame][_chnl] = getSample( m_phase ) * m_volume; m_phase += osc_coeff; }