Commit 5d5f1713 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout_Volume*: use float rather than integer

parent e90d7934
...@@ -628,7 +628,7 @@ AC_CHECK_FUNC(getopt_long,, [ ...@@ -628,7 +628,7 @@ AC_CHECK_FUNC(getopt_long,, [
AC_SUBST(GNUGETOPT_LIBS) AC_SUBST(GNUGETOPT_LIBS)
AC_CHECK_LIB(m,cos,[ AC_CHECK_LIB(m,cos,[
VLC_ADD_LIBS([adjust wave ripple psychedelic gradient a52tofloat32 dtstofloat32 x264 goom visual panoramix rotate noise grain scene kate flac lua chorus_flanger freetype avcodec avformat access_avio swscale postproc i420_rgb faad twolame equalizer spatializer param_eq samplerate freetype mpc dmo mp4 quicktime qt4 compressor headphone_channel_mixer normvol audiobargraph_a speex mono colorthres extract ball access_imem hotkeys mosaic gaussianblur dbus x26410b hqdn3d anaglyph],[-lm]) VLC_ADD_LIBS([adjust wave ripple psychedelic gradient a52tofloat32 dtstofloat32 x264 goom visual panoramix rotate noise grain scene kate flac lua chorus_flanger freetype avcodec avformat access_avio swscale postproc i420_rgb faad twolame equalizer spatializer param_eq samplerate freetype mpc dmo mp4 quicktime qt4 compressor headphone_channel_mixer normvol audiobargraph_a speex mono colorthres extract ball access_imem hotkeys mosaic gaussianblur dbus x26410b hqdn3d anaglyph oldrc ncurses],[-lm])
LIBM="-lm" LIBM="-lm"
], [ ], [
LIBM="" LIBM=""
......
...@@ -29,11 +29,11 @@ ...@@ -29,11 +29,11 @@
#define AOUT_VOLUME_DEFAULT 256 #define AOUT_VOLUME_DEFAULT 256
#define AOUT_VOLUME_MAX 512 #define AOUT_VOLUME_MAX 512
VLC_API audio_volume_t aout_VolumeGet( vlc_object_t * ); VLC_API float aout_VolumeGet( vlc_object_t * );
#define aout_VolumeGet(a) aout_VolumeGet(VLC_OBJECT(a)) #define aout_VolumeGet(a) aout_VolumeGet(VLC_OBJECT(a))
VLC_API int aout_VolumeSet( vlc_object_t *, audio_volume_t ); VLC_API int aout_VolumeSet( vlc_object_t *, float );
#define aout_VolumeSet(a, b) aout_VolumeSet(VLC_OBJECT(a), b) #define aout_VolumeSet(a, b) aout_VolumeSet(VLC_OBJECT(a), b)
VLC_API int aout_VolumeUp( vlc_object_t *, int, audio_volume_t * ); VLC_API int aout_VolumeUp( vlc_object_t *, int, float * );
#define aout_VolumeUp(a, b, c) aout_VolumeUp(VLC_OBJECT(a), b, c) #define aout_VolumeUp(a, b, c) aout_VolumeUp(VLC_OBJECT(a), b, c)
#define aout_VolumeDown(a, b, c) aout_VolumeUp(a, -(b), c) #define aout_VolumeDown(a, b, c) aout_VolumeUp(a, -(b), c)
VLC_API int aout_MuteToggle( vlc_object_t * ); VLC_API int aout_MuteToggle( vlc_object_t * );
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#endif #endif
#include <assert.h> #include <assert.h>
#include <math.h>
#include <vlc/libvlc.h> #include <vlc/libvlc.h>
#include <vlc/libvlc_media.h> #include <vlc/libvlc_media.h>
...@@ -323,29 +324,21 @@ void libvlc_audio_set_mute( libvlc_media_player_t *mp, int mute ) ...@@ -323,29 +324,21 @@ void libvlc_audio_set_mute( libvlc_media_player_t *mp, int mute )
aout_MuteSet( VLC_OBJECT(mp), mute != 0 ); aout_MuteSet( VLC_OBJECT(mp), mute != 0 );
} }
/*****************************************************************************
* libvlc_audio_get_volume : Get the current volume
*****************************************************************************/
int libvlc_audio_get_volume( libvlc_media_player_t *mp ) int libvlc_audio_get_volume( libvlc_media_player_t *mp )
{ {
unsigned volume = aout_VolumeGet( mp ); float vol = aout_VolumeGet( mp );
return ( vol >= 0.f ) ? lroundf( vol * 100.f ) : -1;
return (volume * 100 + AOUT_VOLUME_DEFAULT / 2) / AOUT_VOLUME_DEFAULT;
} }
/*****************************************************************************
* libvlc_audio_set_volume : Set the current volume
*****************************************************************************/
int libvlc_audio_set_volume( libvlc_media_player_t *mp, int volume ) int libvlc_audio_set_volume( libvlc_media_player_t *mp, int volume )
{ {
volume = (volume * AOUT_VOLUME_DEFAULT + 50) / 100; float vol = volume / 100.f;
if (volume < 0 || volume > AOUT_VOLUME_MAX) if (vol < 0.f)
{ {
libvlc_printerr( "Volume out of range" ); libvlc_printerr( "Volume out of range" );
return -1; return -1;
} }
aout_VolumeSet (mp, volume); aout_VolumeSet (mp, vol);
return 0; return 0;
} }
......
...@@ -167,11 +167,11 @@ DBUS_METHOD( Seek ) ...@@ -167,11 +167,11 @@ DBUS_METHOD( Seek )
static void static void
MarshalVolume( intf_thread_t *p_intf, DBusMessageIter *container ) MarshalVolume( intf_thread_t *p_intf, DBusMessageIter *container )
{ {
audio_volume_t i_vol = aout_VolumeGet( p_intf->p_sys->p_playlist ); float f_vol = aout_VolumeGet( p_intf->p_sys->p_playlist );
if( f_vol < 0.f )
/* A volume of 1.0 represents a sensible maximum, ie: 0dB */ f_vol = 1.f; /* ? */
double d_vol = (double) i_vol / AOUT_VOLUME_DEFAULT;
double d_vol = f_vol;
dbus_message_iter_append_basic( container, DBUS_TYPE_DOUBLE, &d_vol ); dbus_message_iter_append_basic( container, DBUS_TYPE_DOUBLE, &d_vol );
} }
...@@ -204,9 +204,7 @@ DBUS_METHOD( VolumeSet ) ...@@ -204,9 +204,7 @@ DBUS_METHOD( VolumeSet )
d_dbus_vol *= AOUT_VOLUME_DEFAULT; d_dbus_vol *= AOUT_VOLUME_DEFAULT;
if( d_dbus_vol < 0. ) if( d_dbus_vol < 0. )
d_dbus_vol = 0.; d_dbus_vol = 0.;
if( d_dbus_vol > AOUT_VOLUME_MAX ) aout_VolumeSet( PL, d_dbus_vol );
d_dbus_vol = AOUT_VOLUME_MAX;
aout_VolumeSet( PL, lround(d_dbus_vol) );
REPLY_SEND; REPLY_SEND;
} }
......
...@@ -70,7 +70,7 @@ static int SpecialKeyEvent( vlc_object_t *, char const *, ...@@ -70,7 +70,7 @@ static int SpecialKeyEvent( vlc_object_t *, char const *,
static void PlayBookmark( intf_thread_t *, int ); static void PlayBookmark( intf_thread_t *, int );
static void SetBookmark ( intf_thread_t *, int ); static void SetBookmark ( intf_thread_t *, int );
static void DisplayPosition( intf_thread_t *, vout_thread_t *, input_thread_t * ); static void DisplayPosition( intf_thread_t *, vout_thread_t *, input_thread_t * );
static void DisplayVolume ( intf_thread_t *, vout_thread_t *, audio_volume_t ); static void DisplayVolume( intf_thread_t *, vout_thread_t *, float );
static void DisplayRate ( vout_thread_t *, float ); static void DisplayRate ( vout_thread_t *, float );
static float AdjustRateFine( input_thread_t *, const int ); static float AdjustRateFine( input_thread_t *, const int );
static void ClearChannels ( intf_thread_t *, vout_thread_t * ); static void ClearChannels ( intf_thread_t *, vout_thread_t * );
...@@ -186,33 +186,31 @@ static int PutAction( intf_thread_t *p_intf, int i_action ) ...@@ -186,33 +186,31 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
/* Volume and audio actions */ /* Volume and audio actions */
case ACTIONID_VOL_UP: case ACTIONID_VOL_UP:
{ {
audio_volume_t i_newvol; float vol;
aout_VolumeUp( p_playlist, 1, &i_newvol ); if( aout_VolumeUp( p_playlist, 1, &vol ) == 0 )
DisplayVolume( p_intf, p_vout, i_newvol ); DisplayVolume( p_intf, p_vout, vol );
break; break;
} }
case ACTIONID_VOL_DOWN: case ACTIONID_VOL_DOWN:
{ {
audio_volume_t i_newvol; float vol;
aout_VolumeDown( p_playlist, 1, &i_newvol ); if( aout_VolumeDown( p_playlist, 1, &vol ) == 0 )
DisplayVolume( p_intf, p_vout, i_newvol ); DisplayVolume( p_intf, p_vout, vol );
break; break;
} }
case ACTIONID_VOL_MUTE: case ACTIONID_VOL_MUTE:
if( aout_MuteToggle( p_playlist ) == 0 && p_vout != NULL ) if( aout_MuteToggle( p_playlist ) == 0 )
{ {
if( aout_MuteGet( p_playlist ) > 0 ) float vol = aout_VolumeGet( p_playlist );
if( aout_MuteGet( p_playlist ) > 0 || vol == 0.f )
{ {
ClearChannels( p_intf, p_vout ); ClearChannels( p_intf, p_vout );
DisplayIcon( p_vout, OSD_MUTE_ICON ); DisplayIcon( p_vout, OSD_MUTE_ICON );
} }
else else
{ DisplayVolume( p_intf, p_vout, vol );
audio_volume_t i_vol = aout_VolumeGet( p_playlist );
DisplayVolume( p_intf, p_vout, i_vol );
}
} }
break; break;
...@@ -1013,21 +1011,17 @@ static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout, ...@@ -1013,21 +1011,17 @@ static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
} }
static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout, static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
audio_volume_t i_vol ) float vol )
{ {
if( p_vout == NULL ) if( p_vout == NULL )
{
return; return;
}
ClearChannels( p_intf, p_vout ); ClearChannels( p_intf, p_vout );
if( var_GetBool( p_vout, "fullscreen" ) ) if( var_GetBool( p_vout, "fullscreen" ) )
{ vout_OSDSlider( p_vout, VOLUME_WIDGET_CHAN, lround(vol * 100.),
vout_OSDSlider( p_vout, VOLUME_WIDGET_CHAN, OSD_VERT_SLIDER );
i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER ); DisplayMessage( p_vout, VOLUME_TEXT_CHAN, _( "Volume %ld%%" ),
} lround(vol * 100.) );
DisplayMessage( p_vout, VOLUME_TEXT_CHAN, _( "Volume %d%%" ),
i_vol*100/AOUT_VOLUME_DEFAULT );
} }
static void DisplayRate( vout_thread_t *p_vout, float f_rate ) static void DisplayRate( vout_thread_t *p_vout, float f_rate )
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <errno.h> /* ENOMEM */ #include <errno.h> /* ENOMEM */
#include <signal.h> #include <signal.h>
#include <assert.h> #include <assert.h>
#include <math.h>
#include <vlc_interface.h> #include <vlc_interface.h>
#include <vlc_aout_intf.h> #include <vlc_aout_intf.h>
...@@ -1497,8 +1498,9 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd, ...@@ -1497,8 +1498,9 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd,
if ( *newval.psz_string ) if ( *newval.psz_string )
{ {
/* Set. */ /* Set. */
audio_volume_t i_volume = atoi( newval.psz_string ); int i_volume = atoi( newval.psz_string );
if( !aout_VolumeSet( p_playlist, i_volume ) ) if( !aout_VolumeSet( p_playlist,
i_volume / (float)AOUT_VOLUME_DEFAULT ) )
i_error = VLC_SUCCESS; i_error = VLC_SUCCESS;
aout_MuteSet( p_playlist, i_volume == 0 ); aout_MuteSet( p_playlist, i_volume == 0 );
osd_Volume( p_this ); osd_Volume( p_this );
...@@ -1507,8 +1509,8 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd, ...@@ -1507,8 +1509,8 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd,
else else
{ {
/* Get. */ /* Get. */
audio_volume_t i_volume = aout_VolumeGet( p_playlist ); msg_rc( STATUS_CHANGE "( audio volume: %ld )",
msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume ); lroundf( aout_VolumeGet( p_playlist ) * AOUT_VOLUME_DEFAULT ) );
i_error = VLC_SUCCESS; i_error = VLC_SUCCESS;
} }
...@@ -1520,7 +1522,7 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd, ...@@ -1520,7 +1522,7 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
{ {
VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
intf_thread_t *p_intf = (intf_thread_t*)p_this; intf_thread_t *p_intf = (intf_thread_t*)p_this;
audio_volume_t i_volume; float volume;
input_thread_t *p_input = input_thread_t *p_input =
playlist_CurrentInput( p_intf->p_sys->p_playlist ); playlist_CurrentInput( p_intf->p_sys->p_playlist );
int i_nb_steps = atoi(newval.psz_string); int i_nb_steps = atoi(newval.psz_string);
...@@ -1539,11 +1541,13 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd, ...@@ -1539,11 +1541,13 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
if( !strcmp(psz_cmd, "voldown") ) if( !strcmp(psz_cmd, "voldown") )
i_nb_steps *= -1; i_nb_steps *= -1;
if( aout_VolumeUp( p_intf->p_sys->p_playlist, i_nb_steps, &i_volume ) < 0 ) if( aout_VolumeUp( p_intf->p_sys->p_playlist, i_nb_steps, &volume ) < 0 )
i_error = VLC_EGENERIC; i_error = VLC_EGENERIC;
osd_Volume( p_this ); osd_Volume( p_this );
if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume ); if ( !i_error )
msg_rc( STATUS_CHANGE "( audio volume: %ld )",
lroundf( volume * AOUT_VOLUME_DEFAULT ) );
return i_error; return i_error;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#import "intf.h" #import "intf.h"
#import "open.h" #import "open.h"
#import "playlist.h" #import "playlist.h"
#import <math.h>
#import <vlc_playlist.h> #import <vlc_playlist.h>
#import <vlc_input.h> #import <vlc_input.h>
#import <vlc_keys.h> #import <vlc_keys.h>
...@@ -515,9 +516,9 @@ static VLCCoreInteraction *_o_sharedInstance = nil; ...@@ -515,9 +516,9 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
if( !p_intf ) if( !p_intf )
return 0; return 0;
audio_volume_t i_volume = aout_VolumeGet( pl_Get( p_intf ) ); float volume = aout_VolumeGet( pl_Get( p_intf ) );
return (int)i_volume; return lroundf(volume * AOUT_VOLUME_DEFAULT);
} }
- (void)setVolume: (int)i_value - (void)setVolume: (int)i_value
...@@ -526,7 +527,7 @@ static VLCCoreInteraction *_o_sharedInstance = nil; ...@@ -526,7 +527,7 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
if( !p_intf ) if( !p_intf )
return; return;
aout_VolumeSet( pl_Get( p_intf ), i_value ); aout_VolumeSet( pl_Get( p_intf ), i_value / (float)AOUT_VOLUME_DEFAULT );
} }
#pragma mark - #pragma mark -
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#import "controls.h" // TODO: remove me #import "controls.h" // TODO: remove me
#import "playlist.h" #import "playlist.h"
#import "SideBarItem.h" #import "SideBarItem.h"
#import <math.h>
#import <vlc_playlist.h> #import <vlc_playlist.h>
#import <vlc_aout_intf.h> #import <vlc_aout_intf.h>
#import <vlc_url.h> #import <vlc_url.h>
...@@ -1515,10 +1516,8 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -1515,10 +1516,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
- (void)updateVolumeSlider - (void)updateVolumeSlider
{ {
audio_volume_t i_volume;
playlist_t * p_playlist = pl_Get( VLCIntf ); playlist_t * p_playlist = pl_Get( VLCIntf );
int i_volume = lroundf(aout_VolumeGet( p_playlist ) * AOUT_VOLUME_DEFAULT);
i_volume = aout_VolumeGet( p_playlist );
BOOL b_muted = [[VLCCoreInteraction sharedInstance] isMuted]; BOOL b_muted = [[VLCCoreInteraction sharedInstance] isMuted];
if( !b_muted ) if( !b_muted )
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <assert.h> #include <assert.h>
#include <wchar.h> #include <wchar.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <math.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
...@@ -1068,7 +1069,7 @@ static int DrawStatus(intf_thread_t *intf) ...@@ -1068,7 +1069,7 @@ static int DrawStatus(intf_thread_t *intf)
}; };
char buf1[MSTRTIME_MAX_SIZE]; char buf1[MSTRTIME_MAX_SIZE];
char buf2[MSTRTIME_MAX_SIZE]; char buf2[MSTRTIME_MAX_SIZE];
unsigned i_volume; float volume;
case INIT_S: case INIT_S:
case END_S: case END_S:
...@@ -1089,9 +1090,13 @@ static int DrawStatus(intf_thread_t *intf) ...@@ -1089,9 +1090,13 @@ static int DrawStatus(intf_thread_t *intf)
mvnprintw(y++, 0, COLS, _(" Position : %s/%s"), buf1, buf2); mvnprintw(y++, 0, COLS, _(" Position : %s/%s"), buf1, buf2);
i_volume = aout_VolumeGet(p_playlist); volume = aout_VolumeGet(p_playlist);
mvnprintw(y++, 0, COLS, _(" Volume : %u%%"), if (volume >= 0.f)
i_volume*100/AOUT_VOLUME_DEFAULT); mvnprintw(y++, 0, COLS, _(" Volume : %3ld%%"),
lroundf(volume * 100.f));
else
mvnprintw(y++, 0, COLS, _(" Volume : ----"),
lroundf(volume * 100.f));
if (!var_Get(p_input, "title", &val)) { if (!var_Get(p_input, "title", &val)) {
int i_title_count = var_CountChoices(p_input, "title"); int i_title_count = var_CountChoices(p_input, "title");
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "input_manager.hpp" /* Get notification of Volume Change */ #include "input_manager.hpp" /* Get notification of Volume Change */
#include "util/input_slider.hpp" /* SoundSlider */ #include "util/input_slider.hpp" /* SoundSlider */
#include <math.h>
#include <vlc_aout_intf.h> /* Volume functions */ #include <vlc_aout_intf.h> /* Volume functions */
#include <QLabel> #include <QLabel>
...@@ -151,8 +152,7 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume ) ...@@ -151,8 +152,7 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume )
/* Only if volume is set by user action on slider */ /* Only if volume is set by user action on slider */
setMuted( false ); setMuted( false );
playlist_t *p_playlist = pl_Get( p_intf ); playlist_t *p_playlist = pl_Get( p_intf );
int i_res = i_sliderVolume * (AOUT_VOLUME_DEFAULT * 2) / VOLUME_MAX; aout_VolumeSet( p_playlist, i_sliderVolume / 100.f );
aout_VolumeSet( p_playlist, i_res );
refreshLabels(); refreshLabels();
} }
...@@ -160,11 +160,8 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume ) ...@@ -160,11 +160,8 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume )
void SoundWidget::libUpdateVolume() void SoundWidget::libUpdateVolume()
{ {
/* Audio part */ /* Audio part */
audio_volume_t i_volume;
playlist_t *p_playlist = pl_Get( p_intf ); playlist_t *p_playlist = pl_Get( p_intf );
long i_volume = lroundf(aout_VolumeGet( p_playlist ) * 100.f);
i_volume = aout_VolumeGet( p_playlist );
i_volume = (i_volume * VOLUME_MAX ) / (AOUT_VOLUME_DEFAULT * 2);
if ( i_volume - volumeSlider->value() != 0 ) if ( i_volume - volumeSlider->value() != 0 )
{ {
......
...@@ -693,7 +693,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal ) ...@@ -693,7 +693,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
(void)p_obj; (void)newVal; (void)p_obj; (void)newVal;
playlist_t* pPlaylist = getIntf()->p_sys->p_playlist; playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
audio_volume_t volume = aout_VolumeGet( pPlaylist ); float volume = aout_VolumeGet( pPlaylist ) * 100.f;
SET_VOLUME( m_cVarVolume, volume, false ); SET_VOLUME( m_cVarVolume, volume, false );
bool b_is_muted = aout_MuteGet( pPlaylist ) > 0; bool b_is_muted = aout_MuteGet( pPlaylist ) > 0;
SET_BOOL( m_cVarMute, b_is_muted ); SET_BOOL( m_cVarMute, b_is_muted );
...@@ -798,7 +798,7 @@ void VlcProc::init_variables() ...@@ -798,7 +798,7 @@ void VlcProc::init_variables()
SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) ); SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) ); SET_BOOL( m_cVarRepeat, var_GetBool( pPlaylist, "repeat" ) );
audio_volume_t volume = aout_VolumeGet( pPlaylist ); float volume = aout_VolumeGet( pPlaylist ) * 100.f;
SET_VOLUME( m_cVarVolume, volume, false ); SET_VOLUME( m_cVarVolume, volume, false );
bool b_is_muted = aout_MuteGet( pPlaylist ) > 0; bool b_is_muted = aout_MuteGet( pPlaylist ) > 0;
SET_BOOL( m_cVarMute, b_is_muted ); SET_BOOL( m_cVarMute, b_is_muted );
......
...@@ -38,7 +38,7 @@ Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf ) ...@@ -38,7 +38,7 @@ Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf )
m_volumeMax = AOUT_VOLUME_DEFAULT * 2; m_volumeMax = AOUT_VOLUME_DEFAULT * 2;
// Initial value // Initial value
audio_volume_t val = aout_VolumeGet( getIntf()->p_sys->p_playlist ); float val = aout_VolumeGet( getIntf()->p_sys->p_playlist ) * 100.f;
set( val, false ); set( val, false );
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include <math.h>
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
#include <vlc_meta.h> #include <vlc_meta.h>
...@@ -48,34 +49,38 @@ ...@@ -48,34 +49,38 @@
static int vlclua_volume_set( lua_State *L ) static int vlclua_volume_set( lua_State *L )
{ {
playlist_t *p_this = vlclua_get_playlist_internal( L ); playlist_t *p_this = vlclua_get_playlist_internal( L );
int i_volume = VLC_CLIP( luaL_checkint( L, 1 ), 0, AOUT_VOLUME_MAX ); int i_volume = luaL_checkint( L, 1 );
int i_ret = aout_VolumeSet( p_this, i_volume ); if( i_volume < 0 )
i_volume = 0;
int i_ret = aout_VolumeSet( p_this, i_volume/(float)AOUT_VOLUME_DEFAULT );
return vlclua_push_ret( L, i_ret ); return vlclua_push_ret( L, i_ret );
} }
static int vlclua_volume_get( lua_State *L ) static int vlclua_volume_get( lua_State *L )
{ {
playlist_t *p_this = vlclua_get_playlist_internal( L ); playlist_t *p_this = vlclua_get_playlist_internal( L );
audio_volume_t i_volume = aout_VolumeGet( p_this ); long i_volume = lroundf(aout_VolumeGet( p_this ) * AOUT_VOLUME_DEFAULT);
lua_pushnumber( L, i_volume ); lua_pushnumber( L, i_volume );
return 1; return 1;
} }
static int vlclua_volume_up( lua_State *L ) static int vlclua_volume_up( lua_State *L )
{ {
audio_volume_t i_volume;
playlist_t *p_this = vlclua_get_playlist_internal( L ); playlist_t *p_this = vlclua_get_playlist_internal( L );
aout_VolumeUp( p_this, luaL_optint( L, 1, 1 ), &i_volume ); float volume;
lua_pushnumber( L, i_volume );
aout_VolumeUp( p_this, luaL_optint( L, 1, 1 ), &volume );
lua_pushnumber( L, lroundf(volume * AOUT_VOLUME_DEFAULT) );
return 1; return 1;
} }
static int vlclua_volume_down( lua_State *L ) static int vlclua_volume_down( lua_State *L )
{ {
audio_volume_t i_volume;
playlist_t *p_this = vlclua_get_playlist_internal( L ); playlist_t *p_this = vlclua_get_playlist_internal( L );
aout_VolumeDown( p_this, luaL_optint( L, 1, 1 ), &i_volume ); float volume;
lua_pushnumber( L, i_volume );
aout_VolumeDown( p_this, luaL_optint( L, 1, 1 ), &volume );
lua_pushnumber( L, lroundf(volume * AOUT_VOLUME_DEFAULT) );
return 1; return 1;
} }
......
...@@ -127,15 +127,17 @@ static void cancelVolume (vlc_object_t *obj, audio_output_t *aout) ...@@ -127,15 +127,17 @@ static void cancelVolume (vlc_object_t *obj, audio_output_t *aout)
#undef aout_VolumeGet #undef aout_VolumeGet
/** /**
* Gets the volume of the output device (independent of mute). * Gets the volume of the output device (independent of mute).
* \return Current audio volume (0 = silent, 1 = nominal),
* or a strictly negative value if undefined.
*/ */
audio_volume_t aout_VolumeGet (vlc_object_t *obj) float aout_VolumeGet (vlc_object_t *obj)
{ {
audio_output_t *aout; audio_output_t *aout;
float vol; float vol;
prepareVolume (obj, &aout, &vol, NULL); prepareVolume (obj, &aout, &vol, NULL);
cancelVolume (obj, aout); cancelVolume (obj, aout);
return lroundf (vol * AOUT_VOLUME_DEFAULT); return vol;
} }
#undef aout_VolumeSet #undef aout_VolumeSet
...@@ -143,10 +145,9 @@ audio_volume_t aout_VolumeGet (vlc_object_t *obj) ...@@ -143,10 +145,9 @@ audio_volume_t aout_VolumeGet (vlc_object_t *obj)
* Sets the volume of the output device. * Sets the volume of the output device.
* The mute status is not changed. * The mute status is not changed.
*/ */
int aout_VolumeSet (vlc_object_t *obj, audio_volume_t volume) int aout_VolumeSet (vlc_object_t *obj, float vol)
{ {
audio_output_t *aout; audio_output_t *aout;
float vol = volume / (float)AOUT_VOLUME_DEFAULT;
bool mute; bool mute;
prepareVolume (obj, &aout, NULL, &mute); prepareVolume (obj, &aout, NULL, &mute);
...@@ -159,7 +160,7 @@ int aout_VolumeSet (vlc_object_t *obj, audio_volume_t volume) ...@@ -159,7 +160,7 @@ int aout_VolumeSet (vlc_object_t *obj, audio_volume_t volume)
* \param value how much to increase (> 0) or decrease (< 0) the volume * \param value how much to increase (> 0) or decrease (< 0) the volume
* \param volp if non-NULL, will contain contain the resulting volume * \param volp if non-NULL, will contain contain the resulting volume
*/ */
int aout_VolumeUp (vlc_object_t *obj, int value, audio_volume_t *volp) int aout_VolumeUp (vlc_object_t *obj, int value, float *volp)
{ {
audio_output_t *aout; audio_output_t *aout;
int ret; int ret;
...@@ -176,7 +177,7 @@ int aout_VolumeUp (vlc_object_t *obj, int value, audio_volume_t *volp) ...@@ -176,7 +177,7 @@ int aout_VolumeUp (vlc_object_t *obj, int value, audio_volume_t *volp)
vol = AOUT_VOLUME_MAX / AOUT_VOLUME_DEFAULT; vol = AOUT_VOLUME_MAX / AOUT_VOLUME_DEFAULT;
ret = commitVolume (obj, aout, vol, mute); ret = commitVolume (obj, aout, vol, mute);
if (volp != NULL) if (volp != NULL)
*volp = lroundf (vol * AOUT_VOLUME_DEFAULT); *volp = vol;
return ret; return ret;
} }
......
...@@ -91,7 +91,7 @@ static void aout_OutputTimeReport (audio_output_t *aout, mtime_t ideal) ...@@ -91,7 +91,7 @@ static void aout_OutputTimeReport (audio_output_t *aout, mtime_t ideal)
*/ */
static void aout_OutputVolumeReport (audio_output_t *aout, float volume) static void aout_OutputVolumeReport (audio_output_t *aout, float volume)
{ {
audio_volume_t vol = lroundf (volume * (float)AOUT_VOLUME_DEFAULT); long vol = lroundf (volume * (float)AOUT_VOLUME_DEFAULT);
/* We cannot acquire the volume lock as this gets called from the audio /* We cannot acquire the volume lock as this gets called from the audio
* output plug-in (it would cause a lock inversion). */ * output plug-in (it would cause a lock inversion). */
...@@ -365,7 +365,7 @@ static int aout_VolumeSoftSet (audio_output_t *aout, float volume, bool mute) ...@@ -365,7 +365,7 @@ static int aout_VolumeSoftSet (audio_output_t *aout, float volume, bool mute)
*/ */
void aout_VolumeSoftInit (audio_output_t *aout) void aout_VolumeSoftInit (audio_output_t *aout)
{ {
audio_volume_t volume = var_GetInteger (aout, "volume"); long volume = var_GetInteger (aout, "volume");
bool mute = var_GetBool (aout, "mute"); bool mute = var_GetBool (aout, "mute");
aout_assert_locked (aout); aout_assert_locked (aout);
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
/* Needed by str_format_time */ /* Needed by str_format_time */
#include <time.h> #include <time.h>
#include <limits.h> #include <limits.h>
#include <math.h>
/* Needed by str_format_meta */ /* Needed by str_format_meta */
#include <vlc_input.h> #include <vlc_input.h>
...@@ -890,9 +891,15 @@ char *str_format_meta( vlc_object_t *p_object, const char *string ) ...@@ -890,9 +891,15 @@ char *str_format_meta( vlc_object_t *p_object, const char *string )
break; break;
case 'V': case 'V':
{ {
audio_volume_t volume = aout_VolumeGet( p_object ); float vol = aout_VolumeGet( p_object );
snprintf( buf, 10, "%d", volume ); if( vol >= 0. )
{
snprintf( buf, 10, "%ld",
lroundf(vol * AOUT_VOLUME_DEFAULT ) );
INSERT_STRING_NO_FREE( buf ); INSERT_STRING_NO_FREE( buf );
}
else
INSERT_STRING_NO_FREE( "---" );
break; break;
} }
case '_': case '_':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment