simple mixer: fix calculation of control range

When calculating the value range of a control, the variables cannot be
initialized with zero because this would prevent the minimum from having
a value above zero or the maximum from having a value below zero.
This commit is contained in:
Clemens Ladisch 2007-11-12 08:50:08 +01:00
parent 15e936e277
commit 7b51f62732

View file

@ -37,6 +37,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#include <limits.h>
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include "mixer_simple.h" #include "mixer_simple.h"
@ -672,9 +673,11 @@ static int simple_update(snd_mixer_elem_t *melem)
caps = 0; caps = 0;
pchannels = 0; pchannels = 0;
pmin = pmax = 0; pmin = LONG_MAX;
pmax = LONG_MIN;
cchannels = 0; cchannels = 0;
cmin = cmax = 0; cmin = LONG_MAX;
cmax = LONG_MIN;
assert(snd_mixer_elem_get_type(melem) == SND_MIXER_ELEM_SIMPLE); assert(snd_mixer_elem_get_type(melem) == SND_MIXER_ELEM_SIMPLE);
simple = snd_mixer_elem_get_private(melem); simple = snd_mixer_elem_get_private(melem);
name = snd_mixer_selem_get_name(melem); name = snd_mixer_selem_get_name(melem);
@ -868,13 +871,13 @@ static int simple_update(snd_mixer_elem_t *melem)
simple->selem.caps = caps; simple->selem.caps = caps;
simple->str[SM_PLAY].channels = pchannels; simple->str[SM_PLAY].channels = pchannels;
if (!simple->str[SM_PLAY].range) { if (!simple->str[SM_PLAY].range) {
simple->str[SM_PLAY].min = pmin; simple->str[SM_PLAY].min = pmin != LONG_MAX ? pmin : 0;
simple->str[SM_PLAY].max = pmax; simple->str[SM_PLAY].max = pmax != LONG_MIN ? pmax : 0;
} }
simple->str[SM_CAPT].channels = cchannels; simple->str[SM_CAPT].channels = cchannels;
if (!simple->str[SM_CAPT].range) { if (!simple->str[SM_CAPT].range) {
simple->str[SM_CAPT].min = cmin; simple->str[SM_CAPT].min = cmin != LONG_MAX ? cmin : 0;
simple->str[SM_CAPT].max = cmax; simple->str[SM_CAPT].max = cmax != LONG_MIN ? cmax : 0;
} }
return 0; return 0;
} }