Use AUDIO_VOLUME param instead of AUDIO_AMP_LEVEL

AMP_LEVEL adjusts the amplification level of VOLUME, and since it's
called "volume" in the UI, this is more appropriate.  This also avoids
the need to use logarithmic scaling when adjusting the volume from the
UI, as VOLUME is linear.

When compared with libxine versions older than 1.2.13, there is no
notable difference in how the volume sounds when adjusted.  From 1.2.13,
the sound does scale a little differently as lower volumes are more
audible now (such as 50% and lower).

Signed-off-by: mio <stigma@disroot.org>
fix/use-audio-level
mio 5 months ago
parent 11c0638baf
commit f464b0384b

@ -26,7 +26,6 @@ namespace Codeine {
VideoWindow *VideoWindow::s_instance = nullptr; VideoWindow *VideoWindow::s_instance = nullptr;
bool VideoWindow::s_logarithmicVolume = false;
VideoWindow::VideoWindow( TQWidget *parent ) VideoWindow::VideoWindow( TQWidget *parent )
@ -54,13 +53,6 @@ VideoWindow::VideoWindow( TQWidget *parent )
//TODO sucks //TODO sucks
//TODO namespace this? //TODO namespace this?
myList->next = myList; //init the buffer list myList->next = myList; //init the buffer list
// 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);
} }
VideoWindow::~VideoWindow() VideoWindow::~VideoWindow()
@ -70,16 +62,17 @@ VideoWindow::~VideoWindow()
eject(); eject();
// fade out volume on exit // fade out volume on exit
if( m_stream && xine_get_status( m_stream ) == XINE_STATUS_PLAY ) { const int volBeforeFade = xine_get_param(m_stream, XINE_PARAM_AUDIO_VOLUME);
if (m_stream && xine_get_status(m_stream) == XINE_STATUS_PLAY)
{
int cum = 0; int cum = 0;
for( int v = 99; v >= 0; v-- ) { int vol = volBeforeFade;
int vol = v;
if (s_logarithmicVolume) while (vol > 0)
{ {
vol = makeVolumeLogarithmic(vol); vol -= 1;
} xine_set_param(m_stream, XINE_PARAM_AUDIO_VOLUME, vol);
xine_set_param( m_stream, XINE_PARAM_AUDIO_AMP_LEVEL, vol ); int sleep = int(32000 * (-std::log10(vol + 1.0) + 2));
int sleep = int(32000 * (-std::log10( double(v + 1) ) + 2));
::usleep(sleep); ::usleep(sleep);
@ -95,6 +88,11 @@ VideoWindow::~VideoWindow()
//xine_set_param( m_stream, XINE_PARAM_IGNORE_VIDEO, 1 ); //xine_set_param( m_stream, XINE_PARAM_IGNORE_VIDEO, 1 );
// Xine (or the audio driver) seems to remember the volume level,
// even when xine's audio.volume.remember_volume is set to false.
// FIXME: The VolumeSlider doesn't reflect this initial volume!
xine_set_param(m_stream, XINE_PARAM_AUDIO_VOLUME, volBeforeFade);
if( m_osd ) xine_osd_free( m_osd ); if( m_osd ) xine_osd_free( m_osd );
if( m_stream ) xine_close( m_stream ); if( m_stream ) xine_close( m_stream );
if( m_eventQueue ) xine_event_dispose_queue( m_eventQueue ); if( m_eventQueue ) xine_event_dispose_queue( m_eventQueue );
@ -268,8 +266,7 @@ VideoWindow::load( const KURL &url )
setParameter( XINE_PARAM_SPU_CHANNEL, -1 ); setParameter( XINE_PARAM_SPU_CHANNEL, -1 );
setParameter( XINE_PARAM_AUDIO_CHANNEL_LOGICAL, -1 ); setParameter( XINE_PARAM_AUDIO_CHANNEL_LOGICAL, -1 );
setParameter( XINE_PARAM_VO_ASPECT_RATIO, 0 ); setParameter( XINE_PARAM_VO_ASPECT_RATIO, 0 );
// 100 is the same for both linear and logarithmic volume control setParameter( XINE_PARAM_AUDIO_VOLUME, 100 );
setParameter( XINE_PARAM_AUDIO_AMP_LEVEL, 100 );
#undef setParameter #undef setParameter
videoWindow()->setShown( xine_get_stream_info( m_stream, XINE_STREAM_INFO_HAS_VIDEO ) ); videoWindow()->setShown( xine_get_stream_info( m_stream, XINE_STREAM_INFO_HAS_VIDEO ) );
@ -456,14 +453,10 @@ VideoWindow::posTimeLength( PosTimeLength type ) const
return 0; //--warning return 0; //--warning
} }
uint int
VideoWindow::volume() const VideoWindow::volume() const
{ {
int vol = xine_get_param( m_stream, XINE_PARAM_AUDIO_AMP_LEVEL ); int vol = xine_get_param(m_stream, XINE_PARAM_AUDIO_VOLUME);
if (s_logarithmicVolume)
{
vol = 100 - 100.0 * (pow(10, (100.0 - vol) / 100.0) - 1) / 9.0;
}
if (vol < 0) if (vol < 0)
{ {
vol = 0; vol = 0;
@ -472,7 +465,7 @@ VideoWindow::volume() const
{ {
vol = 100; vol = 100;
} }
return (uint)vol; return vol;
} }
void void
@ -505,7 +498,7 @@ VideoWindow::seek( uint pos )
// xine_play unpauses stream if stream was paused // xine_play unpauses stream if stream was paused
// was broken at 1.0.1 still // was broken at 1.0.1 still
wasPaused = true; wasPaused = true;
xine_set_param( m_stream, XINE_PARAM_AUDIO_AMP_MUTE, 1 ); xine_set_param( m_stream, XINE_PARAM_AUDIO_MUTE, 1 );
break; break;
default: default:
; ;
@ -554,15 +547,10 @@ VideoWindow::seek( uint pos )
xine_osd_hide( m_osd, xine_get_current_vpts( m_stream ) + 180000 ); //2 seconds xine_osd_hide( m_osd, xine_get_current_vpts( m_stream ) + 180000 ); //2 seconds
if (wasPaused) if (wasPaused)
xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ),
xine_set_param( m_stream, XINE_PARAM_AUDIO_AMP_MUTE, 0 );
}
int
VideoWindow::makeVolumeLogarithmic(int volume)
{ {
// We're using a logarithmic function to make the volume ramp more natural. xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE );
return static_cast<uint>( 100 - 100.0 * std::log10( ( 100 - volume ) * 0.09 + 1.0 ) ); xine_set_param( m_stream, XINE_PARAM_AUDIO_MUTE, 0 );
}
} }
void void
@ -589,12 +577,8 @@ VideoWindow::setStreamParameter( int value )
parameter = XINE_PARAM_VO_ASPECT_RATIO; parameter = XINE_PARAM_VO_ASPECT_RATIO;
else if( sender == "volume" ) else if( sender == "volume" )
{ {
parameter = XINE_PARAM_AUDIO_AMP_LEVEL; parameter = XINE_PARAM_AUDIO_VOLUME;
value = 100 - value; // TQt sliders are wrong way round when vertical value = 100 - value; // TQt sliders are wrong way round when vertical
if (s_logarithmicVolume)
{
value = makeVolumeLogarithmic(value);
}
} }
else else
return; return;

@ -39,7 +39,6 @@ namespace Codeine
enum PosTimeLength { Pos, Time, Length }; enum PosTimeLength { Pos, Time, Length };
static VideoWindow *s_instance; static VideoWindow *s_instance;
static bool s_logarithmicVolume;
VideoWindow( const VideoWindow& ); //disable VideoWindow( const VideoWindow& ); //disable
VideoWindow &operator=( const VideoWindow& ); //disable VideoWindow &operator=( const VideoWindow& ); //disable
@ -62,7 +61,7 @@ namespace Codeine
uint time() const { return posTimeLength( Time ); } uint time() const { return posTimeLength( Time ); }
uint length() const { return posTimeLength( Length ); } uint length() const { return posTimeLength( Length ); }
uint volume() const; int volume() const;
const Engine::Scope &scope(); const Engine::Scope &scope();
Engine::State state() const; Engine::State state() const;
@ -121,7 +120,6 @@ namespace Codeine
private: private:
static void destSizeCallBack( void*, int, int, double, int*, int*, double* ); static void destSizeCallBack( void*, int, int, double, int*, int*, double* );
static void frameOutputCallBack( void*, int, int, double, int*, int*, int*, int*, double*, int*, int* ); static void frameOutputCallBack( void*, int, int, double, int*, int*, int*, int*, double*, int*, int* );
static int makeVolumeLogarithmic(int volume);
void initVideo(); void initVideo();
void cleanUpVideo(); void cleanUpVideo();

Loading…
Cancel
Save