From 4fb369f81515dcede931a666d63b3a0b3e58cf12 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 11 Jan 2001 23:26:16 +0000 Subject: [PATCH] - Move all of the hwvol functions into a mixer_hwvol_* namespace, and make all of the hwvol members of struct snd_mixer live in a hwvol_* namespace. - When changing the mixer device via the hwvol_mixer sysctl, reset the muted state so that a mute operation on a new device won't try to unmute the new device with the old device's saved volume. - When the volume is muted, if a down or up volume request is received, first restore the saved volume level and then adjust it. Reviewed by: cg --- sys/dev/sound/pcm/datatypes.h | 4 ++-- sys/dev/sound/pcm/mixer.c | 26 ++++++++++++++++---------- sys/dev/sound/pcm/mixer.h | 6 +++--- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/sys/dev/sound/pcm/datatypes.h b/sys/dev/sound/pcm/datatypes.h index bf6d73dfecd..8a28162bb6c 100644 --- a/sys/dev/sound/pcm/datatypes.h +++ b/sys/dev/sound/pcm/datatypes.h @@ -40,10 +40,10 @@ struct _snd_mixer { const char *name; void *devinfo; int busy; - int muted; + int hwvol_muted; int hwvol_mixer; int hwvol_step; - u_int32_t mute_level; + u_int32_t hwvol_mute_level; u_int32_t devs; u_int32_t recdevs; u_int32_t recsrc; diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c index c9d4ae8b9e5..a11ab3de4d9 100644 --- a/sys/dev/sound/pcm/mixer.c +++ b/sys/dev/sound/pcm/mixer.c @@ -282,14 +282,16 @@ sysctl_hw_snd_hwvol_mixer(SYSCTL_HANDLER_ARGS) dev = mixer_lookup(devname); if (dev == -1) return EINVAL; - else + else if (dev != m->hwvol_mixer) { m->hwvol_mixer = dev; + m->hwvol_muted = 0; + } } return error; } int -mixer_hwinit(device_t dev) +mixer_hwvol_init(device_t dev) { snddev_info *d; snd_mixer *m; @@ -307,25 +309,25 @@ mixer_hwinit(device_t dev) } void -mixer_hwmute(device_t dev) +mixer_hwvol_mute(device_t dev) { snddev_info *d; snd_mixer *m; d = device_get_softc(dev); m = d->mixer; - if (m->muted) { - m->muted = 0; - mixer_set(m, m->hwvol_mixer, m->mute_level); + if (m->hwvol_muted) { + m->hwvol_muted = 0; + mixer_set(m, m->hwvol_mixer, m->hwvol_mute_level); } else { - m->muted++; - m->mute_level = mixer_get(m, m->hwvol_mixer); + m->hwvol_muted++; + m->hwvol_mute_level = mixer_get(m, m->hwvol_mixer); mixer_set(m, m->hwvol_mixer, 0); } } void -mixer_hwstep(device_t dev, int left_step, int right_step) +mixer_hwvol_step(device_t dev, int left_step, int right_step) { snddev_info *d; snd_mixer *m; @@ -333,7 +335,11 @@ mixer_hwstep(device_t dev, int left_step, int right_step) d = device_get_softc(dev); m = d->mixer; - level = mixer_get(m, m->hwvol_mixer); + if (m->hwvol_muted) { + m->hwvol_muted = 0; + level = m->hwvol_mute_level; + } else + level = mixer_get(m, m->hwvol_mixer); if (level != -1) { left = level & 0xff; right = level >> 8; diff --git a/sys/dev/sound/pcm/mixer.h b/sys/dev/sound/pcm/mixer.h index f7ad35cef26..eeed21191e5 100644 --- a/sys/dev/sound/pcm/mixer.h +++ b/sys/dev/sound/pcm/mixer.h @@ -33,9 +33,9 @@ extern int mixer_ioctl(snddev_info *d, u_long cmd, caddr_t arg); extern int mixer_busy(snd_mixer *m, int busy); extern int mixer_isbusy(snd_mixer *m); -int mixer_hwinit(device_t dev); -void mixer_hwmute(device_t dev); -void mixer_hwstep(device_t dev, int left_step, int right_step); +int mixer_hwvol_init(device_t dev); +void mixer_hwvol_mute(device_t dev); +void mixer_hwvol_step(device_t dev, int left_step, int right_step); extern void change_bits(mixer_tab *t, u_char *regval, int dev, int chn, int newval);