R16开发板tina音频系统测试及tinyalsa移植

Posted __2017__

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了R16开发板tina音频系统测试及tinyalsa移植相关的知识,希望对你有一定的参考价值。

一、硬件


上面红框是耳机插口,下面红框是Speaker插口。

首先,接上Speaker后,在android 4.4上,耳机和Speaker都可以正常工作;但是,烧录R16开发板tina系统LCD调试编译的最新Tina系统,不工作。


二、调试

表面上,执行命令:

# cat cards /proc/asound/cards
 0 [audiocodec     ]: audiocodec - audiocodec
                      audiocodec
以上是 Android 4.4的显示,在Tina上则是:sndcodec。查看代码发现,前者声卡实现:

linux-3.4\\sound\\soc\\sunxi\\audiocodec\\sunxi_sndcodec.c
static struct snd_soc_card snd_soc_sunxi_sndpcm = 
	.name 		= "audiocodec",
	.owner 		= THIS_MODULE,
	.dai_link 	= &sunxi_sndpcm_dai_link,
	.num_links 	= 1,
;
后者声卡定义:

linux-3.4\\sound\\soc\\sunxi\\audiocodec\\sun8iw5_machine.c
static struct snd_soc_card snd_soc_sunxi_sndpcm = 
	.name 		= "sndcodec",
	.owner 		= THIS_MODULE,
	.dai_link 	= sunxi_sndpcm_dai_link,
	.num_links 	= ARRAY_SIZE(sunxi_sndpcm_dai_link),
	.dapm_widgets = sunxi_ac_dapm_widgets,
	.num_dapm_widgets = ARRAY_SIZE(sunxi_ac_dapm_widgets),
	.dapm_routes = audio_map,
	.num_dapm_routes = ARRAY_SIZE(audio_map),
	.controls = ac_pin_controls,
	.num_controls = ARRAY_SIZE(ac_pin_controls),
	.suspend_post = sunxi_suspend,
	.resume_post = sunxi_resume,
;
对比两套代码,发现它们差别很大:


但是,进一步发现这些差别只集中在\\sound\\soc目录下。这样我们可以直接替换soc代码,即把Android内核的soc目录copy覆盖Tina对应的目录,这时通过“aplay /www/ring.wav”可以正常播放,说明音频这部分OK了。

至于原因,等以后研究Linux的ALSA音频子系统后再细数。

三、tinyasla移植
Linux音频子系统框架:


图片来源:http://www.cnblogs.com/Ph-one/p/6293353.html

OSS音频架构已经depressed,所以系统是ALSA架构,“在ALSA音频架构下,App是通过ALSA提供的alsa-lib库访问底层硬件”,Android没有使用alsa-lib库,而是自己实现了一套API即tinyalsa,代码路径:external/tinyalsa。

我们看下tinyalsa的构成:

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_SRC_FILES:= mixer.c pcm.c
LOCAL_MODULE := libtinyalsa
LOCAL_SHARED_LIBRARIES:= libcutils libutils
LOCAL_LDFLAGS += \\
	$(LOCAL_PATH)/libdrc.a
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_SRC_FILES:= tinyplay.c
LOCAL_MODULE := tinyplay
LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_SRC_FILES:= tinycap.c
LOCAL_MODULE := tinycap
LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_SRC_FILES:= tinymix.c
LOCAL_MODULE := tinymix
LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_SRC_FILES:= tinypcminfo.c
LOCAL_MODULE := tinypcminfo
LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
1、libtinyalsa库,可见 libtinyalsa只有mixer.c pcm.c两个文件构成,这极大地方便了移植(libdrc.a对我们没用)

2、tinyplay,播放

3、tinycap,录制

4、tinymix,控制声卡

5、tinypcminfo,查看声卡信息

为简单起见,移植过程中没有编译生成libtinyalsa库,而是作为源码编译,文件列表:

源码:https://github.com/RockyChing/tinyalsa.git

四、简单测试

# tinymix
tinymix
Mixer name: 'audiocodec'
Number of controls: 58
ctl     type    num     name                                     value
0       INT     1       headphone volume control                 62
1       INT     1       earpiece volume control                  62
2       INT     1       speaker volume control                   62
3       INT     1       MIC1_G boost stage output mixer control  3
4       INT     1       MIC2_G boost stage output mixer control  3
5       INT     1       LINEIN_G boost stage output mixer control 3
6       INT     1       PHONE_G boost stage output mixer control 3
7       INT     1       PHONE_PG boost stage output mixer control 3
8       INT     1       PHONE_NG boost stage output mixer control 3
9       INT     1       MIC1 boost AMP gain control              4
10      INT     1       MIC2 boost AMP gain control              4
11      INT     1       Lineout volume control                   62
12      INT     1       PHONEP-PHONEN pre-amp gain control       4
13      INT     1       Phoneout gain control                    3
14      INT     1       ADC input gain ctrl                      3
15      BOOL    1       Audio phone out                          Off
16      BOOL    1       Audio phone in                           Off
17      BOOL    1       Audio earpiece out                       Off
18      BOOL    1       Audio headphone out                      Off
19      BOOL    1       Audio speaker out                        Off
20      BOOL    1       Audio analog main mic                    Off
21      BOOL    1       Audio analog headsetmic                  Off
22      BOOL    1       Audio phone voicerecord                  Off
23      BOOL    1       Audio phone endcall                      Off
24      BOOL    1       Audio linein record                      Off
25      BOOL    1       Audio linein in                          Off
26      ENUM    1       Speaker Function                         spk
27      BOOL    1       Audio digital main mic                   Off
28      BOOL    1       Audio digital headset mic                Off
29      BOOL    1       Audio digital phone out                  Off
30      BOOL    1       Audio digital phonein                    Off
31      BOOL    1       Audio digital clk format status          Off
32      BOOL    1       Audio bt clk format status               Off
33      BOOL    1       Audio bt out                             Off
34      BOOL    1       Audio analog bt mic                      Off
35      BOOL    1       Audio analog bt phonein                  Off
36      BOOL    1       Audio digital bt mic                     Off
37      BOOL    1       Audio digital bt phonein                 Off
38      BOOL    1       Audio bt button voice                    Off
39      BOOL    1       Audio digital bb bt clk format           Off
40      BOOL    1       Audio system bt capture flag             Off
41      BOOL    1       Audio analog bb capture mic              Off
42      BOOL    1       aif3 loopback                            Off
43      BOOL    1       aif2 loopback                            Off
44      BOOL    1       digital_bb_bt                            Off
45      INT     1       system play_capture set 1                0
46      INT     1       system play_capture set 2                0
47      BOOL    1       AIF1_AD0L_MXR_SRC AIF1DA0Ldata           Off
48      BOOL    1       AIF1_AD0L_MXR_SRC AIF2DACLdata           Off
49      BOOL    1       AIF1_AD0L_MXR_SRC ADCLdata               Off
50      BOOL    1       AIF1_AD0L_MXR_SRC AIF2DACRdata           Off
51      BOOL    1       AIF1_AD0R_MXR_SRC AIF1DA0Rdata           Off
52      BOOL    1       AIF1_AD0R_MXR_SRC AIF2DACRdata           Off
53      BOOL    1       AIF1_AD0R_MXR_SRC ADCRdata               Off
54      BOOL    1       AIF1_AD0R_MXR_SRC AIF2DACLdata           Off
55      BOOL    1       Analog cap test disable phonein          Off
56      BOOL    1       Analog cap test disable mic1             Off
57      BOOL    1       Analog cap test disable mic2             Off
设置Speaker音量(对应Number为2):

tinymix 2 24
设置 Speaker音量为24。

26      ENUM    1       Speaker Function                         spk
说明当前用Speaker做外放,下面设置用耳机播放:

tinymix 26 headset
tinyplay xxx.wav

以上是关于R16开发板tina音频系统测试及tinyalsa移植的主要内容,如果未能解决你的问题,请参考以下文章

Android音频底层调试-基于tinyalsa

全志 Tina Linux 系统软件 开发指南 sdk源码编译操作 深入理解Tina-sdk编译框架 支持百问网T113 D1-H哪吒 DongshanPI-D1s V853-Pro等开发板

全志 Tina Linux 系统软件 开发指南 sdk源码编译操作 深入理解Tina-sdk编译框架 支持百问网T113 D1-H哪吒 DongshanPI-D1s V853-Pro等开发板

全志 Tina Linux 系统软件 开发指南 sdk源码编译操作 深入理解Tina-sdk编译框架 支持百问网T113 D1-H哪吒 DongshanPI-D1s V853-Pro等开发板

全志R16编译环境搭建指南,全志R16_Tina SDK Quick Start Guide

支持百问网T113 D1-H D1s V853 V851s 等开发板 使用 Tina Linux NOR Flash文件系统 开发指南