一、添加输出声卡
输出流程图:
在声卡列表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;