Use of audio under hdmirx of ArmSoM-W3 (RK3588)

1 Introduction

2. Audio configuration

DTS adds sound card configuration:

--- a/arch/arm64/boot/dts/rockchip/rk3588-evb1-lp4.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3588-evb1-lp4.dtsi
@@ -47,6 +47,26 @@ play-pause-key {
};
};
+ hdmiin_dc: hdmiin-dc {
+ compatible = "rockchip,dummy-codec";
+ #sound-dai-cells = <0>;
+ };
+ hdmiin-sound {
+ compatible = "simple-audio-card";
+ simple-audio-card,format = "i2s";
+ simple-audio-card,name = "rockchip,hdmiin";
+ simple-audio-card,bitclock-master = <&dailink0_master>;
+ simple-audio-card,frame-master = <&dailink0_master>;
+ status = "okay";
+ simple-audio-card,cpu {
+ sound-dai = <&i2s7_8ch>;
+ };
+ dailink0_master: simple-audio-card,codec {
+ sound-dai = <&hdmiin_dc>;
+ };
+ };
+&i2s7_8ch {
+ status = "okay";
+};

There is a problem here that needs attention. When writing documents, it is based on the SDK version number:

rk3588_linux_release_v1.0.5_20221120.xml

In subsequent updates, the driver used by hdmirx-audio has changed

hdmiin-sound {
	    compatible = "rockchip,hdmi";
	    rockchip,mclk-fs = <128>;
	    rockchip,format = "i2s";
	    rockchip,bitclock-master = <&hdmirx_ctrler>;
	    rockchip,frame-master = <&hdmirx_ctrler>;
	    rockchip,card-name = "rockchip,hdmiin";
	    rockchip,cpu = <&i2s7_8ch>;
	    rockchip,codec = <&hdmirx_ctrler 0>;
	    rockchip,jack-det;
	};

Just understand here

3. Sound card information

When the development board is powered on, the following will be printed:

[    6.640779] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_delayed_work_audio: enable audio
[    6.640801] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_delayed_work_audio: restart audio fs(44100 -> 44100) ch(0 -> 2)
[    6.640810] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_audio_fifo_init
[    6.847421] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_delayed_work_audio: audio underflow 0x2000000, with fs valid 44100
[    6.847443] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_audio_fifo_init
[    7.257421] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_delayed_work_audio: restart audio fs(44100 -> 48000) ch(2 -> 2)
[    7.257468] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_audio_fifo_init
[    7.460747] rk_hdmirx fdee0000.hdmirx-controller: audio on
[   24.984083] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_delayed_work_audio: audio underflow 0x2000000, with fs valid 44100
[   24.984117] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_audio_fifo_init
[   33.727417] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_delayed_work_audio: audio underflow 0x2000000, with fs valid 44100
[   33.727456] rk_hdmirx fdee0000.hdmirx-controller: hdmirx_audio_fifo_init

This contains hdmirx-audio sampling rate and channel number information.
Of course, you can also check the information in the driver file /sys/class/hdmirx/hdmirx

Use the following command to view sound card information:

cat /proc/asound/cards
 0 [rockchiphdmi0  ]: rockchip-hdmi0 - rockchip-hdmi0
                      rockchip-hdmi0
 1 [rockchiphdmi1  ]: rockchip-hdmi1 - rockchip-hdmi1
                      rockchip-hdmi1
 2 [rockchiphdmiin ]: rockchip_hdmiin - rockchip,hdmiin
                      rockchip,hdmiin
 3 [rockchipes8311 ]: rockchip_es8311 - rockchip,es8311
                      rockchip,es8311

4. Sound test

In the Linux system, the arecord and aplay commands are used to test the sound by default.

录音:
root@linaro-alip:~# arecord -l
**** List of CAPTURE Hardware Devices ****
card 2: rockchiphdmiin [rockchip,hdmiin], device 0: rockchip,hdmiin i2s-hifi-0 [rockchip,hdmiin i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: rockchipes8311 [rockchip,es8311], device 0: fe470000.i2s-dummy_codec fpc_dc-0 [fe470000.i2s-dummy_codec fpc_dc-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
  
  //arecord可以查看当前系统里有哪些声卡可以录音,以上内容可以看到hdmirx是card2
  
 root@linaro-alip:~# arecord -D hw:2,0 -f S16_LE -r 48000 -c 2 -d 2 t.wav
Recording WAVE 't.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
//声音格式:16位 采样率:48000 通道数:2 录音:2

Use the above command to record the t.wav file, and then use aplay to test the sound

root@linaro-alip:~# aplay -D plughw:1,0 t.wav  //指定hdmiout播放
Playing WAVE 't.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo

5. Experience sharing

The above command has no problem in the stage of testing the sound card, but it is far from enough as a developer. Most of them will use GStreamer to process audio. Next, I will share some problems I encountered when using GStreamer to process hdmirx. There are two
audios question:

1. When there is a delay, leaky=1 cannot be used, which leads to serious problems in the synchronization of our video and audio.
2. There is (da da da) noise when playing audio through hdmi. The command is as follows:
1. No delay: gst-launch-1.0 alsasrc device=hw:2,0 ! queue ! volume mute=false
! alsasink device=hw:1, 0 -e -v
2, with delay: gst-launch-1.0 alsasrc
device=hw:2,0 use-driver-timestamps=false ! queue max-size-buffers=0
max-size-bytes=0 max-size -time=3100000000 min-threshold-buffers=0
min-threshold-bytes=0 min-threshold-time=3000000000 ! volume
mute=false ! alsasink device=hw:1,0 async=true -e -v

gst-launch-1.0 alsasrc device=hw:2,0 use-driver-timestamps=false ! queue leaky=1 max-size-buffers=0 max-size-bytes=0 max-size-time=3100000000 min-threshold-buffers=0 min-threshold-bytes=0 min-threshold-time=3000000000 ! volume mute=false ! alsasink device=hw:1,0 async=true -e -v
解决方法:
更新/usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstcoreelements.so

There is (da da da) noise when playing audio through hdmi:
the analysis is caused by the sampling rate, gst-launch-1.0 alsasrc device=hw:2,0 ! queue ! volume mute=false ! alsasink device=hw:1,0 - e -v will use the unspecified sampling rate, and will use the default
one. You can view the sampling rate in /sys/class/hdmirx/hdmirx/audio_rate. The
correct command should be:

gst-launch-1.0 alsasrc device=hw:2,0 ! audio/x-raw,format=S16LE,rate=48000,chanels=8 ! queue ! volume mute=false ! alsasink device=hw:1,0 -e -v

The sampling rate is determined by the audio source.
insert image description here
insert image description here
There was noise before gstreamer because the wrong rate was automatically negotiated. The default sampling rate is 44100Hz

6. Conclusion

Developers need to provide more parameters for audio: sampling rate, bit rate, number of channels, and state.
Being able to obtain these information in the driver file is conducive to better development. The most direct impact on sound is the sampling rate. Other parameters, code rate = sampling rate x number of channels x bit depth can also be calculated, and other parameters have little influence.

ArmSoM Technology Forum: http://forum.armsom.org/

Guess you like

Origin blog.csdn.net/nb124667390/article/details/131259821