Subject: kern/18986: cannot record with my usb audio
To: None <gnats-bugs@gnats.netbsd.org>
From: None <oshimaya@sc.starcat.ne.jp>
List: netbsd-bugs
Date: 11/08/2002 21:58:24
>Number:         18986
>Category:       kern
>Synopsis:       cannot record with my usb audio
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 08 21:59:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Yasushi Oshima
>Release:        NetBSD 1.6K
>Organization:
>Environment:
NetBSD muscat 1.6K NetBSD 1.6K (MUSCAT) #71: Sat Nov  9 00:29:26 JST 2002     oshima@muscat:/usr/src/sys/arch/i386/compile/MUSCAT i386

>Description:
I have a USB speaker which has a microphone input connecter.
Its name is TRSPK-SMS
( http://www.torica.com/products/torica-original/slimspk/ ; 
this page is written by Japanese ),
It uses Avance Logic ALU100 Controler chip.
and it supports only 48kHz sampling rate.

It works fine with audioplay(1), but it doesn't work with audiorecord(1).

The dmesg said when attach this :
 uaudio0 at uhub0 port 1 configuration 1 interface 0: Avance Logic Inc USB Audio Multimidia, rev 1.10/1.01, addr 2
 uaudio0: ignored input endpoint of type adaptive
 uaudio0: ignored input endpoint of type adaptive
 uaudio0: ignored input endpoint of type adaptive
 uaudio0: ignored input endpoint of type adaptive
 uaudio0: audio rev 1.00
 audio1 at uaudio0: full duplex, independent
 uhidev0 at uhub0 port 1 configuration 1 interface 3
 uhidev0: Avance Logic Inc USB Audio Multimidia, rev 1.10/1.01, addr 2, iclass 3/0
 uhid0 at uhidev0: input=5, output=0, feature=0

The result of usbdevs -v :
# usbdevs -v
Controller /dev/usb0:
addr 1: full speed, self powered, config 1, UHCI root hub(0x0000), VIA Technologie(0x1106), rev 1.00
 port 1 addr 2: full speed, self powered, config 1, USB Audio Multimidia(0x0100), Avance Logic Inc(0x0680), rev 1.01
 port 2 powered

And when using audiorecord(1) :

% audiorecord -d /dev/sound1 -c 1 -P 16 -s 48000 -e slinear rec.data
audiorecord: failed to open /dev/sound1: Permission denied

I added UQ_AU_INP_ASYNC flag into sys/dev/usb/usb_quirks.c, then
the ignore message disappeared.

However, audiorecord still says:

% audiorecord -d /dev/sound1 -c 1 -P 16 -s 48000 -e slinear rec.data
audiorecord: failed to open /dev/sound1: Invalid argument

>How-To-Repeat:
attach the this device to usb port
and execute audiorecord(1).

% audiorecord -d /dev/sound1 -c 1 -P 16 -s 48000 -e slinear rec.data

>Fix:
I changed uaudio_match_alt_sub() in uaudio.c.
In the case of single-rate only device, I think UA_SAMP_LO(a1d)
and UA_SAMP_HI(a1d) have the same value, Original code does not
match in this case.

Note: It works on uhci only. 

Index: uaudio.c
===================================================================
RCS file: /export/cvsroot/syssrc/sys/dev/usb/uaudio.c,v
retrieving revision 1.61
diff -u -r1.61 uaudio.c 
--- uaudio.c    2002/10/06 10:01:08 1.61
+++ uaudio.c    2002/11/09 03:45:29
@@ -2253,7 +2253,7 @@
        if (a1d->bSamFreqType == UA_SAMP_CONTNUOUS) {
            DPRINTFN(2,("uaudio_match_alt_sub: cont %d-%d\n",
                    UA_SAMP_LO(a1d), UA_SAMP_HI(a1d)));
-           if (UA_SAMP_LO(a1d) < rate && rate < UA_SAMP_HI(a1d))
+           if (UA_SAMP_LO(a1d) <= rate && rate <= UA_SAMP_HI(a1d))
                return i;
        } else { 
            for (j = 0; j < a1d->bSamFreqType; j++) {

Now audiorecord works fine, the audiofile made from audiorecord is
playable with audioplay well.

For support this device,
 Note:
    It includes fix typo (ADVANCELOGIC -> AVANCELOGIC),
    I don't know whether the name of this product (AVANCELOGIC_USBAUDIO)
    is good.

Index: usbdevs
===================================================================
RCS file: /export/cvsroot/syssrc/sys/dev/usb/usbdevs,v
retrieving revision 1.280
diff -u -r1.280 usbdevs
--- usbdevs     2002/11/05 12:13:40     1.280
+++ usbdevs     2002/11/08 12:14:13
@@ -214,7 +214,7 @@
 vendor ACARD           0x0678  ACARD Technology
 vendor PROLIFIC                0x067b  Prolific Technology
 vendor SIEMENS         0x067c  Siemens
-vendor ADVANCELOGIC    0x0680  Avance Logic
+vendor AVANCELOGIC     0x0680  Avance Logic
 vendor HAGIWARA                0x0693  Hagiwara Sys-Com
 vendor MINOLTA         0x0686  Minolta
 vendor CTX             0x0698  Chuntex
@@ -480,6 +480,9 @@

 /* Audio-Technica products */
 product AUDIOTECHNICA ATCHA4USB        0x0009  ATC-HA4USB USB headphone
+
+/* Avance Logic products */
+product AVANCELOGIC USBAUDIO           0x0100  USB Audio Speaker

 /* Avision products */
 product AVISION 1200U          0x0268  1200U scanner
Index: usb_quirks.c
===================================================================
RCS file: /export/cvsroot/syssrc/sys/dev/usb/usb_quirks.c,v
retrieving revision 1.41
diff -u -r1.41 usb_quirks.c
--- usb_quirks.c        2002/08/26 21:34:28     1.41
+++ usb_quirks.c        2002/11/08 12:20:13
@@ -84,6 +84,8 @@
  { USB_VENDOR_TELEX, USB_PRODUCT_TELEX_MIC1,       0x009, { UQ_AU_NO_FRAC }},
  { USB_VENDOR_SILICONPORTALS, USB_PRODUCT_SILICONPORTALS_YAPPHONE,
                                                    0x100, { UQ_AU_INP_ASYNC }},
+ { USB_VENDOR_AVANCELOGIC, USB_PRODUCT_AVANCELOGIC_USBAUDIO,
+                                                   0x101, { UQ_AU_INP_ASYNC }},
  { USB_VENDOR_NEODIO, USB_PRODUCT_NEODIO_ND5010,    0x100, { UQ_NO_STRINGS }},
  /* XXX These should have a revision number, but I don't know what they are. */
  { USB_VENDOR_HP, USB_PRODUCT_HP_895C,             ANY,   { UQ_BROKEN_BIDIR }},

>Release-Note:
>Audit-Trail:
>Unformatted: