RK3399板卡 Linux Alsa 音频开发说明文档一、安装配置
以VS-RK3399 为例:
1.声卡配置
Device Drivers > Sound card support > Advanced Linux Sound Architecture > ALSA
for SoC audio support > CODEC drivers
<*> Realtek ALC5640 CODEC
同时需要在板级文件dts 加入相应的Codec 配置
/kernel/arch/arm64/boot/dts/rockchip/rk3399-sunychip-board-mipi.dts
rt5640-sound {
compatible = "simple-audio-card";
simple-audio-card,format = "i2s";
simple-audio-card,name = "rockchip,rt5640-codec";
simple-audio-card,mclk-fs = <256>;
simple-audio-card,widgets =
"Microphone", "Mic Jack",
"Headphone", "Headphone Jack",
"Speaker", "Speaker";
simple-audio-card,routing =
"Mic Jack", "MICBIAS1",
"IN2P", "Mic Jack",
"IN2N", "Mic Jack",
"Headphone Jack", "HPOL",
"Headphone Jack", "HPOR",
"Speaker", "SPOLP",
"Speaker", "SPOLN",
"Speaker", "SPORP",
"Speaker", "SPORN";
simple-audio-card,cpu {
sound-dai = <&i2s1>;
};
simple-audio-card,codec {
sound-dai = <&rt5640>;
};
};
&i2c1 {
status = "okay";
i2c-scl-rising-time-ns = <300>;
i2c-scl-falling-time-ns = <15>;
rt5640: rt5640@1c{
#sound-dai-cells = <0>;
compatible = "realtek,rt5640";
reg = <0x1c>;
clocks = <&cru SCLK_I2S_8CH_OUT>;
clock-names = "mclk";
realtek,in1-differential;
pinctrl-names = "default";
//hp-con-gpio = <&gpio0 11 GPIO_ACTIVE_HIGH>;
//hp-det-gpio = <&gpio4 28 GPIO_ACTIVE_LOW>;
//io-channels = <&saradc 4>;
//hp-det-adc-value = <300>;
};
};
2.Alsa-lib 及相关调试工具安装
配置勾选相应的安装包。进入到buildroot 目录,make menuconfig
Target packages > Audio and video applications > alsa-utils
可以根据实际的需求勾选相应的alsa 调试工具,一般勾选配置如上图。编译成功后在usr/bin
目录下会有相应的工具生成
二、alsa 配置文件解析及相关配置
1.alsa.conf 文件解析
ALSA 核心配置文件位于usr/share/alsa/目录下,主要配置文件为alsa.conf。其他配
置文件需不需要,位置在哪都由alsa.conf 决定。通常会有usr/share/alsa/card 和
usr/share/alsa/pcm 两个子目录,用于设置card 的相关参数,别名以及一些PCM 默认设置。
Alsa.conf 主要内容包括:
1)用hook 读取/etc/asound.conf 和~/.asoundrc 这两个配置文件
1)用hook 读取/etc/asound.conf 和~/.asoundrc 这两个配置文件
@hooks [
{
func load
files [
{
@func concat
strings [
{ @func datadir }
"/alsa.conf.d/"
}
"/etc/asound.conf"
"~/.asoundrc"
errors false
}
2)设置default pcm 的一些默认参数
defaults.ctl.card 0
defaults.pcm.card 0
defaults.pcm.device 0
defaults.pcm.subdevice -1
defaults.pcm.nonblock 1
defaults.pcm.compat 0
3)设置alsa 内置的一些plugin 接口参数,例如file:
pcm.file {
@args [ FILE FORMAT ]
@args.FILE {
type string
}
@args.FORMAT {
type string
default {
@func refer
name defaults.pcm.file_format
}
}
type file
slave.pcm null
file $FILE
format $FORMAT
truncate {
@func refer
name defaults.pcm.file_truncate
}
}
File plugin 的作用是将pcm 数据流存储到文件中
2.alsa.conf 主要配置
现在配置alsa.conf 文件主要是对route 通路和hw 参数进行配置。针对不同的codec,
放音和录音等都需要对route 通路和一些hw 参数进行设置。具体配置方法是在alsa.conf
配置文件中加入如下配置:
以rt5651 的放音为例:
ctl.SpeakerNormal{
type hw
card 0 # Can replace with driver"s name from /proc/asound/cardx
}
pcm.dmixer {
type dmix
ipc_key 1025
slave {
pcm "hw:0,0"
period_time 0
period_size 4096
buffer_size 16384
rate 44100
}
}
pcm.SpeakerNormal {
type plug
slave.pcm "dmixer"
type hooks
hooks.0 {
type ctl_elems
hook_args [
{
name 'DAC MIXL INF1 Switch'
value on
}
{
name 'DAC MIXR INF1 Switch'
value on
}
{
name 'Stereo DAC MIXL DAC L1 Switch'
value on
}
{
name 'Stereo DAC MIXR DAC R1 Switch'
value on
}
{
name 'OUT MIXL DAC L1 Switch'
value on
}
{
name 'OUT MIXR DAC R1 Switch'
value on
}
{
name 'HPOVOL L Switch'
value on
}
{
name 'HPOVOL R Switch'
value on
}
{
name 'HPO MIX HPVOL Switch'
value on
}
{
name 'HPO MIX HPVOL Switch'
value on
}
{
name 'HPO L Playback Switch'
value on
}
{
name 'HPO R Playback Switch'
value on
}
}
}
对于route 通路具体值设置可以参考使用amixer contents 打印的格式
numid=9,iface=MIXER,name='Headphonel Playback Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=3,step=0
: values=3
| dBscale-min=-48.00dB,step=12.00dB,mute=0
numid=10,iface=MIXER,name='Headphoner Playback Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=3,step=0
: values=3
| dBscale-min=-48.00dB,step=12.00dB,mute=0
numid=97,iface=MIXER,name='Headphone Switch'
; type=BOOLEAN,access=rw------,values=1
: values=on
numid=12,iface=MIXER,name='Lineoutn Playback Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=1,step=0
RK 平台针对不同codec 对应的alsa.conf 文件都存放在sdk 代码的
device\rockchip\rk3399\alsa_conf 目录下,打包固件会将相应的alsa.conf 拷贝覆盖
usr/share/alsa/目录的alsa.conf
|