xref: /OK3568_Linux_fs/debian/overlay-debug/rockchip-test/audio/audio_functions_test.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/bash
2
3device_1=$1
4device_2=$2
5
6echo ""
7echo "*****************************************************"
8echo "*      Rockchip Platform Audio Functions Test       *"
9echo "*****************************************************"
10echo "*  Loop playback:                              [0]  *"
11echo "*  Loop capture:                               [1]  *"
12echo "*  Test loopback:                              [2]  *"
13echo "*  Exit audio test:                            [q]  *"
14echo "*****************************************************"
15
16echo ""
17echo -n  "Please select a test case: "
18read TEST_CASE
19echo ""
20
21PATH_AUDIO=/tmp/audio_test
22mkdir -p $PATH_AUDIO
23
24prepare_mic_capture()
25{
26	amixer set "Capture Digital" 192
27	amixer set "Capture Mute" 0
28	amixer set "Right PGA Mux" "DifferentialR"
29	amixer set "Left PGA Mux" "DifferentialL"
30	amixer set "Differential Mux" "Line 2"
31	amixer set "Left Channel" 0
32	amixer set "Right Channel" 0
33}
34
35loop_playback()
36{
37	echo "******** Loop playback start ********"
38
39	fs_tbl="8000 11025 16000 22050 32000 44100 48000 64000 88200 96000 176400 192000"
40	bits_tbl="16 24 32"
41	ch=2
42	seconds=2
43	gain=-30
44	play_device="default"
45
46	if [ -n "$1" ]; then
47		play_device=$1
48	fi
49
50	while [ $ch -ge 1 ]
51	do
52		for fs in $fs_tbl
53        do
54			for bits in $bits_tbl
55			do
56					echo "play_device=$play_device, ch="$ch", rate="$fs", bit=$bits, $seconds sec, gain=$gain"
57					sox -b $bits -r $fs -c $ch -n -t alsa $play_device synth $seconds sine 440 gain $gain
58			done
59		done
60	done
61
62	echo "******** Loop playback end ********"
63}
64
65loop_capture()
66{
67	PATH_CAPTURE=$PATH_AUDIO/cap_files
68	mkdir $PATH_CAPTURE
69
70	fs_tbl="8000 11025 16000 22050 32000 44100 48000 64000 88200 96000 176400 192000"
71	bits_tbl="S16_LE S24_LE S32_LE"
72	ch_tbl="2"
73	seconds=3
74	capt_device="default"
75
76	if [ -n "$1" ]; then
77		capt_device=$1
78	fi
79
80	echo "******** Loop capture start ********"
81
82	for fs in $fs_tbl
83	do
84		for bits in $bits_tbl
85		do
86			for ch in $ch_tbl
87			do
88				DUMP_FILE=$(printf 'cap_fs%d_format_%s_ch%d.wav' $fs $bits $ch)
89				echo "capt_device: $capt_device capture $DUMP_FILE $seconds sec"
90				arecord -D $capt_device -r $fs -f $bits -c $ch -d $seconds $PATH_CAPTURE/$DUMP_FILE
91			done
92		done
93	done
94
95	echo "******** Loop capture end ********"
96
97	echo "!! Please using 'adb pull /tmp/audio_test/cap_files/ .' dump all capture files !!"
98}
99
100case $TEST_CASE in
101	"0")
102		loop_playback $device_1
103	;;
104	"1")
105		prepare_mic_capture
106		loop_capture $device_1
107	;;
108	"2")
109		source ./test_loopback.sh $device_1 $device_2
110	;;
111	"q")
112		echo "Exit audio test"
113	;;
114	*)
115		echo "Invalid case $TEST_CASE"
116	;;
117esac
118
119exit
120