Update 2023-11-14 11:46:23

This commit is contained in:
c0dev0id 2023-11-14 11:46:25 +01:00
parent 6c9a2ff39c
commit 53da307cc5

View File

@ -0,0 +1,59 @@
# OpenBSD sndio and mutiple devices
## Automatic audio device switch
OpenBSD automatically detects the system audio device. But often this is not enough. I want to plug in a USB headset and audio should automatically switch to it.
You can start sndiod with additional `-F` flags, which define additional devices, which are switched to in order when they appear.
```
# sndiod -f rsnd/0 -F rsnd/1 -F rsnd/2 -F rsnd/3
```
You can set these flags permanently with:
```
# rcctl set sndiod flags -f rsnd/0 -F rsnd/1 -F rsnd/2 -F rsnd/3
```
This configuration allows up to 3 additional USB devices to be connected and sndiod will switch to the last one connected.
If you have multiple devices connected and want to switch to a specific one, you can do so with:
```
$ sndioctl server.device=0
$ sndioctl server.device=1
$ sndioctl server.device=2
...
```
## Record from one device, but play back on another...
Let's say I want to connect USB microphone, but I want to to play back sound on another device.
This works by setting the environment variables `AUDIORECDEVICE` and `AUDIOPLAYDEVICE` accordingly.
Example:
```
export AUDIORECDEVICE=snd/1
export AUDIORECDEVICE=snd/0
```
However, sndiod expects every device to play and record. So the above example would work to play on the system, but record on a headset.
If the devices are more limited, the sndio flags need to be more specific, like this:
```
# rcctl set sndiod flags -f rsnd/0 -m play -s play -f rsnd/1 -m rec -s rec
# rcctl restart sndiod
$ export AUDIOPLAYDEVICE=snd/0.play
$ export AUDIORECDEVICE=snd/1.rec
```
This creates a "play" sub device on the first audio device (system audio). And a sub device "rec" on the first USB device. The default is "play,rec", which would not work on my USB microphone. The -m switch describes what the device can do. The -s switch defines the sub device name.
And now... everything works as expected.
```
$ aucat -o test.wav # record from microphone
$ aucat -i test.wav # play on system speaker
```