diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2023-09-01 12:37:53 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2023-09-07 16:51:55 +0900 |
commit | 75b46c18804ce65b0eb69b865d54eb89f84d9193 (patch) | |
tree | d7707ac7c2173c4a2489f788ca8c21012e7fa7f3 | |
parent | 715a0ab4094dae735de1a49373386eacc33c2f2b (diff) | |
download | amarok-75b46c18804ce65b0eb69b865d54eb89f84d9193.tar.gz amarok-75b46c18804ce65b0eb69b865d54eb89f84d9193.zip |
Avoid double logarithmic volume scaling when using libxine >= 1.2.13. This relates to TDE/tdemultimedia#40
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 41def34f87cd17da787edaabcaf7d859f3bd5cf8)
-rw-r--r-- | amarok/src/engine/xine/xine-engine.cpp | 35 | ||||
-rw-r--r-- | amarok/src/engine/xine/xine-engine.h | 4 | ||||
-rw-r--r-- | amarok/src/enginebase.h | 2 |
3 files changed, 37 insertions, 4 deletions
diff --git a/amarok/src/engine/xine/xine-engine.cpp b/amarok/src/engine/xine/xine-engine.cpp index 7b9230ed..478bbb4f 100644 --- a/amarok/src/engine/xine/xine-engine.cpp +++ b/amarok/src/engine/xine/xine-engine.cpp @@ -68,6 +68,7 @@ static inline TQCString configPath() { return TQFile::encodeName(locate( "data", static Fader *s_fader = 0; static OutFader *s_outfader = 0; +bool XineEngine::s_logarithmicVolume = false; XineEngine::XineEngine() : EngineBase() @@ -89,6 +90,12 @@ XineEngine::XineEngine() addPluginProperty("HasCDDA", "true"); // new property debug() << "hello" << endl; + // Detect xine version, this is used for volume adjustment. + // Xine versions prior to 1.2.13 use linear volume, so the engine uses logarithmic volume. + // Xine versions starting from 1.2.13 use logarithmic volume, so the engine uses linear volume. + int xinemajor = 0, xineminor = 0, xinemaint = 0; + xine_get_version(&xinemajor, &xineminor, &xinemaint); + s_logarithmicVolume = (xinemajor * 1000000 + xineminor * 1000 + xinemaint < 1002013); } XineEngine::~XineEngine() @@ -569,6 +576,15 @@ XineEngine::seek( uint ms ) } void +XineEngine::setVolume( uint value ) +{ + m_volume = value; + + setVolumeSW( adjustVolume( value ) ); +} + + +void XineEngine::setVolumeSW( uint vol ) { if ( !m_stream ) @@ -577,6 +593,19 @@ XineEngine::setVolumeSW( uint vol ) xine_set_param( m_stream, XINE_PARAM_AUDIO_AMP_LEVEL, static_cast<uint>( vol * m_preamp ) ); } +// Xine versions prior to 1.2.13 use linear volume, so the engine uses logarithmic volume. +// Xine versions starting from 1.2.13 use logarithmic volume, so the engine uses linear volume. +uint +XineEngine::adjustVolume( uint volume ) +{ + if (s_logarithmicVolume) + { + return XineEngine::makeVolumeLogarithmic(volume); + } + + return volume; +} + void XineEngine::fadeOut( uint fadeLength, bool* terminate, bool exiting ) { @@ -585,7 +614,7 @@ XineEngine::fadeOut( uint fadeLength, bool* terminate, bool exiting ) m_fadeOutRunning = !m_fadeOutRunning; const bool isPlaying = m_stream && ( xine_get_status( m_stream ) == XINE_STATUS_PLAY ); - const float originalVol = Engine::Base::makeVolumeLogarithmic( m_volume ) * m_preamp; + const float originalVol = adjustVolume( m_volume ) * m_preamp; // On shutdown, limit fadeout to 3 secs max, so that we don't risk getting killed const int length = exiting ? TQMIN( fadeLength, 3000 ) : fadeLength; @@ -605,7 +634,7 @@ XineEngine::fadeOut( uint fadeLength, bool* terminate, bool exiting ) if( *terminate ) break; ::usleep( stepSizeUs ); - float vol = Engine::Base::makeVolumeLogarithmic( m_volume ) * m_preamp; + float vol = adjustVolume( m_volume ) * m_preamp; float mix = (float)t.elapsed() / (float)length; if ( mix > 1.0 ) { @@ -1294,7 +1323,7 @@ Fader::run() elapsedUs += stepSizeUs; // get volume (amarok main * equalizer preamp) - float vol = XineEngine::makeVolumeLogarithmic( m_engine->m_volume ) * m_engine->m_preamp; + float vol = XineEngine::adjustVolume( m_engine->m_volume ) * m_engine->m_preamp; // compute the mix factor as the percentage of time spent since fade begun float mix = (elapsedUs / 1000.0) / (float)m_fadeLength; diff --git a/amarok/src/engine/xine/xine-engine.h b/amarok/src/engine/xine/xine-engine.h index 95c19f34..6a707039 100644 --- a/amarok/src/engine/xine/xine-engine.h +++ b/amarok/src/engine/xine/xine-engine.h @@ -53,7 +53,10 @@ class XineEngine : public Engine::Base virtual Amarok::PluginConfig *configure() const; virtual void setEqualizerEnabled( bool ); virtual void setEqualizerParameters( int preamp, const TQValueList<int>& ); + virtual void setVolume( uint value ); virtual void setVolumeSW( uint ); + static uint adjustVolume( uint volume ); + virtual void fadeOut( uint fadeLength, bool* terminate, bool exiting = false ); static void XineEventListener( void*, const xine_event_t* ); @@ -80,6 +83,7 @@ class XineEngine : public Engine::Base int64_t m_currentVpts; float m_preamp; + static bool s_logarithmicVolume; bool m_stopFader; bool m_fadeOutRunning; diff --git a/amarok/src/enginebase.h b/amarok/src/enginebase.h index 25614c76..eabfa53e 100644 --- a/amarok/src/enginebase.h +++ b/amarok/src/enginebase.h @@ -179,7 +179,7 @@ namespace Engine * Set new volume value. * @param value Volume in range 0 to 100. */ - void setVolume( uint value ); + virtual void setVolume( uint value ); /** Set new crossfade length (msec) */ void setXfadeLength( int value ) { m_xfadeLength = value; } |