Skip to content

Commit 45fe2f0

Browse files
committed
[WIP][RFC] Test-case: Set PGAs to unity gain in script check-alsabat.sh
This patch adds find of volume controls for used playback and capture devices and sets them to unity gain (0 dB). The alsabat test fails if e.g. capture PGA is set to their maximum value that can be up to +30 dB. The test sine wave distorts and causes test fail. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 6b4000f commit 45fe2f0

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

test-case/check-alsabat.sh

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ set -e
2020
# remove the existing alsabat wav files
2121
rm -f /tmp/bat.wav.*
2222

23-
source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh
23+
TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
24+
TPLGREADER="$TESTDIR"/tools/sof-tplgreader.py
25+
26+
# shellcheck source=case-lib/lib.sh
27+
source "$TESTDIR/case-lib/lib.sh"
2428

2529
OPT_OPT_lst['p']='pcm_p' OPT_DESC_lst['p']='pcm for playback. Example: hw:0,0'
2630
OPT_PARM_lst['p']=1 OPT_VALUE_lst['p']=''
@@ -37,12 +41,16 @@ OPT_PARM_lst['n']=1 OPT_VALUE_lst['n']=240000
3741
OPT_OPT_lst['s']='sof-logger' OPT_DESC_lst['s']="Open sof-logger trace the data will store at $LOG_ROOT"
3842
OPT_PARM_lst['s']=0 OPT_VALUE_lst['s']=1
3943

44+
OPT_OPT_lst['t']='tplg' OPT_DESC_lst['t']='tplg file, default value is env TPLG: $''TPLG'
45+
OPT_PARM_lst['t']=1 OPT_VALUE_lst['t']="$TPLG"
46+
4047
func_opt_parse_option "$@"
4148

4249
pcm_p=${OPT_VALUE_lst['p']}
4350
pcm_c=${OPT_VALUE_lst['c']}
4451
frequency=${OPT_VALUE_lst['f']}
4552
frames=${OPT_VALUE_lst['n']}
53+
tplg=${OPT_VALUE_lst['t']}
4654

4755
if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ];
4856
then
@@ -64,11 +72,84 @@ function __upload_wav_file
6472
done
6573
}
6674

75+
function set_pga_to_unity_gain ()
76+
{
77+
tmp=$(amixer controls | grep "$pga" | grep Volume)
78+
search="name="
79+
cname=${tmp#*$search}
80+
81+
# Get volume min and step to compute value for cset
82+
# for 0 dB gain. The amixer line looks like
83+
# "| dBscale-min=-50.00dB,step=1.00dB,mute=1"
84+
scale=$(amixer cget name="$cname" | grep "dBscale" || true)
85+
search="dBscale-min="
86+
tmp=${scale#*$search}
87+
min_db="${tmp%%dB*}"
88+
search="step="
89+
tmp=${scale#*$search}
90+
step_db="${tmp%%dB*}"
91+
92+
# Get multiplied by 100 values by removing decimal dot
93+
min_x100="${min_db//.}"
94+
step_x100="${step_db//.}"
95+
val=$(printf %d "$(((-min_x100) / step_x100))")
96+
97+
# Apply the computed value for requested gain
98+
amixer cset name="$cname" "$val"
99+
}
100+
101+
function set_pgas_list_to_unity_gain ()
102+
{
103+
if [[ -z "$1" ]]; then
104+
return
105+
fi
106+
107+
for pga in $1; do
108+
dlogi "Set $pga"
109+
set_pga_to_unity_gain "$pga"
110+
done
111+
}
112+
113+
function get_snd_base ()
114+
{
115+
tmp=${1#*"hw:"}
116+
ncard="${tmp%%,*}"
117+
ndevice="${tmp#*,}"
118+
echo "/dev/snd/pcmC${ncard}D${ndevice}"
119+
}
120+
121+
function get_play_snd ()
122+
{
123+
tmp=$(get_snd_base $1)
124+
echo ${tmp}p
125+
}
126+
127+
function get_capture_snd ()
128+
{
129+
tmp=$(get_snd_base $1)
130+
echo ${tmp}c
131+
}
132+
67133
# check the PCMs before alsabat test
68134
dlogi "check the PCMs before alsabat test"
69135
[[ $(aplay -Dplug$pcm_p -d 1 /dev/zero -q) ]] && die "Failed to play on PCM: $pcm_p"
70136
[[ $(arecord -Dplug$pcm_c -d 1 /dev/null -q) ]] && die "Failed to capture on PCM: $pcm_c"
71137

138+
# Set PGAs for PCMs to 0 dB value
139+
test -n "$(command -v $TPLGREADER)" || {
140+
die "Command $TPLGREADER is not available."
141+
}
142+
143+
test -n "$tplg" || die "Use -t or set environment variable TPLG to current topology"
144+
dlogi "Getting playback PGA information"
145+
play_snd=$(get_play_snd "$pcm_p")
146+
PLAY_PGA=$($TPLGREADER "$tplg" -f "snd:$play_snd" -d pga -v)
147+
set_pgas_list_to_unity_gain "$PLAY_PGA"
148+
dlogi "Getting capture PGA information"
149+
cap_snd=$(get_capture_snd "$pcm_c")
150+
CAP_PGA=$($TPLGREADER "$tplg" -f "snd:$cap_snd" -d pga -v)
151+
set_pgas_list_to_unity_gain "$CAP_PGA"
152+
72153
# alsabat test
73154
# different PCMs may support different audio formats(like samplerate, channel-counting, etc.).
74155
# use plughw to do the audio format conversions. So we don't need to specify them for each PCM.

0 commit comments

Comments
 (0)