multimedia keys the mixer and virtual_oss

I found my multimedia keys to increase, decrease and mute the volume
stopped working when i switched playback device using the virtual_oss_cmd

using the following command to switch from the default audio device to dsp3

Code:
virtual_oss_cmd /dev/vdsp.ctl -P /dev/dsp3

instead of the using the virtual_oss_cmd to switch playback devices
what you actually want to do is use the mixer command with the -d and -V options

Suppose virtual_oss(8) is running with /dev/vdsp.ctl as its control device,
and pcm1 as the playback device.

Change the default device to pcm3,
and hot-swap to it for playback in virtual_oss(8):

Code:
mixer -d pcm3 -V /dev/vdsp.ctl:play

so in short use the mixer command instead of the virtual_oss_cmd
to make sure you multimedia keys work even if you switch virtual audio devices

notes on setting up virtual oss

install virtual_oss

Code:
sudo pkg install virtual_oss

add cuse_load="YES" loader.conf using sysrc

Code:
sudo sysrc -f /boot/loader.conf cuse_load="YES"

edit your rc.conf

Code:
sudo vi /etc/rc.conf

set dsp1 as the default device and vdsp.ctl as the control device
dsp1 are the headphones on my set up change the device as needed

Code:
virtual_oss_enable="YES"
virtual_oss_configs="dsp"
virtual_oss_dsp="-T /dev/sndstat -S -Q 0 -C 2 -c 2 -r 48000 -b 16 -s 1024 -P /dev/dsp1 -R /dev/null -w vdsp.wav -l dsp -t vdsp.ctl"

edit your sysctl.conf

Code:
sudo vi /etc/sysctl.conf

hw.usb.usbhid.enable=1 - enables multimedia keys on an external usb keyboard
hw.snd.default_unit=1 - sets the default audio device

Code:
# default audio output - headphones
hw.snd.default_unit=1
# use new audio devices automatically
hw.snd.default_auto=1
# dont autoreset vol to default
hw.snd.vpc_autoreset=0
# audio tweaks
hw.snd.latency=0
kern.timecounter.alloweddeviation=0
hw.usb.uaudio.buffer_ms=2
# usb keyboard media keys
hw.usb.usbhid.enable=1


dwl config for media keys

Code:
config.h

Code:
static const char *volumeup[]      = { "/usr/sbin/mixer",   "vol=+5%:+5%",  NULL };
static const char *volumedown[]    = { "/usr/sbin/mixer",   "vol=-5%:-5%",  NULL };
static const char *mutevolume[]    = { "/usr/sbin/mixer",   "vol.mute=^",        NULL };

static const Key keys[] = {
    /* Note that Shift changes certain key codes: c -> C, 2 -> at, etc. */
    /* modifier                  key                 function        argument */
    { 0,                         XKB_KEY_XF86AudioRaiseVolume, spawn, {.v = volumeup   } },
    { 0,                         XKB_KEY_XF86AudioLowerVolume, spawn, {.v = volumedown } },
    { 0,                         XKB_KEY_XF86AudioMute, spawn, {.v = mutevolume } },
 
Back
Top