From owner-freebsd-multimedia@freebsd.org Wed Dec 26 04:44:21 2018 Return-Path: Delivered-To: freebsd-multimedia@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6AAFA1342D10 for ; Wed, 26 Dec 2018 04:44:21 +0000 (UTC) (envelope-from areilly@bigpond.net.au) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id D5AA395BBE for ; Wed, 26 Dec 2018 04:44:20 +0000 (UTC) (envelope-from areilly@bigpond.net.au) Received: by mailman.ysv.freebsd.org (Postfix) id 99A0C1342D06; Wed, 26 Dec 2018 04:44:20 +0000 (UTC) Delivered-To: multimedia@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7729B1342D05 for ; Wed, 26 Dec 2018 04:44:20 +0000 (UTC) (envelope-from areilly@bigpond.net.au) Received: from nsstlmta12p.bpe.bigpond.com (nsstlmta12p.bpe.bigpond.com [203.38.21.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "", Issuer "Openwave Messaging Inc." (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 8931095BBB for ; Wed, 26 Dec 2018 04:44:15 +0000 (UTC) (envelope-from areilly@bigpond.net.au) Received: from smtp.telstra.com ([10.10.24.4]) by nsstlfep12p-svc.bpe.nexus.telstra.com.au with ESMTP id <20181226044401.TARX22137.nsstlfep12p-svc.bpe.nexus.telstra.com.au@smtp.telstra.com> for ; Wed, 26 Dec 2018 15:44:01 +1100 X-RG-Spam: Unknown X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedtkedrudekgedgjeeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuuffpveftpgfvgffnuffvtfetnecuuegrihhlohhuthemuceftddtnecunecujfgurhephfgtggfukfffvffosehmtdhmrehhtddvnecuhfhrohhmpeetnhgurhgvficutfgvihhllhihuceorghrvghilhhlhiessghighhpohhnugdrnhgvthdrrghuqeenucffohhmrghinhepmhhinhhiughsphdrtghomhenucfkphepuddtuddrudeigedrvdegkedrleegnecurfgrrhgrmhephhgvlhhopegluddtrddtrddtrdduudgnpdhinhgvthepuddtuddrudeigedrvdegkedrleegpdhmrghilhhfrhhomhepoegrrhgvihhllhihsegsihhgphhonhgurdhnvghtrdgruheqpdhrtghpthhtohepoehmuhhlthhimhgvughirgesfhhrvggvsghsugdrohhrgheqnecuvehluhhsthgvrhfuihiivgeptd X-RG-VS-CLASS: clean X-Authentication-Info: Submitted using ID areilly@bigpond.net.au Received: from [10.0.0.11] (101.164.248.94) by smtp.telstra.com (9.0.019.26-1) (authenticated as areilly@bigpond.net.au) id 5BB5487719F243D4 for multimedia@freebsd.org; Wed, 26 Dec 2018 15:44:01 +1100 From: Andrew Reilly Content-Type: multipart/mixed; boundary="Apple-Mail=_F7D93643-DD45-453F-8ACD-B7288588073E" Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Stumped with multi-channel USB sound output Message-Id: <5042D970-166F-4D13-8B0C-BD7216064567@bigpond.net.au> Date: Wed, 26 Dec 2018 15:44:00 +1100 To: multimedia@freebsd.org X-Mailer: Apple Mail (2.3445.102.3) X-Rspamd-Queue-Id: 8931095BBB X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dmarc=pass (policy=none) header.from=bigpond.net.au; spf=pass (mx1.freebsd.org: domain of areilly@bigpond.net.au designates 203.38.21.12 as permitted sender) smtp.mailfrom=areilly@bigpond.net.au X-Spamd-Result: default: False [-0.34 / 15.00]; R_SPF_ALLOW(-0.20)[+ip4:203.38.21.0/24]; MV_CASE(0.50)[]; HAS_ATTACHMENT(0.00)[]; TO_DN_NONE(0.00)[]; FREEMAIL_FROM(0.00)[bigpond.net.au]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[extmail.bpbb.bigpond.com,extmail.bpbb.bigpond.com]; DMARC_POLICY_ALLOW(-0.50)[bigpond.net.au,none]; NEURAL_HAM_SHORT(-0.05)[-0.053,0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[bigpond.net.au]; ASN(0.00)[asn:1221, ipnet:203.36.0.0/14, country:AU]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_IN_DNSWL_LOW(-0.10)[12.21.38.203.list.dnswl.org : 127.0.5.1]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.70)[-0.700,0]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.77)[-0.771,0]; MIME_GOOD(-0.10)[multipart/mixed,text/plain]; PREVIOUSLY_DELIVERED(0.00)[multimedia@freebsd.org]; MIME_BAD_ATTACHMENT(1.60)[c]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE(-0.01)[country: AU(-0.03)]; RCVD_TLS_LAST(0.00)[] X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Dec 2018 04:44:21 -0000 --Apple-Mail=_F7D93643-DD45-453F-8ACD-B7288588073E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi there, I've recently acquired one of these: https://www.minidsp.com/products/usb-audio-interface/u-dac8 to do some = multi-amp speaker crossover hi-fi tweaking. Since my FreeBSD-12.STABLE = file server is quite close to my amplifier, I thought that I'd start by = using it to drive the DAC. It is a USB Audio Class 2.0 device, and as such is recognised seemingly = well by the snd_uaudio driver (loaded by /boot/loader.conf, as it = doesn't seem to be compiled-in): (from dmesg.boot:) uaudio0 on uhub1 uaudio0: on usbus1 uaudio0: Play: 192000 Hz, 8 ch, 32-bit S-LE PCM format, 2x8ms buffer. uaudio0: Play: 176400 Hz, 8 ch, 32-bit S-LE PCM format, 2x8ms buffer. uaudio0: Play: 96000 Hz, 8 ch, 32-bit S-LE PCM format, 2x8ms buffer. uaudio0: Play: 88200 Hz, 8 ch, 32-bit S-LE PCM format, 2x8ms buffer. uaudio0: Play: 48000 Hz, 8 ch, 32-bit S-LE PCM format, 2x8ms buffer. uaudio0: Play: 44100 Hz, 8 ch, 32-bit S-LE PCM format, 2x8ms buffer. uaudio0: No recording. uaudio0: No MIDI sequencer. pcm0: on uaudio0 uaudio0: No HID volume keys found. (The motherboard has a an hdac sound device of course, and on the = off-chance that the sound driver was getting confused about = unsynchronised sample rate domains, I've disabled that in = /boot/device.hints:=20 hint.hdacc.0.disabled=3D"1" That still leaves this output in dmesg: hdac0: mem 0xfe860000-0xfe863fff irq 55 at = device 0.1 on pci10 hdac0: hdac_get_capabilities: Invalid corb size (0) device_attach: hdac0 attach returned 6 hdac0: mem 0xfe700000-0xfe707fff irq 43 at = device 0.3 on pci12 but the only pcm to show up in /dev/sndstat now is pcm0 belonging to the = uaudio device. I tried using device.hints to disable hdac0, at first, but all that did = was re-number it to hdac1, and all of the motherboard pcm devices were = still found.) Anyway, I can't make it produce sensible output under FreeBSD. It = sounds to me as though somewhere a buffer is incorrectly formatted, or = the wrong size. Sound plays at seemingly about the right rate, but = there is distortion that sounds like blocks of null values at a rate of = about 20-30Hz. It doesn't seem to matter whether I write one, two or = eight channels: sounds the same pitch and distortion rate, although with = mono output my test signal plays out both channel 0 and 1. I expect = that is the automatic vchan mixer at work? The DAC works without problems on macOS. The sysctl values for hw.snd are: hw.snd.maxautovchans: 16 hw.snd.default_unit: 0 hw.snd.version: 2009061500/amd64 hw.snd.default_auto: 1 hw.snd.verbose: 2 hw.snd.vpc_mixer_bypass: 1 hw.snd.feeder_rate_quality: 1 hw.snd.feeder_rate_round: 25 hw.snd.feeder_rate_max: 2016000 hw.snd.feeder_rate_min: 1 hw.snd.feeder_rate_polyphase_max: 183040 hw.snd.feeder_rate_presets: 100:8:0.85 100:36:0.92 100:164:0.97 hw.snd.feeder_eq_exact_rate: 0 hw.snd.feeder_eq_presets: = PEQ:16000,0.2500,62,0.2500:-9,9,1.0:44100,48000,88200,96000,176400,192000 hw.snd.basename_clone: 1 hw.snd.compat_linux_mmap: 0 hw.snd.syncdelay: -1 hw.snd.usefrags: 0 hw.snd.vpc_reset: 0 hw.snd.vpc_0db: 45 hw.snd.vpc_autoreset: 1 hw.snd.timeout: 5 hw.snd.latency_profile: 1 hw.snd.latency: 5 hw.snd.report_soft_matrix: 1 hw.snd.report_soft_formats: 1 and for dev.pcm: dev.pcm.0.feedback_rate: 47999 dev.pcm.0.mixer.mute_1.desc:=20 dev.pcm.0.mixer.mute_1.max: 1 dev.pcm.0.mixer.mute_1.min: 0 dev.pcm.0.mixer.mute_1.val: 0 dev.pcm.0.mixer.vol_0.desc:=20 dev.pcm.0.mixer.vol_0.max: 0 dev.pcm.0.mixer.vol_0.min: -32512 dev.pcm.0.mixer.vol_0.val: -11475 dev.pcm.0.bitperfect: 0 dev.pcm.0.buffersize: 0 dev.pcm.0.play.vchanformat: s16le:2.0 dev.pcm.0.play.vchanrate: 48000 dev.pcm.0.play.vchanmode: fixed dev.pcm.0.play.vchans: 1 dev.pcm.0.hwvol_mixer: vol dev.pcm.0.hwvol_step: 5 dev.pcm.0.%parent: uaudio0 dev.pcm.0.%pnpinfo:=20 dev.pcm.0.%location:=20 dev.pcm.0.%driver: pcm dev.pcm.0.%desc: USB audio dev.pcm.%parent:=20 When running squeezelite, compiled to use portaudio (from ports), = /dev/sndstat says: FreeBSD Audio Driver (64bit 2009061500/amd64) Installed devices: pcm0: at ? kld snd_uaudio (1p:1v/0r:0v) default snddev = flags=3D0x200002e3 [pcm0:play:dsp0.p0]: spd 48000, fmt 0x00200010/0x08801000, flags = 0x00002108, 0x00000046 interrupts 543, underruns 0, feed 1084, ready 0 = [b:24576/12288/2|bs:4096/2048/2] channel flags=3D0x2108 {userland} -> feeder_mixer(0x00200010) -> = feeder_format(0x00200010 -> 0x00201000) -> feeder_matrix(2.0 -> 7.1) -> = {hardware} pcm0:play:dsp0.p0[pcm0:virtual:dsp0.vp0]: spd 44100/48000, fmt = 0x00200010, flags 0x1000114c, 0x00000029, pid 9675 (squeezelite) interrupts 0, underruns 0, feed 1072, ready 7232 = [b:0/0/0|bs:8192/2048/4] channel = flags=3D0x1000114c {userland} -> feeder_root(0x00200010) -> = feeder_volume(0x00200010) -> feeder_rate(0x00200010 q:1 44100 -> 48000) = -> {hardware} No devices installed from userspace. I think that is saying (working from the bottom up) that userland is = sending data which is being sample-rate converted using the default = (q:1) sample rate converter to 48kHz, and then feeder_matrix(2.0 -> 7.1) = is probably trying to do the right thing to drive eight output channels? If I run my little test program (attached) to drive all eight channels = directly, it does something much weirder: FreeBSD Audio Driver (64bit 2009061500/amd64) Installed devices: pcm0: at ? kld snd_uaudio (1p:1v/0r:0v) default snddev = flags=3D0x200002e3 [pcm0:play:dsp0.p0]: spd 48000, fmt 0x00200010/0x08801000, flags = 0x00002108, 0x00000046 interrupts 409, underruns 0, feed 816, ready 0 = [b:24576/12288/2|bs:4096/2048/2] channel flags=3D0x2108 {userland} -> feeder_mixer(0x00200010) -> = feeder_format(0x00200010 -> 0x00201000) -> feeder_matrix(2.0 -> 7.1) -> = {hardware} pcm0:play:dsp0.p0[pcm0:virtual:dsp0.vp0]: spd 48000, fmt = 0x08801000/0x00200010, flags 0x1000012c, 0x00000063, pid 9752 (singen) interrupts 0, underruns 0, feed 34680, ready 131072 = [b:0/0/0|bs:131072/4096/32] channel = flags=3D0x1000012c {userland} -> feeder_root(0x08801000) -> = feeder_format(0x08801000 -> 0x08800010) -> feeder_matrix(7.1 -> 2.0) -> = feeder_volume(0x00200010) -> {hardware} No devices installed from userspace. That looks as though my eight channels is being mixed down to two (on = the last line) and then up-mixed to eight (7.1)? I don't want it to do = that. How do I stop it? Also, this hardware is perfectly capable of running at 44100Hz, as shown = in the dmesg output. Is there a way to tell the pcm driver to set the = hardware sample rate, rather than do sample rate conversion in software? Is there any documentation about any of this? The pcm(4) man page says = that there is matrixing support to handle channel routing and up/down = mixing, but it isn't particularly clear about the possibilities. If I sysctl dev.pcm.0.play.vchanformat=3Ds32le:7.1 then sndstat seems = more promising: FreeBSD Audio Driver (64bit 2009061500/amd64) Installed devices: pcm0: at ? kld snd_uaudio (1p:1v/0r:0v) default snddev = flags=3D0x200002e3 [pcm0:play:dsp0.p0]: spd 48000, fmt 0x08801000, flags = 0x00002108, 0x00000004 interrupts 6612, underruns 0, feed 6611, ready 0 = [b:24576/12288/2|bs:32768/16384/2] channel flags=3D0x2108 {userland} -> feeder_mixer(0x08801000) -> {hardware} pcm0:play:dsp0.p0[pcm0:virtual:dsp0.vp0]: spd 48000, fmt = 0x08801000, flags 0x1000012c, 0x00000021, pid 9819 (singen) interrupts 0, underruns 0, feed 6611, ready 131072 = [b:0/0/0|bs:131072/4096/32] channel = flags=3D0x1000012c {userland} -> feeder_root(0x08801000) -> = feeder_volume(0x08801000) -> {hardware} No devices installed from userspace. but the audio output distortion is the same. Despite the distorted = output, sndstat is indicating that there are no underruns, and there are = no kernel messages showing up in the dmesg buffer about pcm = misbehaviour. Setting dev.pcm.0.bitperfect=3D1 doesn't seem to make any difference, = except the feeder_volume() node goes away in the sndstat output: FreeBSD Audio Driver (64bit 2009061500/amd64) Installed devices: pcm0: at ? kld snd_uaudio (1p:1v/0r:0v) default snddev = flags=3D0x200003e3 [pcm0:play:dsp0.p0]: spd 48000, fmt 0x08801000, flags = 0x00002108, 0x00000004 interrupts 359, underruns 0, feed 358, ready 0 = [b:24576/12288/2|bs:32768/16384/2] channel flags=3D0x2108 {userland} -> feeder_mixer(0x08801000) -> {hardware} pcm0:play:dsp0.p0[pcm0:virtual:dsp0.vp0]: spd 48000, fmt = 0x08801000, flags 0x3000012c, 0x00000001, pid 9993 (singen) interrupts 0, underruns 0, feed 358, ready 131072 = [b:0/0/0|bs:131072/4096/32] channel = flags=3D0x3000012c {userland} -> feeder_root(0x08801000) -> {hardware} No devices installed from userspace. Am I going to win, with additional tweaking, do you think? Or will I be = better off setting up a Raspberry Pi or the like, running linux, to = drive it? Where can I find documentation about the mixer/feeder architecture, to = interpret those sndstat outputs? Cheers, Andrew Reilly M: 0409-824-272 areilly@bigpond.net.au --Apple-Mail=_F7D93643-DD45-453F-8ACD-B7288588073E Content-Disposition: attachment; filename=Makefile Content-Type: application/octet-stream; x-unix-mode=0644; name="Makefile" Content-Transfer-Encoding: 7bit CFLAGS= -Wall -Wextra -O2 -ggdb singen: singen.c $(CC) -o singen $(CFLAGS) singen.c -lm --Apple-Mail=_F7D93643-DD45-453F-8ACD-B7288588073E--