volume: Clamp volume to PA_VOLUME_MAX

This ensures that we always clamp the volume to PA_VOLUME_MAX. While
this currently has no effect, it will be required for making sure we
don't exceed PA_VOLUME_MAX when its value changes in the future.
This commit is contained in:
Arun Raghavan 2010-10-09 15:38:43 +05:30
parent 1d2ef7923d
commit 49101fc540
7 changed files with 24 additions and 19 deletions

View file

@ -172,7 +172,7 @@ fail:
int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
struct userdata *u;
pa_volume_t volume_limit = PA_VOLUME_NORM*3/2;
pa_volume_t volume_limit = PA_CLAMP_VOLUME(PA_VOLUME_NORM*3/2);
pa_volume_t volume_step = PA_VOLUME_NORM/20;
pa_assert(m);
@ -199,8 +199,8 @@ int pa__init(pa_module*m) {
u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
u->lirc_fd = -1;
u->mute_toggle_save = 0;
u->volume_limit = volume_limit;
u->volume_step = volume_step;
u->volume_limit = PA_CLAMP_VOLUME(volume_limit);
u->volume_step = PA_CLAMP_VOLUME(volume_step);
if ((u->lirc_fd = lirc_init((char*) pa_modargs_get_value(ma, "appname", "pulseaudio"), 1)) < 0) {
pa_log("lirc_init() failed.");

View file

@ -127,7 +127,7 @@ static int load_rules(struct userdata *u, const char *filename) {
*d = 0;
if (pa_atou(v, &k) >= 0) {
volume = (pa_volume_t) k;
volume = (pa_volume_t) PA_CLAMP_VOLUME(k);
} else if (*v == '"') {
char *e;

View file

@ -188,8 +188,8 @@ int pa__init(pa_module*m) {
u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
u->fd = -1;
u->fd_type = 0;
u->volume_limit = volume_limit;
u->volume_step = volume_step;
u->volume_limit = PA_CLAMP_VOLUME(volume_limit);
u->volume_step = PA_CLAMP_VOLUME(volume_step);
if ((u->fd = pa_open_cloexec(pa_modargs_get_value(ma, "device", DEFAULT_DEVICE), O_RDONLY, 0)) < 0) {
pa_log("Failed to open evdev device: %s", pa_cstrerror(errno));

View file

@ -359,8 +359,8 @@ static int sink_get_hw_volume_cb(pa_sink *s) {
if (waveOutGetVolume(u->hwo, &vol) != MMSYSERR_NOERROR)
return -1;
left = (vol & 0xFFFF) * PA_VOLUME_NORM / WAVEOUT_MAX_VOLUME;
right = ((vol >> 16) & 0xFFFF) * PA_VOLUME_NORM / WAVEOUT_MAX_VOLUME;
left = PA_CLAMP_VOLUME((vol & 0xFFFF) * PA_VOLUME_NORM / WAVEOUT_MAX_VOLUME);
right = PA_CLAMP_VOLUME(((vol >> 16) & 0xFFFF) * PA_VOLUME_NORM / WAVEOUT_MAX_VOLUME);
/* Windows supports > 2 channels, except for volume control */
if (s->hw_volume.channels > 2)

View file

@ -271,10 +271,10 @@ int pa_oss_get_volume(int fd, unsigned long mixer, const pa_sample_spec *ss, pa_
pa_cvolume_reset(volume, ss->channels);
volume->values[0] = ((vol & 0xFF) * PA_VOLUME_NORM) / 100;
volume->values[0] = PA_CLAMP_VOLUME(((vol & 0xFF) * PA_VOLUME_NORM) / 100);
if (volume->channels >= 2)
volume->values[1] = (((vol >> 8) & 0xFF) * PA_VOLUME_NORM) / 100;
volume->values[1] = PA_CLAMP_VOLUME((((vol >> 8) & 0xFF) * PA_VOLUME_NORM) / 100);
pa_log_debug("Read mixer settings: %s", pa_cvolume_snprint(cv, sizeof(cv), volume));
return 0;