Android4.0 声卡配置-高通msm8916移植

一个正常的UAC设备插入Android 7.0是默认打开UAC配置的,打印的log如下:

[ 2367.490491] usb 3-3.2: new full-speed USB device number 9 using xhci_hcd
[ 2367.580010] usb 3-3.2: New USB device found, idVendor=0d8c, idProduct=0132
[ 2367.580018] usb 3-3.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2367.580023] usb 3-3.2: Product: USB PnP Audio Device
[ 2367.580027] usb 3-3.2: Manufacturer: C-Media Electronics Inc.
[ 2367.581679] input: C-Media Electronics Inc. USB PnP Audio Device as /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.2/0003:0D8C:0132.0004/input/input18
[ 2367.581999] hid-generic 0003:0D8C:0132.0004: input,hidraw3: USB HID v1.11 Device [C-Media Electronics Inc. USB PnP Audio Device] on usb-0000:00:14.0-3.2/input2
[ 2367.913280] usbcore: registered new interface driver snd-usb-audio

而Android4.0是没有默认打开,是需要进行相应的配置的;这里可以看到其驱动程序为snd-usb-audio,依据这个关键词在内核中查找到如下内容:

1 root@ubuntu:/home/lh/work/git/ML16/kernel# grep "registered new interface driver" ./ -rn
2 ./drivers/usb/core/driver.c:914:        pr_info("%s: registered new interface driver %s\n",

需要在 /kernel/arch/arm/configs目录下增加msm8916_defconfig和msm8916-perf_defconfig配置;

在AndroidBoard.mk就已经定义了我们kernel配置文件的属性:

CONFIG_SND_USB_AUDIO=y就行了,因为sound/usb/中的makefile包含了:

在sound/usb/card.c

1 static struct usb_driver usb_audio_driver = {
2     .name =     "snd-usb-audio",
3     .probe =    usb_audio_probe,
4     .disconnect =   usb_audio_disconnect,
5     .suspend =  usb_audio_suspend,
6     .resume =   usb_audio_resume,
7     .id_table = usb_audio_ids,
8     .supports_autosuspend = 1,
9 };

根据probe方法snd_usb_audio_probe调用了snd_usb_apply_boot_quirksnd_card_register,查到了:

 1 static int usb_audio_probe(struct usb_interface *intf,
 2                const struct usb_device_id *id)
 3 {
 4     struct snd_usb_audio *chip;
 5     chip = snd_usb_audio_probe(interface_to_usbdev(intf), intf, id);
 6     if (chip) {
 7         usb_set_intfdata(intf, chip);
 8         return 0;
 9     } else
10         return -EIO;
11 }
12 
13 
14 // linux-3.4.y/sound/usb/quirks.c
15 int snd_usb_apply_boot_quirk(struct usb_device *dev,
16                  struct usb_interface *intf,
17                  const struct snd_usb_audio_quirk *quirk)
18 {
19     u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
20             le16_to_cpu(dev->descriptor.idProduct));
21 
22     switch (id) {
23     case USB_ID(0x041e, 0x3000):
24         /* SB Extigy needs special boot-up sequence */
25         /* if more models come, this will go to the quirk list. */
26         return snd_usb_extigy_boot_quirk(dev, intf);
27 
28     case USB_ID(0x041e, 0x3020):
29         /* SB Audigy 2 NX needs its own boot-up magic, too */
30         return snd_usb_audigy2nx_boot_quirk(dev);
31 
32     case USB_ID(0x10f5, 0x0200):
33         /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
34         return snd_usb_cm106_boot_quirk(dev);
35 
36     case USB_ID(0x0d8c, 0x0102):
37         /* C-Media CM6206 / CM106-Like Sound Device */
38     case USB_ID(0x0ccd, 0x00b1): /* Terratec Aureon 7.1 USB */
39         return snd_usb_cm6206_boot_quirk(dev);
40 
41     case USB_ID(0x133e, 0x0815):
42         /* Access Music VirusTI Desktop */
43         return snd_usb_accessmusic_boot_quirk(dev);
44 
45     case USB_ID(0x17cc, 0x1000): /* Komplete Audio 6 */
46     case USB_ID(0x17cc, 0x1010): /* Traktor Audio 6 */
47     case USB_ID(0x17cc, 0x1020): /* Traktor Audio 10 */
48         return snd_usb_nativeinstruments_boot_quirk(dev);
49     case USB_ID(0x0763, 0x2012):  /* M-Audio Fast Track Pro USB */
50         return snd_usb_fasttrackpro_boot_quirk(dev);
51     }
52 
53     return 0;
54 }

snd_usb_audio_probe:

  1 /*
  2  * probe the active usb device
  3  *
  4  * note that this can be called multiple times per a device, when it
  5  * includes multiple audio control interfaces.
  6  *
  7  * thus we check the usb device pointer and creates the card instance
  8  * only at the first time.  the successive calls of this function will
  9  * append the pcm interface to the corresponding card.
 10  */
 11 static struct snd_usb_audio *
 12 snd_usb_audio_probe(struct usb_device *dev,
 13             struct usb_interface *intf,
 14             const struct usb_device_id *usb_id)
 15 {
 16     const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info;
 17     int i, err;
 18     struct snd_usb_audio *chip;
 19     struct usb_host_interface *alts;
 20     int ifnum;
 21     u32 id;
 22 
 23     alts = &intf->altsetting[0];
 24     ifnum = get_iface_desc(alts)->bInterfaceNumber;
 25     id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
 26             le16_to_cpu(dev->descriptor.idProduct));
 27     if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
 28         goto __err_val;
 29 
 30     if (snd_usb_apply_boot_quirk(dev, intf, quirk) < 0)
 31         goto __err_val;
 32 
 33     /*
 34      * found a config.  now register to ALSA
 35      */
 36 
 37     /* check whether it's already registered */
 38     chip = NULL;
 39     mutex_lock(&register_mutex);
 40     for (i = 0; i < SNDRV_CARDS; i++) {
 41         if (usb_chip[i] && usb_chip[i]->dev == dev) {
 42             if (usb_chip[i]->shutdown) {
 43                 snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");
 44                 goto __error;
 45             }
 46             chip = usb_chip[i];
 47             chip->probing = 1;
 48             break;
 49         }
 50     }
 51     if (! chip) {
 52         /* it's a fresh one.
 53          * now look for an empty slot and create a new card instance
 54          */
 55         for (i = 0; i < SNDRV_CARDS; i++)
 56             if (enable[i] && ! usb_chip[i] &&
 57                 (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
 58                 (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
 59                 if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) {
 60                     goto __error;
 61                 }
 62                 snd_card_set_dev(chip->card, &intf->dev);
 63                 chip->pm_intf = intf;
 64                 break;
 65             }
 66         if (!chip) {
 67             printk(KERN_ERR "no available usb audio device\n");
 68             goto __error;
 69         }
 70     }
 71 
 72     /*
 73      * For devices with more than one control interface, we assume the
 74      * first contains the audio controls. We might need a more specific
 75      * check here in the future.
 76      */
 77     if (!chip->ctrl_intf)
 78         chip->ctrl_intf = alts;
 79 
 80     chip->txfr_quirk = 0;
 81     err = 1; /* continue */
 82     if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
 83         /* need some special handlings */
 84         if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0)
 85             goto __error;
 86     }
 87 
 88     if (err > 0) {
 89         /* create normal USB audio interfaces */
 90         if (snd_usb_create_streams(chip, ifnum) < 0 ||
 91             snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) {
 92             goto __error;
 93         }
 94     }
 95 
 96     /* we are allowed to call snd_card_register() many times */
 97     if (snd_card_register(chip->card) < 0) {
 98         goto __error;
 99     }
100 
101     usb_chip[chip->index] = chip;
102     chip->num_interfaces++;
103     chip->probing = 0;
104     mutex_unlock(&register_mutex);
105     return chip;
106 
107  __error:
108     if (chip) {
109         if (!chip->num_interfaces)
110             snd_card_free(chip->card);
111         chip->probing = 0;
112     }
113     mutex_unlock(&register_mutex);
114  __err_val:
115     return NULL;
116 }

probe依次调用了:

1 snd_usb_apply_boot_quirk
2 snd_usb_audio_create
3 snd_usb_create_quirk
4 snd_usb_create_streams
5  snd_usb_create_stream
6   snd_usb_parse_audio_interface 这里根据usb的信息解析成pcm参数(如声道数量,采样率等等)
7 
8 snd_usb_create_mixer
9 snd_card_register

总结:

UAC设备的参数是通过USB描述符确定的。比如声道bNrChannels位深bBitResolution采样率bSamFreqType。截取其中一段说明:

bNrChannels             1
bSubframeSize           2
bBitResolution         16
bSamFreqType            7 Discrete
tSamFreq[ 0]         8000
tSamFreq[ 1]        11025
tSamFreq[ 2]        16000
tSamFreq[ 3]        22050
tSamFreq[ 4]        32000
tSamFreq[ 5]        44100
tSamFreq[ 6]        48000

声道1,位深16,波特率8000~48000。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏黑白安全

windows命令执行漏洞不会玩? 看我!

经常有小伙伴碰到了命令执行漏洞不会玩,比如mssql注入点的命令执行,怎么来获取一个meterpreter?这个时候,就需要想办法来获取了,关于命令行来执行远程...

2004
来自专栏程序员叨叨叨

【转】从零开始手敲次世代游戏引擎(一)

况且,考虑到项目的庞大,和剩下的时日(可能也就1~2万天了),基于已经过去的1万多天的经验,这过程当中比尔盖茨一定会死去,冯氏架构也可能成为遗物。所以,保持代码...

2192
来自专栏施炯的IoT开发专栏

有关Visual Studio 2010 RTM与Windows Mobile/Windows Phone开发

    4月12日参加了Visual Studio 2010的首发活动,回来通过MSDN Subscription下载了Windows 7 Utimate和Vi...

1948
来自专栏张善友的专栏

Mono 2.2 发布了

Mono 2.2 推出新的代码生成引擎,会产生更优质的代码.对 Windows Form 以及其它内容做进一步改进 MONO 2.2 新特性: JIT N...

1867
来自专栏张善友的专栏

Mono运行于IPhone之上

今晚看到Mono老大的blog上有一个Mono on the iPhone, 就是最近Sun公司还在为iPhone上运行Java 苹果没兴趣 Sun单干。 .N...

1936
来自专栏大内老A

MS Enterprise Library 5.0发布!!

What is Enterprise Library Enterprise Library is a collection of reusable softwa...

1795
来自专栏哈雷彗星撞地球

RunLoop总结:RunLoop的应用场景(四)App卡顿监测

今天要介绍的RunLoop使用场景很有意思,在做长期项目,需要跟踪解决用户问题非常有用。 使用RunLoop 监测主线程的卡顿,并将卡顿时的线程堆栈信息保存下...

1162
来自专栏walterlv - 吕毅的博客

Support Horizontal Scrolling of TouchPad in WPF Application

发布于 2017-11-23 14:09 更新于 2018-08...

791
来自专栏张善友的专栏

每周.NET前沿技术文章摘要(2017-05-17)

汇总国外.NET社区相关文章,覆盖.NET ,ASP.NET等内容,本期包含性能分析这一主题内容

3760
来自专栏林德熙的博客

WPF popup置顶 另外的已知问题

http://www.cnblogs.com/Leaco/p/3164394.html

1263

扫码关注云+社区