aout: respect AOUT_VOLUME_MAX in aout_volumeUpdate()

This commit is contained in:
Fatih Uzunoglu 2023-06-20 19:57:41 +03:00 committed by Steve Lhomme
parent 8315605610
commit 4134f7f3ef
2 changed files with 15 additions and 8 deletions

View File

@ -514,7 +514,7 @@ VLC_API float aout_VolumeGet (audio_output_t *);
VLC_API int aout_VolumeSet (audio_output_t *, float);
/**
* Raises the volume.
* Adjusts the volume.
* \param aout the audio output to update the volume for
* \param value how much to increase (> 0) or decrease (< 0) the volume
* \param volp if non-NULL, will contain contain the resulting volume

View File

@ -46,6 +46,16 @@ typedef struct aout_dev
/* Local functions */
static inline float clampf(const float value, const float min, const float max)
{
if (value < min)
return min;
else if (value > max)
return max;
else
return value;
}
static int var_Copy (vlc_object_t *src, const char *name, vlc_value_t prev,
vlc_value_t value, void *data)
{
@ -830,18 +840,15 @@ int aout_VolumeSet (audio_output_t *aout, float vol)
int aout_VolumeUpdate (audio_output_t *aout, int value, float *volp)
{
int ret = -1;
float stepSize = var_InheritFloat (aout, "volume-step") / (float)AOUT_VOLUME_DEFAULT;
float delta = value * stepSize;
const float defaultVolume = (float)AOUT_VOLUME_DEFAULT;
const float stepSize = var_InheritFloat (aout, "volume-step") / defaultVolume;
float vol = aout_VolumeGet (aout);
if (vol >= 0.f)
{
vol += delta;
if (vol < 0.f)
vol = 0.f;
if (vol > 2.f)
vol = 2.f;
vol += (value * stepSize);
vol = (roundf (vol / stepSize)) * stepSize;
vol = clampf(vol, 0.f, AOUT_VOLUME_MAX / defaultVolume);
if (volp != NULL)
*volp = vol;
ret = aout_VolumeSet (aout, vol);