Solved switching dsp-devices on-the-fly

Hi,
sometimes when listening to some music or watching youtube, i wish to simply switch the audio device where the output gets directed to to another device like for example my USB-based headphones. Unfortunately the only way known to me is to restart the application which emits the audiostream (i configured FreeBSD to make the last attached dsp the default one).
Is there any possible solution besides pulseaudio? Is sndio capable of doing this.
 
Hello. Sometimes, it is enough to set the default unit: systctl hw.snd.default_unit=[number], where [number] is one of the available devices from cat /dev/sndstat

But, some applications, like Firefox, may continue attached to the old unit. There is some hack with pulse audio, if I found my notes, I'll help you later.
 
I've already set hw.snd.default_unit to "0", which will automatically assign hw.snd.default_unit to the newly-attached devices. . This works fine as long as no programm is still using the former default one. Restarting firefox solves the problem with the sound output, but ist not the desired solution because i have to navigate to the specific spot again to continue where i restarted firefox.
Pulseaudio is capable of switching the audio-sink for applications. But i would like to not use pulse audio if possible. As sndio is also placed between sound device and application, i thought it is possible somehow to get this functionality, but i did not find any information in the web concerning my use case.
 
The problem is that different sound devices may support different properties: sample width, maximum sample rate, number of channels and so on. An application opens the device, checks which properties are supported, and then uses it with the values that it thinks are optimal. But these values might not work with a different device that supports different properties. If you want to change the device, the application would have to be notified somehow so it can close the old device, open the new one, and then request the new device's properties before it can resume audio output. Most applications don't have a way to do that, so you have to restart them.

Libraries like Pulse audio insert an additional abstraction layer between application and hardware, converting sound formats if necessary, so the output device can be switched without the application even noticing.
 
Hm, so it seams that my desired behaviour is only possible with PulseAudio. Thanks for your answer.
 
If you really want to, you can ask virtual_oss for a loopback device:
Code:
# virtual_oss -Q 0 -C 2 -c 2 -r 48000 -b 16 -s 1024 -P /dev/null -R /dev/null -w vdsp.wav -l dsp

And then replay the captured sound at whatever device necessary. Something like that:
Code:
% env AUDIODEV=/dev/dsp1 sox /dev/vdsp.wav -d --buffer 192

Feels quite a bit off, though: seems to mess up Audacious, possibly other issues.
 
Back
Top