解决Android USB声卡与SPK不兼容问题

问题:

        USB拾音器插上安卓设备,可以进行录音,但spk喇叭无声音输出,拔掉USB拾音器时,spk喇叭可以正常发出声音。

原因分析:

        USB拾音器自带一个播放网卡,需要禁用USB声卡功放功能

在A133_Android10.1源码中,路径

android/frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml

是用于配置USB音频策略的文件。

<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<!-- USB Audio HAL Audio Policy Configuration file -->

<module name="usb" halVersion="2.0">
    <mixPorts>
        <mixPort name="usb_accessory output" role="source">
            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                     samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
        </mixPort>
        <mixPort name="usb_device output" role="source"/>
        <mixPort name="usb_device input" role="sink"/>
    </mixPorts>
    <devicePorts>
        <devicePort tagName="USB Host Out" type="AUDIO_DEVICE_OUT_USB_ACCESSORY" role="sink">
            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                     samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
        </devicePort>
        <devicePort tagName="USB Device Out" type="AUDIO_DEVICE_OUT_USB_DEVICE" role="sink"/>
        <devicePort tagName="USB Headset Out" type="AUDIO_DEVICE_OUT_USB_HEADSET" role="sink"/>
        <devicePort tagName="USB Device In" type="AUDIO_DEVICE_IN_USB_DEVICE" role="source"/>
        <devicePort tagName="USB Headset In" type="AUDIO_DEVICE_IN_USB_HEADSET" role="source"/>
    </devicePorts>
    <routes>
        <route type="mix" sink="USB Host Out"
               sources="usb_accessory output"/>
       <!-- <route type="mix" sink="USB Device Out"
               sources="usb_device output"/>
        <route type="mix" sink="USB Headset Out"
               sources="usb_device output"/>-->
        <route type="mix" sink="usb_device input"
               sources="USB Device In,USB Headset In"/>
    </routes>
</module>

        根据XML 文件内容,我们可以知道这是一个与 USB 音频设备相关的配置文件。它定义了不同的混音端口(mixPorts)和设备端口(devicePorts),以及它们之间的路由(routes)。

在混音端口(mixPorts)部分,有以下定义:

  • “usb_accessory output” 是一个音频输出源,其角色是"source",支持的音频格式为 16 位 PCM,采样率为 44100,通道模式为立体声。
  • “usb_device output” 是一个音频输出源,其角色也是"source",但没有具体的音频配置。
  • “usb_device input” 是一个音频输入接收端,其角色为"sink",可以接收来自 USB 设备的音频输入。

在设备端口(devicePorts)部分,有以下定义:

  • “USB Host Out” 是一个音频输出接收端,其类型为"AUDIO_DEVICE_OUT_USB_ACCESSORY",角色为"sink",支持的音频格式为 16 位 PCM,采样率为 44100,通道模式为立体声。
  • “USB Device In” 是一个音频输入源,其类型为"AUDIO_DEVICE_IN_USB_DEVICE",角色为"source",表示它接收来自 USB 设备的音频输入。
  • “USB Headset In” 是一个音频输入源,其类型为"AUDIO_DEVICE_IN_USB_HEADSET",角色为"source",表示它接收来自 USB 耳机或头戴式耳机的音频输入。

在路由(routes)部分,有以下定义:

  • “USB Host Out” 接收来自 “usb_accessory output” 的音频混音输出。
  • “USB Device Out” 接收来自 “usb_device output” 的音频混音输出。
  • “USB Headset Out” 接收来自 “usb_device output” 的音频混音输出。
  • “usb_device input” 接收来自 “USB Device In” 和 “USB Headset In” 的音频输入源。

要关闭USB拾音器的播放网卡,您需要修改上述XML配置文件中的routes部分。

您可以按照以下步骤进行操作:

  1. 打开该XML配置文件,并找到routes部分。

  2. 将与USB拾音器输出相关的路由注释掉或删除。

<route type="mix" sink="USB Device Out" sources="usb_device output"/>
<route type="mix" sink="USB Headset Out" sources="usb_device output"/>

注释上述代码:

<!-- <route type="mix" sink="USB Device Out" sources="usb_device output"/> -->
<!-- <route type="mix" sink="USB Headset Out" sources="usb_device output"/> -->
  1. 保存修改后的XML配置文件。

  2. 重启编译或者重新加载USB音频驱动后重启。

猜你喜欢

转载自blog.csdn.net/qq_53676406/article/details/131513028