From 49101fc540aec9a249e97a9f650be38f9f92f5ac Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Sat, 9 Oct 2010 15:38:43 +0530 Subject: 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. --- src/modules/module-lirc.c | 6 +++--- src/modules/module-match.c | 2 +- src/modules/module-mmkbd-evdev.c | 4 ++-- src/modules/module-waveout.c | 4 ++-- src/modules/oss/oss-util.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-lirc.c b/src/modules/module-lirc.c index e9778620..15f3442d 100644 --- a/src/modules/module-lirc.c +++ b/src/modules/module-lirc.c @@ -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."); diff --git a/src/modules/module-match.c b/src/modules/module-match.c index b1693f18..d83c86c3 100644 --- a/src/modules/module-match.c +++ b/src/modules/module-match.c @@ -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; diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c index 193c1f40..4e89aed9 100644 --- a/src/modules/module-mmkbd-evdev.c +++ b/src/modules/module-mmkbd-evdev.c @@ -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)); diff --git a/src/modules/module-waveout.c b/src/modules/module-waveout.c index d1b9f2ff..6fedceb2 100644 --- a/src/modules/module-waveout.c +++ b/src/modules/module-waveout.c @@ -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) diff --git a/src/modules/oss/oss-util.c b/src/modules/oss/oss-util.c index b95023c3..966a6ca1 100644 --- a/src/modules/oss/oss-util.c +++ b/src/modules/oss/oss-util.c @@ -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; -- cgit