RK3588 tinyalsa_hal添加一个自定义声卡输入和输出

一、添加输出声卡

输出流程图:

在声卡列表snd_out_sound_cards里添加一个自己的声卡,比如

--- a/tinyalsa_hal/audio_hw.h
+++ b/tinyalsa_hal/audio_hw.h
@@ -216,6 +216,7 @@ enum snd_out_sound_cards {
     SND_OUT_SOUND_CARD_SPDIF,
     SND_OUT_SOUND_CARD_SPDIF_1,
     SND_OUT_SOUND_CARD_BT,
+    SND_OUT_SOUND_CARD_UAC,
     SND_OUT_SOUND_CARD_MAX,
 };

//这里声卡数量也要加1
--- a/tinyalsa_hal/audio_hw.c
+++ b/tinyalsa_hal/audio_hw.c
@@ -62,8 +62,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <ctype.h>
-#define SNDRV_CARDS 8
-#define SNDRV_DEVICES 8
+#define SNDRV_CARDS 9
+#define SNDRV_DEVICES 9

添加一个dev_proc_info

参考一下rk的speaker:

自定义声卡为:

--- a/tinyalsa_hal/audio_hw.c
+++ b/tinyalsa_hal/audio_hw.c
@@ -407,9 +410,17 @@ struct dev_proc_info SPEAKER_OUT_NAME[] = /* add codes& dai name here*/
     {"rockchiprt5672c", NULL,},
     {"rk3528acodec",    NULL},
     {"rockchipdummyco",    NULL},
     {NULL, NULL}, /* Note! Must end with NULL, else will cause crash */
 };
 
+struct dev_proc_info UAC_OUT_NAME[] =
+{
+    {"UAC2Gadget",    NULL},//这里填写实际的声卡名。用cat /proc/asound/cards查看
+    {NULL, NULL}, /* Note! Must end with NULL, else will cause crash */
+};
+
+

将声卡添加到输出流中:

根据上面的输出流程图,首先会调用adev_open_output_stream这个函数来打开要配置输出声卡,

write配置为out_write

最终是调用了start_output_stream函数

在 read_out_sound_card函数里面获取声卡id添加到dev_out中

@@ -781,6 +792,7 @@ static void read_out_sound_card(struct stream_out *out)
         get_specified_out_dev(&device->dev_out[SND_OUT_SOUND_CARD_SPDIF], card, id, SPDIF_OUT_NAME);
         get_specified_out_dev(&device->dev_out[SND_OUT_SOUND_CARD_SPDIF_1],card, id, SPDIF_1_OUT_NAME);
         get_specified_out_dev(&device->dev_out[SND_OUT_SOUND_CARD_BT], card, id, BT_OUT_NAME);
+               get_specified_out_dev(&device->dev_out[SND_OUT_SOUND_CARD_UAC], card, id, UAC_OUT_NAME);
     }
     dumpdev_info("out", device->dev_out, SND_OUT_SOUND_CARD_MAX);
     return ;
@@ -1164,6 +1176,20 @@ static int start_output_stream(struct stream_out *out)
             device = adev->dev_out[SND_OUT_SOUND_CARD_SPEAKER].device;
             ret = open_pcm(card, device, (int)SND_OUT_SOUND_CARD_SPEAKER, out);
             if (ret <  0) return ret;
+                       /**添加UAC声卡播放音频**/
+                       char value[PROPERTY_VALUE_MAX];
+                       property_get("persist.sys.uac_speak_output", value, "0");
+                   int uac_speak_output = atoi(value);
                    if(uac_speak_output == 1)
+                       {
+                               card = adev->dev_out[SND_OUT_SOUND_CARD_UAC].card;
+               device = adev->dev_out[SND_OUT_SOUND_CARD_UAC].device;
+                               if(card != (int)SND_OUT_SOUND_CARD_UNKNOWN)
+                               {
+                                       ret = open_pcm(card, device, (int)SND_OUT_SOUND_CARD_UAC, out);
+                                       if (ret < 0) return ret;
+                   }
+                       }
   

通过配置属性persist.sys.uac_speak_output为1声卡就可以播放音频

二、添加输入声卡

输入流程图

添加输入声卡与上述输出声卡的步骤类似,这里贴上对应的补丁:

diff --git a/tinyalsa_hal/audio_hw.h b/tinyalsa_hal/audio_hw.h
index aeade30..ba7cb38 100755
--- a/tinyalsa_hal/audio_hw.h
+++ b/tinyalsa_hal/audio_hw.h
@@ -225,6 +236,9 @@ enum snd_in_sound_cards {
     SND_IN_SOUND_CARD_MIC = 0,
     SND_IN_SOUND_CARD_BT,
     SND_IN_SOUND_CARD_HDMI,
+    SND_IN_SOUND_CARD_LT6911UXE,
     SND_IN_SOUND_CARD_MAX,
};
--- a/tinyalsa_hal/audio_hw.c
+++ b/tinyalsa_hal/audio_hw.c
@@ -485,6 +485,28 @@ struct dev_proc_info MIC_IN_NAME[] =
     {NULL, NULL}, /* Note! Must end with NULL, else will cause crash */
 };
+struct dev_proc_info LT6911UXE_IN_NAME[] =
+{
+	{"soundlt6911uxe", NULL},
+	{NULL, NULL}, /* Note! Must end with NULL, else will cause crash */
+};
@@ -834,10 +856,15 @@ static void read_in_sound_card(struct stream_in *in)
             len--;
            id[len] = '\0';
         }
+		ALOGD("MIC card%d id:%s", card, id);
         get_specified_in_dev(&device->dev_in[SND_IN_SOUND_CARD_MIC], card, id, MIC_IN_NAME);
         /* set HDMI audio input info if need hdmi audio input */
         get_specified_in_dev(&device->dev_in[SND_IN_SOUND_CARD_HDMI], card, id, HDMI_IN_NAME);
         get_specified_in_dev(&device->dev_in[SND_IN_SOUND_CARD_BT], card, id, BT_IN_NAME);
+		get_specified_in_dev(&device->dev_in[SND_IN_SOUND_CARD_LT6911UXE], card, id, LT6911UXE_IN_NAME);
     }
     dumpdev_info("in", device->dev_in, SND_IN_SOUND_CARD_MAX);
     return ;
@@ -1481,11 +1508,31 @@ static int start_input_stream(struct stream_in *in)
       } else {
         ALOGD("open build mic");
         in->config = &pcm_config_in;
-        card = adev->dev_in[SND_IN_SOUND_CARD_MIC].card;
-        device =  adev->dev_in[SND_IN_SOUND_CARD_MIC].device;
+
+		/**根据系统属性选择不同的声卡**/
+		char mic_value[PROPERTY_VALUE_MAX];
+		property_get("persist.sys.mic", mic_value, "0");
+		if (strcmp(mic_value, "soundlt6911uxe") == 0) {
+       		card = adev->dev_in[SND_IN_SOUND_CARD_LT6911UXE].card;
+        	device =  adev->dev_in[SND_IN_SOUND_CARD_LT6911UXE].device;
+			ALOGD("mic_value is LT6911UXE: card = %d,device = %d",card,device);
+       }
         if (card != SND_IN_SOUND_CARD_UNKNOWN) {
-            route_pcm_card_open(card, getRouteFromDevice(in->device | AUDIO_DEVICE_BIT_IN));
+            //route_pcm_card_open(card, getRouteFromDevice(in->device | AUDIO_DEVICE_BIT_IN));
             in->pcm = pcm_open(card, device, PCM_IN, in->config);
         }

 @@ -4260,6 +4307,9 @@ static void adev_open_init(struct audio_device *adev)
         	adev->dev_out[SND_OUT_SOUND_CARD_UAC].id = "UAC";
     adev->dev_in[SND_IN_SOUND_CARD_MIC].id = "MIC";
     adev->dev_in[SND_IN_SOUND_CARD_BT].id = "BT";
+	adev->dev_in[SND_IN_SOUND_CARD_DUMMY].id = "LT6911UXE";
     adev->owner[0] = NULL;
     adev->owner[1] = NULL;

相关推荐

  1. RK3588 Android13定义一个按键实现长按短按

    2024-07-20 15:16:02       36 阅读
  2. RK3568 linux-5.10 rk809 实现spk hp自动切换

    2024-07-20 15:16:02       36 阅读
  3. 音视频实战--定义输入输出IO

    2024-07-20 15:16:02       53 阅读
  4. bash shell 重定向输入输出

    2024-07-20 15:16:02       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-20 15:16:02       169 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-20 15:16:02       185 阅读
  3. 在Django里面运行非项目文件

    2024-07-20 15:16:02       155 阅读
  4. Python语言-面向对象

    2024-07-20 15:16:02       169 阅读

热门阅读

  1. C#面:MVC中的TempData\ViewBag\ViewData区别?

    2024-07-20 15:16:02       33 阅读
  2. Linux下载网络文档

    2024-07-20 15:16:02       32 阅读
  3. 网络爬虫基础介绍

    2024-07-20 15:16:02       34 阅读
  4. Linux内存从0到1学习笔记(8.20 ION (二))

    2024-07-20 15:16:02       36 阅读
  5. 基于 Go1.19 的站点模板爬虫:构建与实战

    2024-07-20 15:16:02       35 阅读
  6. Redis

    Redis

    2024-07-20 15:16:02      34 阅读
  7. 订单管理系统需求规范

    2024-07-20 15:16:02       42 阅读
  8. E15.【C语言】练习:逗号表达式和前置后置++

    2024-07-20 15:16:02       36 阅读
  9. VScode+latex+Sumatra 环境配置

    2024-07-20 15:16:02       42 阅读