Created attachment 202465 [details] proposal patch (switch between /dev/dsp and default_unit /dev/dsp[0-9]*) I have 4 sound devices, device 1 is the default. portaudio hides /dev/dsp1, sysctl hw.snd.basename_clone=0 hides /dev/dsp. Since the default output sink is hidden, no sound can be obtained.
Created attachment 202466 [details] proposal patch (switch the existence of /dev/dsp)
The command for the experiment was made as follows. clang -I/usr/local/include/ /usr/local/share/examples/portaudio/pa_devs.c -L/usr/local/lib -lportaudio
Created attachment 202467 [details] portaudio.diff Hmm, the code seems quite broken indeed. I don't think your patch is quite right/simple enough though. I think we can do what you propose (always add /dev/dsp to the device list first) and simplify the code a lot in the process. We don't really need to care about hw.snd.basename_clone in portaudio. QueryDevice() for /dev/dsp will fail if it does not exist and it will never be added to the device list in the first place. The default device will appear twice (once as /dev/dsp and /dev/dsp1) in the list, but that shouldn't matter much.
Comment on attachment 202466 [details] proposal patch (switch the existence of /dev/dsp) (In reply to Tobias Kortkamp from comment #3) I made it difficult because I thought that #ifdef __FreeBSD__ had meaning. It is better to simply as attachment 202467 [details] if #ifdef __FreeBSD__ is not important. I think the default device should be appeared twice, for example because Audacity stores configuration as following. [AudioIO] RecordingDevice=/dev/dsp1 PlaybackDevice=/dev/dsp1 If hw.snd.basename_clone changes, it will not lose sight of /dev/dsp[0-9]*. In addition, hw.snd.basename_clone is changed by virtual_oss (audio/virtual_oss) when virtual_oss is run with option -d dsp.
A commit references this bug: Author: tobik Date: Fri Mar 1 09:40:25 UTC 2019 New revision: 494248 URL: https://svnweb.freebsd.org/changeset/ports/494248 Log: audio/portaudio: Amend r419598 and always add OSS default device first r419598 tried to solve a problem where when hw.snd.default_unit is set to anything except zero /dev/dsp0 is not available to programs using portaudio since it assumes that /dev/dsp and /dev/dsp0 are the same device. However with that fix, when hw.snd.default_unit=1 and hw.snd.basename_clone=0, portaudio will hide /dev/dsp1 from the device list since it will use /dev/dsp for it instead of /dev/dsp1. However since /dev/dsp is not available, QueryDevice() will fail and /dev/dsp1 will never be added to the device list. Instead of looking up hw.snd.default_unit we can solve this by always trying to add /dev/dsp to the device list first. PR: 236118 Submitted by: Tatsuki Makino <tatsuki_makino@hotmail.com> Changes: head/audio/portaudio/Makefile head/audio/portaudio/files/patch-src_hostapi_oss_pa__unix__oss.c
(In reply to Tatsuki Makino from comment #4) > I think the default device should be appeared twice, for example because > Audacity stores configuration as following. > > [AudioIO] > RecordingDevice=/dev/dsp1 > PlaybackDevice=/dev/dsp1 > > If hw.snd.basename_clone changes, it will not lose sight of /dev/dsp[0-9]*. Aha, that's good to know! I committed the patch. Thanks for this!
Thank you very much.