Android/linux從usb聲卡獲取音頻(使用libusb庫)----環境,lsusb命令的介紹(一)

Android/linux從usb聲卡獲取音頻(使用libusb庫)---環境,lsusb命令的介紹(一)
       Android/linux從usb聲卡獲取音頻(使用libusb庫)---設備環境的確認(二)
      Android/linux從usb聲卡獲取音頻(使用libusb庫)---libusb庫獲取“純麥”音頻數據(三)
      Android/linux從usb聲卡獲取音頻(使用libusb庫)---libusb庫獲取“純麥”音頻數據,附(四)
      Android/linux從usb聲卡獲取音頻(使用libusb庫)---監聽“純麥”(五)
     環境:ubuntu 18.04  + 小米爐石純麥無線K歌 麥克風 。 libusb庫,android設備。(在android上同樣適用,libsub庫都已經提供好了android的編譯,代碼通用,後續github給上工程)

寫這一篇,主要介紹下個人使用libusb庫讀取外接的usb-mic音頻數據的過程心得,第一篇,先說明一下使用環境和基本的原理。個人當前調試的設備,是一款無線K歌麥克風,小米出品的“純麥”,爐石純麥。其無線接收終端,是插在電視上的一個USB接收設備。這個就是我們調試的對象。無線話筒會將聲音信號發送到usb接收設備,usb接收設備將採樣好的pcm數據通過usb協議傳輸給主機。(具體信號的採樣過程是在話筒端還是在usb接收終端?我覺得是在話筒端採樣然後將數字信號負載到模擬信號發射出去,可以避免直接發送模擬信號導致的變形衰減比如噪音,就像我們以前用“天線”接收器收看電視節目,信號不好滿屏雪花點,和衛星接收器收看電視節目,信號不好只會卡殼花屏。一個道理。具體就不深入論述了,以上屬於個人猜測,屬於通信系同學考慮的問題,與本文主題無關。)
       所以,從usb口通過usb協議,可以讀到我們mic傳輸過來的數據。有些商家宣傳的免驅動,並不是真的不需要驅動,只是linux內核已經集成了這類標準驅動,所以標準的設備是可以直接插用的。個人之前測試的一個usb攝像頭
       只要我們的設備符合這個標準,ok.直接使用。怎麼確認我們的設備被系統真確識別並支持?這些usb熱插拔設備會被自動掛載到usb總線上,用命令:#lsusb 就可以列舉出掛載的usb設備。lsusb這個程序默認的android上也提供,但是看樣子是個精簡版。在ubuntu上可以man手冊查看使用方法。
先接上設備到虛擬機:


lsusb命令查看:

root@can-virtual-machine:/work/test/libusb/libusb-1.0.22/examples# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 015: ID 0c76:1915 JMTek, LLC. 
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

root@can-virtual-machine:/work/test/libusb/libusb-1.0.22/examples# lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
    |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/7p, 12M
        |__ Port 1: Dev 15, If 2, Class=Human Interface Device, Driver=usbhid, 12M
        |__ Port 1: Dev 15, If 0, Class=Audio, Driver=snd-usb-audio, 12M
        |__ Port 1: Dev 15, If 1, Class=Audio, Driver=snd-usb-audio, 12M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
root@can-virtual-machine:/work/test/libusb/libusb-1.0.22/examples# 


man lsusb幫助手冊:以下結合man手冊解釋lsusb命令的使用(android上的lsusb可能是個簡單版,部分選項不支持)

#這個是lsusb的顯示。
root@can-virtual-machine:/work/test/libusb/libusb-1.0.22/examples# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 015: ID 0c76:1915 JMTek, LLC. 
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

man手冊:
lsusb(8)                                                       Linux USB Utilities                                                      

NAME
       lsusb - list USB devices

SYNOPSIS
       lsusb [ options ]

DESCRIPTION # lsusb是一個實用程序,用於顯示有關係統中的USB總線及其連接的設備的信息
       lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.

OPTIONS
       -v, --verbose
              Tells  lsusb  to be verbose and display detailed information about the devices shown.  This includes configuration descriptors for
              the device's current speed.  Class descriptors will be shown, when available, for USB device classes including  hub,  audio,  HID,
              communications, and chipcard.

       -s [[bus]:][devnum] #這個選項可以單獨顯示指定的usb設備的信息,bus是掛載的總線號,devnunm是設備掛載時的序號,比如 lsusb -s 002:015
              Show only devices in specified bus and/or devnum.  Both ID's are given in decimal and may be omitted.

       -d [vendor]:[product] #這個選項和上面-s一樣,但是通過 VID和PID來指定設備,比如lsusb -d 0c76:1915
              Show only devices with the specified vendor and product ID.  Both ID's are given in hexadecimal.

       -D device #這個選項比較有用,他是通過設備節點來指定設備,然後單獨列出這個設備的詳細信息,這些詳細的usb信息是我們後續開發需要用到的,列出的具體信息怎麼查看,參考:https://www.cnblogs.com/Daniel-G/p/3993904.html 
設備節點,usb設備掛載在usb總線上,usb總線上的設備的設備節點,在/dev/bus/usb/**/** 比如 lsusb -D /dev/bus/usb/002/015
              Do  not scan the /dev/bus/usb directory, instead display only information about the device whose device file is given.  The device
              file should be something like /dev/bus/usb/001/001.  This option displays detailed information like the v option; you must be root
              to do this.

       -t     Tells lsusb to dump the physical USB device hierarchy as a tree. This overrides the v option.
       -V, --version #這個選項,會詳細列出所有的 設備的 詳細詳細,標準usb設備信息輸出。
              Print  version information on standard output, then exit successfully.

RETURN VALUE
       If the specified device is not found, a non-zero exit code is returned.

FILES 
       /var/lib/usbutils/usb.ids #這個文件可以看到usb組織已經知道的廠家ID和部分設備。公開的
              A list of all known USB ID's (vendors, products, classes, subclasses and protocols).

usb設備掛載在  /dev/bus/usb/**/**
usb是一個組織,官網:https://www.usb.org/ 廠家要生產一個符合usb標準的usb設備,可以申請一個VID vendor ID . 該網站可以查詢已經”標識”的usb ID http://www.voidcn.com/article/p-tdrrcoup-ho.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章