diff --git a/include/lmms_math.h b/include/lmms_math.h index 7c965eb77..8f09a1b5a 100644 --- a/include/lmms_math.h +++ b/include/lmms_math.h @@ -165,4 +165,29 @@ static inline float linearToLogScale( float min, float max, float value ) return powf( val, EXP ) * ( max - min ) + min; } + + + +//! @brief Converts linear amplitude (0-1.0) to dBV scale. +//! @param amp Linear amplitude, where 1.0 = 0dBV. +//! @return Amplitude in dBV. -inf for 0 amplitude. +static inline float ampToDbv( float amp ) +{ + return amp == 0.0f + ? -INFINITY + : log10f( amp ) * 20.0f; +} + + +//! @brief Converts dBV-scale to linear amplitude with 0dBV = 1.0 +//! @param dbv The dBV value to convert: all infinites are treated as -inf and result in 0 +//! @return Linear amplitude +static inline float dbvToAmp( float dbv ) +{ + return isinff( dbv ) + ? 0.0f + : powf( 10.0f, dbv * 0.05f ); +} + + #endif diff --git a/plugins/monstro/Monstro.cpp b/plugins/monstro/Monstro.cpp index e34acc2fe..f3c2a86ac 100644 --- a/plugins/monstro/Monstro.cpp +++ b/plugins/monstro/Monstro.cpp @@ -921,7 +921,7 @@ void MonstroSynth::renderModulators( fpp_t _frames ) // envelope 1 // adjust phase for release - if( m_nph->isReleased() && m_env1_phase < 4.0f ) + if( m_env1_phase < 4.0f && m_nph->isReleased() && f >= m_nph->framesBeforeRelease() ) { if( m_env1_phase < 1.0f ) m_env1_phase = 5.0f; else if( m_env1_phase < 2.0f ) m_env1_phase = 5.0f - fraction( m_env1_phase ); @@ -973,7 +973,7 @@ void MonstroSynth::renderModulators( fpp_t _frames ) // adjust phase for release - if( m_nph->isReleased() && m_env2_phase < 4.0f ) + if( m_env2_phase < 4.0f && m_nph->isReleased() && f >= m_nph->framesBeforeRelease() ) { if( m_env2_phase < 1.0f ) m_env2_phase = 5.0f; else if( m_env2_phase < 2.0f ) m_env2_phase = 5.0f - fraction( m_env2_phase );