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 41def34f87)
r14.1.x
Michele Calgaro 1 year ago
parent 715a0ab409
commit 75b46c1880
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -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()
@ -568,6 +575,15 @@ XineEngine::seek( uint ms )
}
}
void
XineEngine::setVolume( uint value )
{
m_volume = value;
setVolumeSW( adjustVolume( value ) );
}
void
XineEngine::setVolumeSW( uint vol )
{
@ -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;

@ -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;

@ -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; }

Loading…
Cancel
Save