Bug 252761

Summary: multichannel USB audio device reports only 2 channels via SNDCTL_AUDIOINFO
Product: Base System Reporter: Ed Maste <emaste>
Component: usbAssignee: freebsd-usb (Nobody) <usb>
Status: New ---    
Severity: Affects Only Me CC: hselasky, sascha.folie
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   

Description Ed Maste freebsd_committer freebsd_triage 2021-01-17 01:04:08 UTC
After attaching an 18-in / 18-out device:

ugen0.7: <BEHRINGER X18/XR18> at usbus0
uaudio0 on uhub0
uaudio0: <X18/XR18> on usbus0
uaudio0: Play[0]: 48000 Hz, 18 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record[0]: 48000 Hz, 18 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: MIDI sequencer.
pcm2: <USB audio> on uaudio0
uaudio0: No HID volume keys found.

SNDCTL_AUDIOINFO reports min_channels = 2, max_channels = 2


pcm/dsp.c::dsp_oss_audioinfo() only reports 1 or 2 for min/max it appears:

                        for (i = 0; caps->fmtlist[i]; i++) {
                                fmts |= caps->fmtlist[i];
                                if (AFMT_CHANNEL(caps->fmtlist[i]) > 1) {
                                        minch = (minch == 0) ? 2 : minch;
                                        maxch = 2;
                                } else {
                                        minch = 1;
                                        maxch = (maxch == 0) ? 1 : maxch;
                                }
                        }
Comment 1 Hans Petter Selasky freebsd_committer freebsd_triage 2021-01-18 15:50:53 UTC
FreeBSD OSS use stereo mode by default, unless you set
"dev.pcm.<n>.play.vchanformat" and "dev.pcm.<n>.rec.vchanformat". If there is more than 8 channels, then only bitperfect mode is supported.

Maybe the audioinfo could need an update in that regards. I think we support up to 127 channels, limited by AFMT.

--HPS
Comment 2 Ed Maste freebsd_committer freebsd_triage 2021-01-18 16:18:46 UTC
Indeed, this attaches with bitperfect mode enabled
dev.pcm.2.bitperfect: 1

The 2nd problem I encountered is Audacity's OSS support via PortAudio does not support beyond S16_NE.

I will try (sometime) to have a look at improving audioinfo reporting in this case.
Comment 3 Ed Maste freebsd_committer freebsd_triage 2021-01-20 03:43:53 UTC
I've submitted a few pull requests to PortAudio related to the work that prompted this PR:

https://github.com/PortAudio/portaudio/pull/448
https://github.com/PortAudio/portaudio/pull/449
https://github.com/PortAudio/portaudio/pull/450

with these applied as well as addition of cases for AFMT_S32_NE I can now record from the XR18 in 2 channel mode with bitperfect=1.

Attempting to record in 18 channel mode results in a PA assertion:

21:42:13: Debug: GetBestRate() suggested rate 48000 Hz
21:42:13: Debug: GetBestRate() Returning 48000 Hz
Assertion failed: (firstChannel + channelCount <= bp->inputChannelCount), function PaUtil_SetInterleavedInputChannels, file src/common/pa_process.c, line 482.
Abort trap (core dumped)
Comment 4 Ed Maste freebsd_committer freebsd_triage 2021-01-20 17:48:14 UTC
Looks like PA OSS only tries up to 16 channels:

https://github.com/PortAudio/portaudio/blob/master/src/hostapi/oss/pa_unix_oss.c#L358

    /* Negotiate for the maximum number of channels for this device. PLB20010927
     * Consider up to 16 as the upper number of channels.
     * Variable maxNumChannels should contain the actual upper limit after the call.
     * Thanks to John Lazzaro and Heiko Purnhagen for suggestions.
     */
    maxNumChannels = 0;
    for( numChannels = 1; numChannels <= 16; numChannels++ )
    {
Comment 5 Ed Maste freebsd_committer freebsd_triage 2021-01-20 18:10:37 UTC
That's not directly the cause of the assertion though, the values involved in the assertion expression:
firstChannel=0
channelCount=18
bp->inputChannelCount=2
Comment 6 Hans Petter Selasky freebsd_committer freebsd_triage 2021-05-14 14:18:14 UTC
Any news here?

--HPS
Comment 7 Sascha Folie 2021-12-12 21:05:13 UTC
(In reply to Hans Petter Selasky from comment #1)

I have a 20-in/18-out device and would like to use vchans.
So far I only managed to use the audio interface with virtual_oss.

Is anyone working on changing the limit from 8 to 127?

uaudio0 on uhub4
uaudio0: <Audiofuse Studio> on usbus1
uaudio0: Play[0]: 192000 Hz, 18 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Play[0]: 176400 Hz, 18 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Play[0]: 96000 Hz, 18 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Play[0]: 88200 Hz, 18 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Play[0]: 48000 Hz, 18 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Play[0]: 44100 Hz, 18 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record[0]: 192000 Hz, 20 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record[0]: 176400 Hz, 20 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record[0]: 96000 Hz, 20 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record[0]: 88200 Hz, 20 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record[0]: 48000 Hz, 20 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: Record[0]: 44100 Hz, 20 ch, 32-bit S-LE PCM format, 2x8ms buffer.
uaudio0: MIDI sequencer.
pcm4: <USB audio> on uaudio0
Comment 8 Hans Petter Selasky freebsd_committer freebsd_triage 2021-12-13 08:43:11 UTC
When there are more than 8 channels, vchannels are disabled and bitperfect is enabled. Then you have to use virtual_oss if your application does not support bitperfect.

The vchannel limit of 8 channels was chosen because surround use 8 channels.

--HPS
Comment 9 Hans Petter Selasky freebsd_committer freebsd_triage 2021-12-13 08:47:46 UTC
> Is anyone working on changing the limit from 8 to 127?

Not as I'm aware of.