Skip to content

Commit

Permalink
[WIP][RFC] Test-case: Set PGAs to unity gain in script check-alsabat.sh
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
singalsu committed Oct 15, 2020
1 parent 6b4000f commit 45fe2f0
Showing 1 changed file with 82 additions and 1 deletion.
83 changes: 82 additions & 1 deletion test-case/check-alsabat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ set -e
# remove the existing alsabat wav files
rm -f /tmp/bat.wav.*

source $(dirname ${BASH_SOURCE[0]})/../case-lib/lib.sh
TESTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
TPLGREADER="$TESTDIR"/tools/sof-tplgreader.py

# shellcheck source=case-lib/lib.sh
source "$TESTDIR/case-lib/lib.sh"

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

OPT_OPT_lst['t']='tplg' OPT_DESC_lst['t']='tplg file, default value is env TPLG: $''TPLG'
OPT_PARM_lst['t']=1 OPT_VALUE_lst['t']="$TPLG"

func_opt_parse_option "$@"

pcm_p=${OPT_VALUE_lst['p']}
pcm_c=${OPT_VALUE_lst['c']}
frequency=${OPT_VALUE_lst['f']}
frames=${OPT_VALUE_lst['n']}
tplg=${OPT_VALUE_lst['t']}

if [ "$pcm_p" = "" ]||[ "$pcm_c" = "" ];
then
Expand All @@ -64,11 +72,84 @@ function __upload_wav_file
done
}

function set_pga_to_unity_gain ()
{
tmp=$(amixer controls | grep "$pga" | grep Volume)
search="name="
cname=${tmp#*$search}

# Get volume min and step to compute value for cset
# for 0 dB gain. The amixer line looks like
# "| dBscale-min=-50.00dB,step=1.00dB,mute=1"
scale=$(amixer cget name="$cname" | grep "dBscale" || true)
search="dBscale-min="
tmp=${scale#*$search}
min_db="${tmp%%dB*}"
search="step="
tmp=${scale#*$search}
step_db="${tmp%%dB*}"

# Get multiplied by 100 values by removing decimal dot
min_x100="${min_db//.}"
step_x100="${step_db//.}"
val=$(printf %d "$(((-min_x100) / step_x100))")

# Apply the computed value for requested gain
amixer cset name="$cname" "$val"
}

function set_pgas_list_to_unity_gain ()
{
if [[ -z "$1" ]]; then
return
fi

for pga in $1; do
dlogi "Set $pga"
set_pga_to_unity_gain "$pga"
done
}

function get_snd_base ()
{
tmp=${1#*"hw:"}
ncard="${tmp%%,*}"
ndevice="${tmp#*,}"
echo "/dev/snd/pcmC${ncard}D${ndevice}"
}

function get_play_snd ()
{
tmp=$(get_snd_base $1)
echo ${tmp}p
}

function get_capture_snd ()
{
tmp=$(get_snd_base $1)
echo ${tmp}c
}

# check the PCMs before alsabat test
dlogi "check the PCMs before alsabat test"
[[ $(aplay -Dplug$pcm_p -d 1 /dev/zero -q) ]] && die "Failed to play on PCM: $pcm_p"
[[ $(arecord -Dplug$pcm_c -d 1 /dev/null -q) ]] && die "Failed to capture on PCM: $pcm_c"

# Set PGAs for PCMs to 0 dB value
test -n "$(command -v $TPLGREADER)" || {
die "Command $TPLGREADER is not available."
}

test -n "$tplg" || die "Use -t or set environment variable TPLG to current topology"
dlogi "Getting playback PGA information"
play_snd=$(get_play_snd "$pcm_p")
PLAY_PGA=$($TPLGREADER "$tplg" -f "snd:$play_snd" -d pga -v)
set_pgas_list_to_unity_gain "$PLAY_PGA"
dlogi "Getting capture PGA information"
cap_snd=$(get_capture_snd "$pcm_c")
CAP_PGA=$($TPLGREADER "$tplg" -f "snd:$cap_snd" -d pga -v)
set_pgas_list_to_unity_gain "$CAP_PGA"

# alsabat test
# different PCMs may support different audio formats(like samplerate, channel-counting, etc.).
# use plughw to do the audio format conversions. So we don't need to specify them for each PCM.
Expand Down

0 comments on commit 45fe2f0

Please sign in to comment.