Android 如何使用libusb捕获音频?

Android 如何使用libusb捕获音频?,android,audio,record,capture,libusb,Android,Audio,Record,Capture,Libusb,我知道已经有一些问题与我的问题相似,但它们都是老问题,对我没有帮助。 我对libusb非常陌生,但我已经到了可以使用libusb_设备_手柄的地步。 问题是我不知道下一步是什么。 我的程序的一部分是从我的调频收音机棒中捕获音频。这个棒通过usb发送音频,还有一个接口来改变频率等等 有了windows,棍子就可以被识别为音频输入设备,我也能听到。我的程序应该在android 4.2及以上版本上运行,但我想测试我的应用程序的智能手机不支持usb音频输入设备,因此我想让它与libusb一起工作 Ubu

我知道已经有一些问题与我的问题相似,但它们都是老问题,对我没有帮助。 我对libusb非常陌生,但我已经到了可以使用libusb_设备_手柄的地步。 问题是我不知道下一步是什么。 我的程序的一部分是从我的调频收音机棒中捕获音频。这个棒通过usb发送音频,还有一个接口来改变频率等等

有了windows,棍子就可以被识别为音频输入设备,我也能听到。我的程序应该在android 4.2及以上版本上运行,但我想测试我的应用程序的智能手机不支持usb音频输入设备,因此我想让它与libusb一起工作

Ubuntu上的libusb-v命令如下所示:

Bus 002 Device 007: ID 10c4:818a Cygnal Integrated Products, Inc. Silicon Labs FM Radio Reference Design
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x10c4 Cygnal Integrated Products, Inc.
  idProduct          0x818a Silicon Labs FM Radio Reference Design
  bcdDevice            1.00
  iManufacturer           1 SILICON LABORATORIES INC.
  iProduct                2 FM Radio
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          145
    bNumInterfaces          3
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      1 Control Device
      bInterfaceProtocol      0 
      iInterface              0 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength           43
        bInCollection           1
        baInterfaceNr( 0)       1
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             1
        wTerminalType      0x0710 Radio Receiver
        bAssocTerminal          0
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0 
        iTerminal               0 
      AudioControl Interface Descriptor:
        bLength                13
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                 2
        bSourceID               1
        bControlSize            2
        bmaControls( 0)      0x01
        bmaControls( 0)      0x00
          Mute Control
        bmaControls( 1)      0x00
        bmaControls( 1)      0x00
        bmaControls( 2)      0x00
        bmaControls( 2)      0x00
        iFeature                0 
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             3
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bSourceID               2
        iTerminal               0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0 
      iInterface              0 
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink           3
        bDelay                  0 frames
        wFormatTag              1 PCM
      AudioStreaming Interface Descriptor:
        bLength                11
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             2
        bSubframeSize           2
        bBitResolution         16
        bSamFreqType            1 Discrete
        tSamFreq[ 0]        96000
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            5
          Transfer Type            Isochronous
          Synch Type               Asynchronous
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress           0
        AudioControl Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x00
          bLockDelayUnits         2 Decoded PCM samples
          wLockDelay              0 Decoded PCM samples
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     203
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval              10
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
Device Status:     0x0000
  (Bus Powered)
如果有帮助的话,这个无线电棒的源代码是开源的,可以下载

有人能告诉我在libusb_open2之后我要做什么来捕获音频并将其写入文件吗

2014年8月28日编辑:
所以,我现在可以从我的音频棒中获取数据,但我认为有问题。 我分配10个libusb_传输对象,每个传输10个iso数据包。 回调函数将被调用,我检查了libusb_iso_packet_描述符对象的实际_长度。数据包大小为512,但实际_长度介于380和382之间。 为了检查数据是否正确,我还停止了第一次和最后一次回调之间的时间。如果停止传输,libusb_iso_数据包描述符->长度的总和太大,而libusb_iso_数据包描述符->实际长度的总和太低

谢谢
Thomas

由于这是一款USBAudio设备,我相信您应该能够使用音频API打开音频流-从那里您可以将您的示例打包到一个文件中,我没有使用Android audio,但在Windows上使用过,我就是这样做的。谢谢您的回答。问题是android不提供音频API。附带的API只能访问默认的扬声器和麦克风。哦-我没有意识到,我以为它是受支持的。此时,您应该只引用。祝你好运。如果数据的实际长度低于你要求的长度,我想没关系。这可能是因为数据包大小不同于libusb-1.0api文档中的iso数据包大小。请尝试从数据缓冲区中提取
actual_length
给定的字节数。