uaudio diff to test

2009-10-10 Thread Jacob Meuser
maybe you've seen such a line in your dmesg after plugging in USB
audio devices:

uaudio0: ignored input endpoint of type adaptive
or
uaudio0: ignored output endpoint of type async

these input/adaptive and output/async endpoints need external help to
synchronize them, or more accurately, to keep their data rate as
constant as possible.  in the USB specification literature, the
synchronization method is referred to as feedback (USB 2.0 Spec.,
Section 5.2.14.2).  usually, it is the responsibility of the driver
to facilitate this feedback, but uaudio(4) does not do this yet, and
that is why you may see the above messages in your dmesg.

however, it is possible that the device is providing the synchronization
on it's own.  consider the following specification excerpts:

from USB Audio Specification 1.0, Section 3.7.2 AudioStreaming Interface:
  [...] Each AudioStreaming interface can have at most one isochronous
  data endpoint.  [...]  In some cases, the isochronous data endpoint
  is accompanied by an associated isochronous synch endpoint for
  synchronisation purposes.  The isochronous data endpoint is required
  to be the first endpoint in the AudioStreaming interface.  The synch
  endpoint always follows its associated data endpoint.

from USB 2.0 Specification, Section 5.12.4.3 Implicit Feedback
  In some cases, implementing a separate explicit feedback endpoint
  can be avoided.  If a device implements a group of isochronous data
  endpoints that are closely related and if:
* All the endpoints in the group are synchronized (i.e. use
  sample clocks that are derived from a common master clock)
* The group contains one or more isochronous data endpoints in one
  direction that normally would need explicit feedback
* The group contains at least one isochronous data endpoint in the
  opposite direction
  Under these circumstances, the device may elect not to implement
  a separate isochronous explicit feedback endpoint.  Instead, feedback
  information can be derived from the data endpoint in the opposite
  direction by observing its data rate.


I have two different audio devices that have input/async endpoints
in their AudioStreaming interface.  these devices should require a
synchronisation endpoint, as the first excerpt says.  however, they
do not provide any such endpoint.  both these audio devices do
provide both recording and playback capabilities (endpoints in both
directions), and as with most audio devices, both playback and
recording very likely use the same clock source.

so, it seems likely to me that these devices are using implicit
feedback and don't really need anything special from the driver.
the patch below allows input/adaptive and output/async endpoints
that have no corresponding synch endpoint to be used.

this lets me record with:

uaudio0 at uhub1 port 2 configuration 1 interface 0 Logitech Logitech USB 
Headset rev 1.10/10.12 addr 2
uaudio0: audio rev 1.00, 6 mixer controls
audio1 at uaudio0

and

uaudio0 at uhub1 port 2 configuration 1 interface 0 Ten X Technology, Inc. USB 
 AUDIO rev 1.10/1.0b addr 2
uaudio0: audio rev 1.00, 4 mixer controls
audio1 at uaudio0
(though this thing still has other issues)


Linux (well, ALSA) does the same thing, their comment is, check the
number of EP, since some devices have broken descriptors which fool us.
if it has only one EP, assume it as adaptive-out or async-in.

please test with any and all USB audio devices.

-- 
jake...@sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org

Index: uaudio.c
===
RCS file: /cvs/src/sys/dev/usb/uaudio.c,v
retrieving revision 1.61
diff -u -p uaudio.c
--- uaudio.c21 Nov 2008 17:55:02 -  1.61
+++ uaudio.c10 Oct 2009 14:48:30 -
@@ -1555,21 +1555,27 @@ uaudio_process_as(struct uaudio_softc *sc, const char 
 
/* We can't handle endpoints that need a sync pipe yet. */
sync = FALSE;
-   if (dir == UE_DIR_IN  type == UE_ISO_ADAPT) {
-   sync = TRUE;
+   /* If there's only one endpoint, then the device is implementing
+* implicit feedback (USB Specification 2.0, Section 5.12.4.3),
+* and we don't have to configure a sync pipe.
+*/
+   if (id-bNumEndpoints  1) {
+   if (dir == UE_DIR_IN  type == UE_ISO_ADAPT) {
+   sync = TRUE;
 #ifndef UAUDIO_MULTIPLE_ENDPOINTS
-   printf(%s: ignored input endpoint of type adaptive\n,
-  sc-sc_dev.dv_xname);
-   return (USBD_NORMAL_COMPLETION);
+   printf(%s: ignored input endpoint of type adaptive\n,
+  sc-sc_dev.dv_xname);
+   return (USBD_NORMAL_COMPLETION);
 #endif
-   }
-   if (dir != UE_DIR_IN  type == UE_ISO_ASYNC) {
-   sync = TRUE;
+   }
+   if (dir != UE_DIR_IN  type == UE_ISO_ASYNC) {
+   

Re: uaudio diff to test

2009-10-10 Thread Thomas Pfaff
On Sat, 10 Oct 2009 15:28:33 +
Jacob Meuser jake...@sdf.lonestar.org wrote:
 
 please test with any and all USB audio devices.
 

Works for me.

OpenBSD 4.6-current (GENERIC.MP) #31: Sat Oct 10 18:41:10 CEST 2009
tpf...@ws.tp76.info:/usr/src/sys/arch/amd64/compile/GENERIC.MP
[...]

After the patch, I can also record from the device.

Before:

uaudio1 at uhub2 port 1 configuration 1 interface 0 Logitech Logitech USB 
Headset rev 1.10/10.13 addr 2
uaudio1: ignored input endpoint of type adaptive
uaudio1: audio rev 1.00, 6 mixer controls
audio2 at uaudio1

After:

uaudio1 at uhub2 port 1 configuration 1 interface 0 Logitech Logitech USB 
Headset rev 1.10/10.13 addr 2
uaudio1: audio rev 1.00, 6 mixer controls
audio2 at uaudio1


$ audioctl
name=USB audio
version=
config=uaudio
encodings=ulinear:8*,mulaw:8*,alaw:8*,slinear:8*,slinear_le:16,ulinear_le:16*,slinear_be:16*,ulinear_be:16*
properties=full_duplex,independent
full_duplex=0
fullduplex=0
blocksize=400
hiwat=163
lowat=122
output_muted=0
monitor_gain=0
mode=
play.rate=8000
play.channels=1
play.precision=8
play.encoding=mulaw
play.gain=127
play.balance=32
play.port=0x0
play.avail_ports=0x0
play.seek=0
play.samples=0
play.eof=0
play.pause=0
play.error=0
play.waiting=0
play.open=0
play.active=0
play.buffer_size=65536
play.block_size=400
play.errors=0
record.rate=8000
record.channels=1
record.precision=8
record.encoding=mulaw
record.gain=127
record.balance=32
record.port=0x0
record.avail_ports=0x0
record.seek=0
record.samples=0
record.eof=0
record.pause=0
record.error=0
record.waiting=0
record.open=0
record.active=0
record.buffer_size=65536
record.block_size=400
record.errors=0

$ mixerctl -v
outputs.spkr.mute=off  [ off on ]
outputs.spkr=121,121 volume
record.mic.mute=off  [ off on ]
record.mic=255 volume
inputs.mic.mute=on  [ off on ]
inputs.mic=0 volume

$ dmesg
OpenBSD 4.6-current (GENERIC.MP) #32: Sat Oct 10 21:24:34 CEST 2009
tpf...@ws.tp76.info:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 3152609280 (3006MB)
avail mem = 3066208256 (2924MB)
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.4 @ 0xf06b0 (76 entries)
bios0: vendor American Megatrends Inc. version 1704 date 11/27/2007
bios0: ASUSTeK Computer INC. P5B-E
acpi0 at bios0: rev 2
acpi0: tables DSDT FACP APIC MCFG OEMB HPET
acpi0: wakeup devices P0P2(S4) P0P1(S4) UAR1(S4) PS2K(S4) PS2M(S4) EUSB(S4) 
USBE(S4) P0P4(S4) P0P5(S4) P0P6(S4) P0P7(S4) P0P8(S4) P0P9(S4) USB0(S4) 
USB1(S4) USB2(S4) USB3(S4) USB4(S4) USB5(S4)
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM)2 CPU 6400 @ 2.13GHz, 2562.37 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,SBF,SSE3,MWAIT,DS-CPL,VMX,EST,TM2,CX16,xTPR,NXE,LONG
cpu0: 2MB 64b/line 8-way L2 cache
cpu0: apic clock running at 269MHz
cpu1 at mainbus0: apid 1 (application processor)
cpu1: Intel(R) Core(TM)2 CPU 6400 @ 2.13GHz, 2156.39 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,SBF,SSE3,MWAIT,DS-CPL,VMX,EST,TM2,CX16,xTPR,NXE,LONG
cpu1: 2MB 64b/line 8-way L2 cache
ioapic0 at mainbus0: apid 2 pa 0xfec0, version 20, 24 pins
acpihpet0 at acpi0: 14318179 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus 1 (P0P2)
acpiprt2 at acpi0: bus 5 (P0P1)
acpiprt3 at acpi0: bus 4 (P0P4)
acpiprt4 at acpi0: bus -1 (P0P5)
acpiprt5 at acpi0: bus -1 (P0P6)
acpiprt6 at acpi0: bus 3 (P0P7)
acpiprt7 at acpi0: bus 2 (P0P8)
acpicpu0 at acpi0: PSS
acpicpu1 at acpi0: PSS
aibs at acpi0 not configured
acpibtn0 at acpi0: PWRB
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 Intel 82G965 Host rev 0x02
ppb0 at pci0 dev 1 function 0 Intel 82G965 PCIE rev 0x02: apic 2 int 16 (irq 
11)
pci1 at ppb0 bus 1
vga1 at pci1 dev 0 function 0 NVIDIA GeForce 7600 GT rev 0xa1
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
uhci0 at pci0 dev 26 function 0 Intel 82801H USB rev 0x02: apic 2 int 16 (irq 
11)
uhci1 at pci0 dev 26 function 1 Intel 82801H USB rev 0x02: apic 2 int 17 (irq 
5)
ehci0 at pci0 dev 26 function 7 Intel 82801H USB rev 0x02: apic 2 int 18 (irq 
15)
usb0 at ehci0: USB revision 2.0
uhub0 at usb0 Intel EHCI root hub rev 2.00/1.00 addr 1
azalia0 at pci0 dev 27 function 0 Intel 82801H HD Audio rev 0x02: apic 2 int 
22 (irq 3)
azalia0: codecs: Analog Devices AD1988A
audio0 at azalia0
ppb1 at pci0 dev 28 function 0 Intel 82801H PCIE rev 0x02: apic 2 int 16 (irq 
11)
pci2 at ppb1 bus 4
ppb2 at pci0 dev 28 function 3 Intel 82801H PCIE rev 0x02: apic 2 int 19 (irq 
10)
pci3 at ppb2 bus 3
age0 at pci3 dev 0 function 0 Attansic Technology L1 rev 0xb0: apic 2 int 19 
(irq 10), address 00:18:f3:9d:7d:04
atphy0 at age0 phy 0: F1 10/100/1000 PHY, rev. 5
ppb3 at pci0 dev 28 function 4 Intel 82801H PCIE rev 0x02: apic 2 int 16 (irq 
11)
pci4 at ppb3 bus 2