Solved Change default audio device without restarting applications to take effect

I am trying to change default audio device without restarting applications to take effect, I think that is possible using virtual_oss device but it seems that I can't change default audio device to virtual_oss generated.

My audio devices:
Code:
dmesg |grep pcm
pcm0: <Intel Haswell (HDMI/DP 8ch)> at nid 3 on hdaa0
pcm1: <Realtek ALC292 (Analog 2.0+HP/2.0)> at nid 20,21 and 26 on hdaa1
pcm2: <Realtek ALC292 (Internal Analog Mic)> at nid 18 on hdaa1
pcm3: <USB audio> on uaudio0
I have installed virtual_oss:
pkg install virtual_oss
Enabled it:
sysrc virtual_oss_enable=YES
Configured start options to use default speakers as output:
sysrc virtual_oss_dsp="-T /dev/sndstat -C 2 -c 2 -S -i 8 -r 48000 -b 24 -s 8.0ms -f /dev/dsp1 -d dsp -t dsp.ctl"
Started virtual_oss:
service virtual_oss start
Now I can see a new device: dsp: <Virtual OSS> (play/rec)
Code:
 cat /dev/sndstat 
Installed devices:
pcm0: <Intel Haswell (HDMI/DP 8ch)> (play)
pcm1: <Realtek ALC292 (Analog 2.0+HP/2.0)> (play/rec) default
pcm2: <Realtek ALC292 (Internal Analog Mic)> (rec)
pcm3: <USB audio> (play/rec)
Installed devices from userspace:
dsp: <Virtual OSS> (play/rec)
But I don't know how to make it the default device:
sysctl hw.snd.default_unit=UNIT_NUMBER
If I can use virtual_oss device as default audio device I think that I will be able to change audio output without restarting current apps with the following command:
virtual_oss_cmd /dev/dsp.ctl -f /dev/dsp3

Any advise?

Best regards.
 
  • Thanks
Reactions: mro
The handbook tells to

# sysctl hw.snd.default_unit=<yourdevice>

and this normally has immediate effect, without needing to restart anything.
 
Hello skunk, that takes immediate effect but your running apps like music players or browsers playing youtube videos has to be restarted to output sound through new selected device.

How can I select Virtual OSS device, dsp from the following list?:
Code:
cat /dev/sndstat
Installed devices:
pcm0: <Intel Haswell (HDMI/DP 8ch)> (play)
pcm1: <Realtek ALC292 (Analog 2.0+HP/2.0)> (play/rec) default
pcm2: <Realtek ALC292 (Internal Analog Mic)> (rec)
pcm3: <USB audio> (play/rec)
Installed devices from userspace:
dsp: <Virtual OSS> (play/rec)
Best regards.
 
hw.snd.default_unit merely changes whatever device /dev/dsp points to. If you paid enough attention to virtual_oss, you might have noticed that -d dsp sets hw.snd.basename_clone=0, removes normal /dev/dsp and replaces it with /dev/dsp controlled by virtual_oss, which means it's already the default.
 
shkhln, you are correct, it is not needed to change default audio device using:
sysctl hw.snd.default_unit=<yourdevice>
I can use:
virtual_oss_cmd /dev/dsp.ctl -f /dev/dsp3
And it works like a charm.

In the other hand when I start virtual_oss service I can see:
service virtual_oss restart
Stopping Virtual OSS config dsp ... done
Starting Virtual OSS config dsp ...hw.snd.basename_clone: 0 -> 0
And -d parameter only indicates the device name:
-d name
Create an OSS device by given name.
And nothing more is logged to /var/log/ files.

How it's supposed that I would had to deduce:
If you paid enough attention to virtual_oss, you might have noticed that -d dsp sets hw.snd.basename_clone=0, removes normal /dev/dsp and replaces it with /dev/dsp controlled by virtual_oss, which means it's already the default.
How can I pay attention to virtual_oss? Wich log should I have to read?

Best regards.
 
I have detected that each 16s aproximately I hear some chop/glitch in the sound even configuring virtual_oss with maximum priotity: -i 0
root 14643 0.3 0.1 53148 7224 - S<s 10:40 1:25.45 /usr/local/sbin/virtual_oss -B -D /var/run/virtual_oss/dsp.pid -T /dev/sndstat -C 2 -c 2 -S -i 0 -r 44100 -b 24 -s 16.0ms -f /dev/dsp1 -d dsp -t dsp.ctl
rtprio 14643
rtprio: realtime priority 0
And renicing PID:
renice -10 -p 14643

CPU/RAM seems to be ok while the sound cut happens, no log registered under /var/log files.

Any advice?
 
I think the chop/glitch is related with my wireless headset, not virtual_oss.
Thank you for your help, I close the thread as resolved.
 
  • Like
Reactions: mro
Back
Top