-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathcheck-smart-amplifier.sh
More file actions
executable file
·117 lines (101 loc) · 4.32 KB
/
check-smart-amplifier.sh
File metadata and controls
executable file
·117 lines (101 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2020 Intel Corporation. All rights reserved.
set -e
##
## Case Name: check-smart-amplifier
## Preconditions:
## require python3-numpy, python3-scipy and python3-matplotlib
## to be installed, or wavetool.py will not work
## Description:
## test smart amplifier with customized wavetool.py,
## this tool will do binary comparison of reference wave file
## and recorded wave file.
## Case step:
## 1. acquire playback & capture pipelines with smart_amp component
## 2. generate playback wave file (default 997Hz sine wave)
## 3. play reference wave file through smart_amp playback pipeline
## and record it back through smart_amp capture pipeline
## 4. compare channel 0/1, 2/3 of recorded wave with reference wave
## Expect result:
## 1. reference wave and recorded wave are binary same
## 2. delay in recorded wave less than 5ms
##
# source from the relative path of current folder
# shellcheck source=case-lib/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")"/../case-lib/lib.sh
# What we want here is the "$TPLG" string
# shellcheck disable=SC2016
OPT_NAME['t']='tplg' OPT_DESC['t']='tplg file, default value is env TPLG: $TPLG'
# $TPLG is assigned outside this script as env variable
# shellcheck disable=SC2153
OPT_HAS_ARG['t']=1 OPT_VAL['t']="$TPLG"
OPT_NAME['s']='sof-logger' OPT_DESC['s']="Open sof-logger trace the data will store at $LOG_ROOT"
OPT_HAS_ARG['s']=0 OPT_VAL['s']=1
OPT_NAME['l']='loop' OPT_DESC['l']='loop count'
OPT_HAS_ARG['l']=1 OPT_VAL['l']=1
OPT_NAME['d']='duration' OPT_DESC['d']='playback/capture duration in second'
OPT_HAS_ARG['d']=1 OPT_VAL['d']=6
# We need OPT_NAME to tell what the command option is, and OPT_HAS_ARG to tell
# how many arguments this option required, though they are not used.
# shellcheck disable=SC2034
OPT_NAME['F']='fmts' OPT_DESC['F']='Iterate all supported formats'
# shellcheck disable=SC2034
OPT_HAS_ARG['F']=0 OPT_VAL['F']=0
func_opt_parse_option "$@"
duration=${OPT_VAL['d']}
loop_cnt=${OPT_VAL['l']}
tplg=${OPT_VAL['t']}
start_test
logger_disabled || func_lib_start_log_collect
func_pipeline_export "$tplg" "smart_amp:any"
[ "$PIPELINE_COUNT" == "2" ] || die "Only detect $PIPELINE_COUNT pipeline(s) from topology, but two are needed"
for idx in $(seq 0 $((PIPELINE_COUNT - 1)))
do
type=$(func_pipeline_parse_value "$idx" type)
if [ "$type" == "playback" ]; then
pb_chan=$(func_pipeline_parse_value "$idx" ch_max)
pb_rate=$(func_pipeline_parse_value "$idx" rate)
pb_dev=$(func_pipeline_parse_value "$idx" dev)
else
cp_chan=$(func_pipeline_parse_value "$idx" ch_max)
cp_rate=$(func_pipeline_parse_value "$idx" rate)
cp_fmt=$(func_pipeline_parse_value "$idx" fmt)
cp_fmts=$(func_pipeline_parse_value "$idx" fmts)
cp_dev=$(func_pipeline_parse_value "$idx" dev)
fi
done
fmts="$cp_fmt"
if [ "${OPT_VAL['F']}" = '1' ]; then
fmts="$cp_fmts"
fi
for i in $(seq 1 "$loop_cnt")
do
for fmt in $fmts
do
dlogi "Testing: iteration $i of $loop_cnt with $fmt format"
# S24_LE format is not supported
if [ "$fmt" == "S24_LE" ]; then
continue
fi
# generate wave file
tmp_dir="/tmp"
file="$tmp_dir/smart_amp_test_${fmt%_*}.wav"
recorded_file="$tmp_dir/smart_amp_recorded_${fmt%_*}.wav"
wavetool.py -gsinusoid -A0.8 -B"${fmt%_*}" -o"$file"
dlogc "aplay -D$pb_dev -r $pb_rate -c $pb_chan -f $fmt -d $duration -v -q $file &"
aplay -D"$pb_dev" -r "$pb_rate" -c "$pb_chan" -f "$fmt" -d "$duration" -v -q "$file" &
dlogc "arecord -D$cp_dev -r $cp_rate -c $cp_chan -f $fmt -d $duration -v -q $recorded_file"
arecord -D"$cp_dev" -r "$cp_rate" -c "$cp_chan" -f "$fmt" -d "$duration" -v -q "$recorded_file"
dlogi "Comparing recorded wave and reference wave"
wavetool.py -a"smart_amp" -R"$recorded_file" || {
# upload the failed wav file, and die
find /tmp -maxdepth 1 -type f -name "$(basename "$recorded_file")" -size +0 -exec cp {} "$LOG_ROOT/" \;
die "wavetool.py exit with failure"
}
# clean up generated wave files
rm -rf "$file" "$recorded_file"
sleep 2
done
done
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"