I am trying to write an application in C++ that
- read samples from the microphones (looking at using ALSA from portaudio)
- if samples > threshold, then get the DOA (using libusb and reading the registers)
It seems that I cannot do both? If I read registers with libusb, and automatically detach/attach the kernel driver, then I can no longer see the mic array 2.0 in the list of devices using arecord -l
Is there some way to use both together, or alternatively can I read the samples directly via libusb? When I look at the libusb list of interfaces, I can see it has 5 interfaces, are these to access the 4 microphones directly?
I have simplied my program so it does the bare basics to test:
After reboot, I can see the respeaker device
</s><i>
</i>>arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: ArrayUAC10 [ReSpeaker 4 Mic Array (UAC1.0)], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
<e>
My code does the following
- Initialises libusc
</s><i>
</i>libusb_context *ctx = NULL;
int resp = libusb_init(&ctx);
<e>
- Opens the device
</s><i>
</i>respeaker= libusb_open_device_with_vid_pid(NULL, RESPEAKER_V2_MIC_ARRAY_VENDOR_ID, RESPEAKER_V2_MIC_ARRAY_PRODUCT_ID);
<e>
where
</s><i>
</i>#define RESPEAKER_V2_MIC_ARRAY_VENDOR_ID 10374
#define RESPEAKER_V2_MIC_ARRAY_PRODUCT_ID 24
<e>
- sets auto detach for the kernel driver
</s><i>
</i>int resp=libusb_set_auto_detach_kernel_driver(respeaker,1);
<e>
- Claims the interface
</s><i>
</i>int rp = libusb_claim_interface(respeaker, 0);
<e>
- Releases the interface (this should reattach the kernel driver)
</s><i>
</i>int r = libusb_release_interface(respeaker, 0);
<e>
- Closes the device
</s><i>
</i>libusb_close (respeaker);
<e>
- Closes the context
</s><i>
</i>libusb_exit(ctx);
<e>
After my program runs I can no longer see the device
</s><i>
</i>> arecord -l
**** List of CAPTURE Hardware Devices ****
<e>
There are no errors reported.
[code]
[timestamp] [threadID] facility level [function call]
[ 0.022655] [00000739] libusb: debug [libusb_get_device_list]
[ 0.023049] [00000739] libusb: debug [libusb_get_device_descriptor]
[ 0.023151] [00000739] libusb: debug [libusb_open] open 1.4
[ 0.023303] [00000739] libusb: debug [usbi_add_pollfd] add fd 10 events 4
[ 0.023403] [00000739] libusb: debug [libusb_kernel_driver_active] interface 0
[ 0.023577] [00000739] libusb: debug [libusb_claim_interface] interface 0
[ 0.024912] [00000739] libusb: debug [libusb_release_interface] interface 0
[ 0.028316] [00000739] libusb: debug [libusb_close]
[ 0.028647] [00000739] libusb: debug [usbi_remove_pollfd] remove fd 10
[ 0.029306] [00000739] libusb: debug [libusb_exit]
[ 0.029588] [00000739] libusb: debug [libusb_exit] destroying default context
[/code]
I have also tried manually detaching the kernel driver before I claim the interface and manually attaching the kernel driver after I release the interface, but it does not seem to make any difference
I note that when I release the interface, I can see the following transactions over the usb bus
</s><i>
</i>b0e82400 1861717967 S Ci:1:004:0 s 80 06 0303 0409 00ff 255 <
b0e82400 1861718384 C Ci:1:004:0 0 62 = 3e035200 65005300 70006500 61006b00 65007200 20003400 20004d00 69006300
b0e82400 1861718430 S Ci:1:004:0 s 80 06 0301 0409 00ff 255 <
b0e82400 1861718752 C Ci:1:004:0 0 12 = 0c035300 45004500 45004400
<e>
I am not sure what this is actually doing?
Edit: A SET_INTERFACE control request will be sent to the device, resetting interface state to the first alternate setting.
Can anyone help me debug why I cannot see the device after executing my program? I want to be able to read the registers for angle of arrival, and also capture samples via portaudio or some other ALSA based driver.
OR
IS there another way I can achieve this? for example, could I read the samples via libusb? What is the API to do that?
What are each of the interfaces doing for this device?
</s><i>
</i>> usb-devices
T: Bus=01 Lev=03 Prnt=03 Port=01 Cnt=02 Dev#= 4 Spd=12 MxCh= 0
D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=2886 ProdID=0018 Rev=02.00
S: Manufacturer=SEEED
S: Product=ReSpeaker 4 Mic Array (UAC1.0)
C: #Ifs= 5 Cfg#= 1 Atr=80 MxPwr=500mA
I: If#=0x0 Alt= 0 #EPs= 0 Cls=01(audio) Sub=01 Prot=00 Driver=snd-usb-audio
I: If#=0x1 Alt= 0 #EPs= 0 Cls=01(audio) Sub=02 Prot=00 Driver=snd-usb-audio
I: If#=0x2 Alt= 0 #EPs= 0 Cls=01(audio) Sub=02 Prot=00 Driver=snd-usb-audio
I: If#=0x3 Alt= 0 #EPs= 0 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none)
I: If#=0x4 Alt= 0 #EPs= 0 Cls=fe(app. ) Sub=01 Prot=01 Driver=(none)
<e>