android - libusb - How to select an alternate setting of a usb-soundcard for stereo recording? -
i have usb sound card has following setup , allows stereo recording 48000hz 2 channels 16 bit, i'm trying set way:
usbconfiguration[mid=1,mname=null, mattributes=160, mmaxpower=50, minterfaces=[ usbinterface[mid=0,malternatesetting=0,mname=null,mclass=1,msubclass=1,mprotocol=0, mendpoints=[] usbinterface[mid=1,malternatesetting=0,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[] usbinterface[mid=1,malternatesetting=1,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[usbendpoint[maddress=4,mattributes=9,mmaxpacketsize=384,minterval=1]] usbinterface[mid=1,malternatesetting=2,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[usbendpoint[maddress=4,mattributes=9,mmaxpacketsize=576,minterval=1]] usbinterface[mid=1,malternatesetting=3,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[usbendpoint[maddress=4,mattributes=9,mmaxpacketsize=192,minterval=1]] usbinterface[mid=2,malternatesetting=0,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[] usbinterface[mid=2,malternatesetting=1,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[usbendpoint[maddress=138,mattributes=5,mmaxpacketsize=196,minterval=1]] usbinterface[mid=2,malternatesetting=2,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[usbendpoint[maddress=138,mattributes=5,mmaxpacketsize=294,minterval=1]] usbinterface[mid=2,malternatesetting=3,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[usbendpoint[maddress=138,mattributes=5,mmaxpacketsize=388,minterval=1]] usbinterface[mid=2,malternatesetting=4,mname=null,mclass=1,msubclass=2,mprotocol=0, mendpoints=[usbendpoint[maddress=138,mattributes=5,mmaxpacketsize=582,minterval=1]] usbinterface[mid=3,malternatesetting=0,mname=null,mclass=3,msubclass=0,mprotocol=0, mendpoints=[usbendpoint[maddress=130,mattributes=3,mmaxpacketsize=16,minterval=16] ] ]
i'm trying select , use incoming interface alternate setting stereo input , same thing interface stereo output. input, i've tried natively following code:
int androidusbaudioio_start(int samplerate, int buffersize, void *callback, void *clientdata) { int rc = -1; if (androidusbaudioio == null) { androidusbaudioio = (androidusbaudioiointernals *) malloc(sizeof(androidusbaudioiointernals)); } androidusbaudioio->samplerate = samplerate; androidusbaudioio->buffersize = buffersize; androidusbaudioio->callback = (audiousbprocessingcallback *) callback; androidusbaudioio->clientdata = clientdata; androidusbaudioio->marustream = 0; androidusbaudioio->issetup = 0; androidusbaudioio->isplaying = 0; rc = libusb_init(null); if (rc < 0) { } androidusbaudioio->devicehandle = libusb_open_device_with_vid_pid(null, vid, pid); if (!androidusbaudioio->devicehandle) { rc = -1; goto out; } rc = libusb_reset_device(androidusbaudioio->devicehandle); if (rc < 0) { goto out; } rc = libusb_set_configuration(androidusbaudioio->devicehandle, 1); if (rc < 0) { } rc = libusb_kernel_driver_active(androidusbaudioio->devicehandle, iface_num); if (rc == 1) { rc = libusb_detach_kernel_driver(androidusbaudioio->devicehandle, iface_num); if (rc < 0) { goto out; } } rc = libusb_claim_interface(androidusbaudioio->devicehandle, iface_num); if (rc < 0) { goto out; } rc = libusb_set_interface_alt_setting(androidusbaudioio->devicehandle, 1, 2); if (rc < 0) { printf("libusb_claim_interface: %s.\n", libusb_error_name(rc)); goto out; } ...
i'm getting following error @ when setting alternate interface:
fatal signal 11 (sigsegv) @ 0x0000001d (code=1), thread 10303
and tried java following code upon receiving permission use device:
usbdeviceconnection musbdevconn = musbmanager.opendevice(maudiodevice); int mreqtype = 0x01; // int mrequest = 0x0b; // set_interface usb spec constant int mvalue = 0x02; // alt settings int mindex = 0x01; // interface nr byte[] mbuffer = null; int mlength = 0; int mtimout = 1000; musbdevconn.controltransfer(usbconstants.usb_dir_out | mreqtype, mrequest, mvalue, mindex, mbuffer, mlength, mtimout);
i'm getting following error:
error (status 6: **unknown**)
what missing?
i think highly unusual libusb_set_interface_alt_setting call cause sigsegv. expect either prior call cause this, or sigsegv indirect effect of call. is, call changes alternate setting, starts transfer of audio data. if buffers, other data structures or callback not setup correctly sigsegv may result.
in situation, put more debug messages in code, including in library , callback try narrow down last thing before crash.
if code working "mono" device, have @ has changed in move "stereo". perhaps data-packet size (buffers) needs larger.
as far java version concerned, error 6 may related fact don't seem detaching kernel drivers or claiming interface before trying change alternate setting.
in past found necessary detach kernel drivers each , every interface including hid interfaces free allocated bus bandwidth before starting audio.
finally, if free version of usbeffects (android app) works device, can connect adb phone via wi-fi , run app device connected see debug messages tell if requesttype, request etc parameters correct hardware.
Comments
Post a Comment