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,, [
AC_SUBST(GNUGETOPT_LIBS)
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=""
......
......@@ -29,11 +29,11 @@
#define AOUT_VOLUME_DEFAULT 256
#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))
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)
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_VolumeDown(a, b, c) aout_VolumeUp(a, -(b), c)
VLC_API int aout_MuteToggle( vlc_object_t * );
......
......@@ -27,6 +27,7 @@
#endif
#include <assert.h>
#include <math.h>
#include <vlc/libvlc.h>
#include <vlc/libvlc_media.h>
......@@ -323,29 +324,21 @@ void libvlc_audio_set_mute( libvlc_media_player_t *mp, int mute )
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 )
{
unsigned volume = aout_VolumeGet( mp );
return (volume * 100 + AOUT_VOLUME_DEFAULT / 2) / AOUT_VOLUME_DEFAULT;
float vol = aout_VolumeGet( mp );
return ( vol >= 0.f ) ? lroundf( vol * 100.f ) : -1;
}
/*****************************************************************************
* libvlc_audio_set_volume : Set the current volume
*****************************************************************************/
int libvlc_audio_set_volume( libvlc_media_player_t *mp, int volume )
{
volume = (volume * AOUT_VOLUME_DEFAULT + 50) / 100;
if (volume < 0 || volume > AOUT_VOLUME_MAX)
float vol = volume / 100.f;
if (vol < 0.f)
{
libvlc_printerr( "Volume out of range" );
return -1;
}
aout_VolumeSet (mp, volume);
aout_VolumeSet (mp, vol);
return 0;
}
......
......@@ -167,11 +167,11 @@ DBUS_METHOD( Seek )
static void
MarshalVolume( intf_thread_t *p_intf, DBusMessageIter *container )
{
audio_volume_t i_vol = aout_VolumeGet( p_intf->p_sys->p_playlist );
/* A volume of 1.0 represents a sensible maximum, ie: 0dB */
double d_vol = (double) i_vol / AOUT_VOLUME_DEFAULT;
float f_vol = aout_VolumeGet( p_intf->p_sys->p_playlist );
if( f_vol < 0.f )
f_vol = 1.f; /* ? */
double d_vol = f_vol;
dbus_message_iter_append_basic( container, DBUS_TYPE_DOUBLE, &d_vol );
}
......@@ -204,9 +204,7 @@ DBUS_METHOD( VolumeSet )
d_dbus_vol *= AOUT_VOLUME_DEFAULT;
if( d_dbus_vol < 0. )
d_dbus_vol = 0.;
if( d_dbus_vol > AOUT_VOLUME_MAX )
d_dbus_vol = AOUT_VOLUME_MAX;
aout_VolumeSet( PL, lround(d_dbus_vol) );
aout_VolumeSet( PL, d_dbus_vol );
REPLY_SEND;
}
......
......@@ -70,7 +70,7 @@ static int SpecialKeyEvent( vlc_object_t *, char const *,
static void PlayBookmark( 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 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 float AdjustRateFine( input_thread_t *, const int );
static void ClearChannels ( intf_thread_t *, vout_thread_t * );
......@@ -186,33 +186,31 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
/* Volume and audio actions */
case ACTIONID_VOL_UP:
{
audio_volume_t i_newvol;
aout_VolumeUp( p_playlist, 1, &i_newvol );
DisplayVolume( p_intf, p_vout, i_newvol );
float vol;
if( aout_VolumeUp( p_playlist, 1, &vol ) == 0 )
DisplayVolume( p_intf, p_vout, vol );
break;
}
case ACTIONID_VOL_DOWN:
{
audio_volume_t i_newvol;
aout_VolumeDown( p_playlist, 1, &i_newvol );
DisplayVolume( p_intf, p_vout, i_newvol );
float vol;
if( aout_VolumeDown( p_playlist, 1, &vol ) == 0 )
DisplayVolume( p_intf, p_vout, vol );
break;
}
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 );
DisplayIcon( p_vout, OSD_MUTE_ICON );
}
else
{
audio_volume_t i_vol = aout_VolumeGet( p_playlist );
DisplayVolume( p_intf, p_vout, i_vol );
}
DisplayVolume( p_intf, p_vout, vol );
}
break;
......@@ -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,
audio_volume_t i_vol )
float vol )
{
if( p_vout == NULL )
{
return;
}
ClearChannels( p_intf, p_vout );
if( var_GetBool( p_vout, "fullscreen" ) )
{
vout_OSDSlider( p_vout, VOLUME_WIDGET_CHAN,
i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
}
DisplayMessage( p_vout, VOLUME_TEXT_CHAN, _( "Volume %d%%" ),
i_vol*100/AOUT_VOLUME_DEFAULT );
vout_OSDSlider( p_vout, VOLUME_WIDGET_CHAN, lround(vol * 100.),
OSD_VERT_SLIDER );
DisplayMessage( p_vout, VOLUME_TEXT_CHAN, _( "Volume %ld%%" ),
lround(vol * 100.) );
}
static void DisplayRate( vout_thread_t *p_vout, float f_rate )
......
......@@ -36,6 +36,7 @@
#include <errno.h> /* ENOMEM */
#include <signal.h>
#include <assert.h>
#include <math.h>
#include <vlc_interface.h>
#include <vlc_aout_intf.h>
......@@ -1497,8 +1498,9 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd,
if ( *newval.psz_string )
{
/* Set. */
audio_volume_t i_volume = atoi( newval.psz_string );
if( !aout_VolumeSet( p_playlist, i_volume ) )
int i_volume = atoi( newval.psz_string );
if( !aout_VolumeSet( p_playlist,
i_volume / (float)AOUT_VOLUME_DEFAULT ) )
i_error = VLC_SUCCESS;
aout_MuteSet( p_playlist, i_volume == 0 );
osd_Volume( p_this );
......@@ -1507,8 +1509,8 @@ static int Volume( vlc_object_t *p_this, char const *psz_cmd,
else
{
/* Get. */
audio_volume_t i_volume = aout_VolumeGet( p_playlist );
msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
msg_rc( STATUS_CHANGE "( audio volume: %ld )",
lroundf( aout_VolumeGet( p_playlist ) * AOUT_VOLUME_DEFAULT ) );
i_error = VLC_SUCCESS;
}
......@@ -1520,7 +1522,7 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
{
VLC_UNUSED(oldval); VLC_UNUSED(p_data);
intf_thread_t *p_intf = (intf_thread_t*)p_this;
audio_volume_t i_volume;
float volume;
input_thread_t *p_input =
playlist_CurrentInput( p_intf->p_sys->p_playlist );
int i_nb_steps = atoi(newval.psz_string);
......@@ -1539,11 +1541,13 @@ static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
if( !strcmp(psz_cmd, "voldown") )
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;
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;
}
......
......@@ -25,6 +25,7 @@
#import "intf.h"
#import "open.h"
#import "playlist.h"
#import <math.h>
#import <vlc_playlist.h>
#import <vlc_input.h>
#import <vlc_keys.h>
......@@ -515,9 +516,9 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
if( !p_intf )
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
......@@ -526,7 +527,7 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
if( !p_intf )
return;
aout_VolumeSet( pl_Get( p_intf ), i_value );
aout_VolumeSet( pl_Get( p_intf ), i_value / (float)AOUT_VOLUME_DEFAULT );
}
#pragma mark -
......
......@@ -34,6 +34,7 @@
#import "controls.h" // TODO: remove me
#import "playlist.h"
#import "SideBarItem.h"
#import <math.h>
#import <vlc_playlist.h>
#import <vlc_aout_intf.h>
#import <vlc_url.h>
......@@ -1515,10 +1516,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
- (void)updateVolumeSlider
{
audio_volume_t i_volume;
playlist_t * p_playlist = pl_Get( VLCIntf );
i_volume = aout_VolumeGet( p_playlist );
int i_volume = lroundf(aout_VolumeGet( p_playlist ) * AOUT_VOLUME_DEFAULT);
BOOL b_muted = [[VLCCoreInteraction sharedInstance] isMuted];
if( !b_muted )
......
......@@ -39,6 +39,7 @@
#include <assert.h>
#include <wchar.h>
#include <sys/stat.h>
#include <math.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
......@@ -1068,7 +1069,7 @@ static int DrawStatus(intf_thread_t *intf)
};
char buf1[MSTRTIME_MAX_SIZE];
char buf2[MSTRTIME_MAX_SIZE];
unsigned i_volume;
float volume;
case INIT_S:
case END_S:
......@@ -1089,9 +1090,13 @@ static int DrawStatus(intf_thread_t *intf)
mvnprintw(y++, 0, COLS, _(" Position : %s/%s"), buf1, buf2);
i_volume = aout_VolumeGet(p_playlist);
mvnprintw(y++, 0, COLS, _(" Volume : %u%%"),
i_volume*100/AOUT_VOLUME_DEFAULT);
volume = aout_VolumeGet(p_playlist);
if (volume >= 0.f)
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)) {
int i_title_count = var_CountChoices(p_input, "title");
......
......@@ -31,6 +31,7 @@
#include "input_manager.hpp" /* Get notification of Volume Change */
#include "util/input_slider.hpp" /* SoundSlider */
#include <math.h>
#include <vlc_aout_intf.h> /* Volume functions */
#include <QLabel>
......@@ -151,8 +152,7 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume )
/* Only if volume is set by user action on slider */
setMuted( false );
playlist_t *p_playlist = pl_Get( p_intf );
int i_res = i_sliderVolume * (AOUT_VOLUME_DEFAULT * 2) / VOLUME_MAX;
aout_VolumeSet( p_playlist, i_res );
aout_VolumeSet( p_playlist, i_sliderVolume / 100.f );
refreshLabels();
}
......@@ -160,11 +160,8 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume )
void SoundWidget::libUpdateVolume()
{
/* Audio part */
audio_volume_t i_volume;
playlist_t *p_playlist = pl_Get( p_intf );
i_volume = aout_VolumeGet( p_playlist );
i_volume = (i_volume * VOLUME_MAX ) / (AOUT_VOLUME_DEFAULT * 2);
long i_volume = lroundf(aout_VolumeGet( p_playlist ) * 100.f);
if ( i_volume - volumeSlider->value() != 0 )
{
......
......@@ -693,7 +693,7 @@ void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
(void)p_obj; (void)newVal;
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 );
bool b_is_muted = aout_MuteGet( pPlaylist ) > 0;
SET_BOOL( m_cVarMute, b_is_muted );
......@@ -798,7 +798,7 @@ void VlcProc::init_variables()
SET_BOOL( m_cVarLoop, var_GetBool( pPlaylist, "loop" ) );
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 );
bool b_is_muted = aout_MuteGet( pPlaylist ) > 0;
SET_BOOL( m_cVarMute, b_is_muted );
......
......@@ -38,7 +38,7 @@ Volume::Volume( intf_thread_t *pIntf ): VarPercent( pIntf )
m_volumeMax = AOUT_VOLUME_DEFAULT * 2;
// 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 );
}
......
......@@ -33,6 +33,7 @@
# include "config.h"
#endif
#include <math.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_meta.h>
......@@ -48,34 +49,38 @@
static int vlclua_volume_set( lua_State *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_ret = aout_VolumeSet( p_this, i_volume );
int i_volume = luaL_checkint( L, 1 );
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 );
}
static int vlclua_volume_get( lua_State *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 );
return 1;
}
static int vlclua_volume_up( lua_State *L )
{
audio_volume_t i_volume;
playlist_t *p_this = vlclua_get_playlist_internal( L );
aout_VolumeUp( p_this, luaL_optint( L, 1, 1 ), &i_volume );
lua_pushnumber( L, i_volume );
float volume;
aout_VolumeUp( p_this, luaL_optint( L, 1, 1 ), &volume );
lua_pushnumber( L, lroundf(volume * AOUT_VOLUME_DEFAULT) );
return 1;
}
static int vlclua_volume_down( lua_State *L )
{
audio_volume_t i_volume;
playlist_t *p_this = vlclua_get_playlist_internal( L );
aout_VolumeDown( p_this, luaL_optint( L, 1, 1 ), &i_volume );
lua_pushnumber( L, i_volume );
float volume;
aout_VolumeDown( p_this, luaL_optint( L, 1, 1 ), &volume );
lua_pushnumber( L, lroundf(volume * AOUT_VOLUME_DEFAULT) );
return 1;
}
......
......@@ -127,15 +127,17 @@ static void cancelVolume (vlc_object_t *obj, audio_output_t *aout)
#undef aout_VolumeGet
/**
* 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;
float vol;
prepareVolume (obj, &aout, &vol, NULL);
cancelVolume (obj, aout);
return lroundf (vol * AOUT_VOLUME_DEFAULT);
return vol;
}
#undef aout_VolumeSet
......@@ -143,10 +145,9 @@ audio_volume_t aout_VolumeGet (vlc_object_t *obj)
* Sets the volume of the output device.
* 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;
float vol = volume / (float)AOUT_VOLUME_DEFAULT;
bool mute;
prepareVolume (obj, &aout, NULL, &mute);
......@@ -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 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;
int ret;
......@@ -176,7 +177,7 @@ int aout_VolumeUp (vlc_object_t *obj, int value, audio_volume_t *volp)
vol = AOUT_VOLUME_MAX / AOUT_VOLUME_DEFAULT;
ret = commitVolume (obj, aout, vol, mute);
if (volp != NULL)
*volp = lroundf (vol * AOUT_VOLUME_DEFAULT);
*volp = vol;
return ret;
}
......
......@@ -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)
{
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
* 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)
*/
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");
aout_assert_locked (aout);
......
......@@ -37,6 +37,7 @@
/* Needed by str_format_time */
#include <time.h>
#include <limits.h>
#include <math.h>
/* Needed by str_format_meta */
#include <vlc_input.h>
......@@ -889,12 +890,18 @@ char *str_format_meta( vlc_object_t *p_object, const char *string )
}
break;
case 'V':
{
float vol = aout_VolumeGet( p_object );
if( vol >= 0. )
{
audio_volume_t volume = aout_VolumeGet( p_object );
snprintf( buf, 10, "%d", volume );
snprintf( buf, 10, "%ld",
lroundf(vol * AOUT_VOLUME_DEFAULT ) );
INSERT_STRING_NO_FREE( buf );
break;
}
else
INSERT_STRING_NO_FREE( "---" );
break;
}
case '_':
*(dst+d) = '\n';
d++;
......
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