better ALSA volume steps, using rounding up rather than normal float to

2004-02-29  Bastien Nocera  <hadess@hadess.net>

	* actions/acme-volume-alsa.c: (acme_volume_alsa_get_volume),
	(acme_volume_alsa_set_volume): better ALSA volume steps, using
	rounding up rather than normal float to int casting
	(Closes: #124741)
This commit is contained in:
Bastien Nocera 2004-02-29 23:40:17 +00:00 committed by Bastien Nocera
parent 32625b2992
commit d6b98e4435
2 changed files with 23 additions and 13 deletions

View file

@ -1,3 +1,10 @@
2004-02-29 Bastien Nocera <hadess@hadess.net>
* actions/acme-volume-alsa.c: (acme_volume_alsa_get_volume),
(acme_volume_alsa_set_volume): better ALSA volume steps, using
rounding up rather than normal float to int casting
(Closes: #124741)
2004-02-25 Bastien Nocera <hadess@hadess.net>
* actions/Makefile.am:

View file

@ -36,6 +36,8 @@
#define D(x...)
#endif
#define ROUND(x) ((x - (int)x > 0.5) ? x+1 : x)
struct AcmeVolumeAlsaPrivate
{
gboolean use_pcm;
@ -50,7 +52,6 @@ static GObjectClass *parent_class = NULL;
static int acme_volume_alsa_get_volume (AcmeVolume *self);
static void acme_volume_alsa_set_volume (AcmeVolume *self, int val);
static gboolean acme_volume_alsa_mixer_check (AcmeVolumeAlsa *self, int fd);
static void
acme_volume_alsa_finalize (GObject *object)
@ -68,12 +69,6 @@ acme_volume_alsa_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static int
acme_volume_alsa_vol_check (AcmeVolumeAlsa *self, int volume)
{
return CLAMP (volume, self->_priv->pmin, self->_priv->pmax);
}
static void
acme_volume_alsa_set_use_pcm (AcmeVolume *vol, gboolean val)
{
@ -134,27 +129,35 @@ acme_volume_alsa_get_volume (AcmeVolume *vol)
AcmeVolumeAlsa *self = (AcmeVolumeAlsa *) vol;
long lval, rval;
int tmp;
float alsa_vol;
snd_mixer_selem_get_playback_volume(self->_priv->elem,
SND_MIXER_SCHN_FRONT_LEFT, &lval);
snd_mixer_selem_get_playback_volume(self->_priv->elem,
SND_MIXER_SCHN_FRONT_RIGHT, &rval);
tmp = acme_volume_alsa_vol_check (self, (int) (lval + rval) / 2);
return (tmp * 100 / self->_priv->pmax);
alsa_vol = (lval + rval) / 2;
alsa_vol = alsa_vol * 100 / (self->_priv->pmax - self->_priv->pmin);
tmp = ROUND (alsa_vol);
return tmp;
}
static void
acme_volume_alsa_set_volume (AcmeVolume *vol, int val)
{
AcmeVolumeAlsa *self = (AcmeVolumeAlsa *) vol;
float volume;
int tmp;
volume = (float) val / 100 * (self->_priv->pmax - self->_priv->pmin);
volume = CLAMP (volume, self->_priv->pmin, self->_priv->pmax);
tmp = ROUND (volume);
val = (long) acme_volume_alsa_vol_check (self,
val * self->_priv->pmax / 100);
snd_mixer_selem_set_playback_volume(self->_priv->elem,
SND_MIXER_SCHN_FRONT_LEFT, val);
SND_MIXER_SCHN_FRONT_LEFT, tmp);
snd_mixer_selem_set_playback_volume(self->_priv->elem,
SND_MIXER_SCHN_FRONT_RIGHT, val);
SND_MIXER_SCHN_FRONT_RIGHT, tmp);
}
static void