Skip to content

Commit ae69045

Browse files
committed
TinyAlsa: Add support for tinyAlsa.
Add support for tinyALSA and update env-check and README file. Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
1 parent e7c456d commit ae69045

File tree

3 files changed

+120
-22
lines changed

3 files changed

+120
-22
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ expect alsa-utils python3 python3-construct python3-graphviz
1818
```
1919
sudo apt install expect alsa-utils python3 python3-construct python3-graphviz
2020
```
21+
If you would like to use tinyALSA for testing, install tinyALSA and SoX.
22+
- How to install tinyALSA: https://github.com/tinyalsa/tinyalsa
23+
- To install SoX run below command:
24+
```
25+
sudo apt-install sox
26+
```
2127
#### user group
2228
sudo adm audio
2329

@@ -52,12 +58,14 @@ Usage: ./check-playback.sh [OPTION]
5258
2020-03-19 22:13:32 UTC [COMMAND] aplay -q --fatal-errors -Dhw:0,0 -r 48000 -c 2 -f S16_LE -d 4 /dev/zero -v -q
5359
...
5460
```
55-
56-
Some tests support SOF_ALSA_OPTS, SOF_APLAY_OPTS and SOF_ARECORD_OPTS,
57-
work in progress. Where supported, optional parameters in SOF_APLAY_OPTS
58-
and SOF_ARECORD_OPTS are passed to all aplay and arecord
59-
invocations. SOF_ALSA_OPTS parameters are passed to both aplay and
60-
arecord. Warning these environments variables do NOT support parameters
61+
Some tests support these environment variables (work in progress):
62+
- SOF_ALSA_TOOL is used to select the audio tool for testing.
63+
Set this variable to 'alsa' (default value) or 'tinyalsa' to choose between the ALSA and TinyALSA toolsets.
64+
- SOF_ALSA_OPTS contains optional parameters passed on both play and record.
65+
- SOF_APLAY_OPTS and SOF_ARECORD_OPTS contain optional parameters passed additionally on play and record respectively.
66+
These options are applied to the selected tool (alsa or tinyalsa) based on the value of SOF_ALSA_TOOL
67+
68+
Warning, these environment variables do NOT support parameters
6169
with whitespace or globbing characters, in other words this does NOT
6270
work:
6371

case-lib/lib.sh

Lines changed: 103 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -752,17 +752,88 @@ func_lib_check_pa()
752752
# However, 1. arrays would complicate the user interface 2. ALSA does not
753753
# seem to need arguments with whitespace or globbing characters.
754754

755+
# SOF_ALSA_TOOL:
756+
# This option is used for selecting tool for testing,
757+
# So far, supported tools are 'alsa' and 'tinyalsa'
758+
# To select appropriate tool, set SOF_ALSA_TOOL to one of above
759+
# before using 'aplay_opts' or 'arecord_opts' function.
760+
# Default is SOF_ALSA_TOOL='alsa'
761+
762+
763+
# Function to extract the card number and device number from $dev option (e.g., hw:0,10)
764+
parse_audio_device() {
765+
# Extract the card number (e.g., "0" from hw:0,10)
766+
card_nr=$(printf '%s' "$1" | cut -d ':' -f2 | cut -d ',' -f1)
767+
768+
# Extract the device number (e.g., "10" from hw:0,10)
769+
dev_nr=$(printf '%s' "$1" | cut -d ',' -f2)
770+
}
771+
772+
# Function to extract the numeric format value from the PCM sample formats
773+
# There is passes PCM sample format while using ALSA tool (arecord)
774+
# While using TinyALSA (tinycap -b) we need to convert PCM sample fomrat to bits.
775+
extract_format_number() {
776+
# (e.g., extracting '16' from 'S16_LE')
777+
format=$(printf '%s' "$1" | grep '[0-9]\+' -o)
778+
}
779+
780+
# Initialize the parameters using for audio testing.
781+
# shellcheck disable=SC2034
782+
initialize_audio_params()
783+
{
784+
local idx="$1"
785+
786+
channel=$(func_pipeline_parse_value "$idx" channel)
787+
rate=$(func_pipeline_parse_value "$idx" rate)
788+
fmts=$(func_pipeline_parse_value "$idx" fmt)
789+
dev=$(func_pipeline_parse_value "$idx" dev)
790+
pcm=$(func_pipeline_parse_value "$idx" pcm)
791+
type=$(func_pipeline_parse_value "$idx" type)
792+
snd=$(func_pipeline_parse_value "$idx" snd)
793+
794+
: "${SOF_ALSA_TOOL:="alsa"}"
795+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
796+
parse_audio_device "$dev"
797+
fi
798+
}
799+
755800
aplay_opts()
756801
{
757-
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
758-
# shellcheck disable=SC2086
759-
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
802+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
803+
# shellcheck disable=SC2154
804+
if ! sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white; then
805+
printf 'Error: sox command failed.\n' >&2
806+
return 1
807+
fi
808+
dlogc "tinyplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS -D $card_nr -d $dev_nr -i wav noise.wav"
809+
# shellcheck disable=SC2086
810+
tinyplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS -D "$card_nr" -d "$dev_nr" -i wav noise.wav
811+
elif [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
812+
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
813+
# shellcheck disable=SC2086
814+
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
815+
else
816+
die "Unknown ALSA tool: $SOF_ALSA_TOOL"
817+
fi
760818
}
819+
761820
arecord_opts()
762821
{
763-
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
764-
# shellcheck disable=SC2086
765-
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
822+
823+
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
824+
# shellcheck disable=SC2154
825+
# Global variable "$fmt_elem" from check_capture.sh test script
826+
extract_format_number "$fmt_elem"
827+
dlogc "tinycap $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $file -D $card_nr -d $dev_nr -c $channel -t $duration -r $rate -b $format"
828+
# shellcheck disable=SC2086
829+
tinycap $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$file" -D "$card_nr" -d "$dev_nr" -c "$channel" -t "$duration" -r "$rate" -b "$format"
830+
elif [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
831+
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
832+
# shellcheck disable=SC2086
833+
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
834+
else
835+
die "Unknown ALSA tool: $SOF_ALSA_TOOL"
836+
fi
766837
}
767838

768839
die()
@@ -952,7 +1023,7 @@ is_ipc4()
9521023
logger_disabled()
9531024
{
9541025
# Disable logging when available...
955-
if [ ${OPT_VAL['s']} -eq 0 ]; then
1026+
if [ "${OPT_VAL['s']}" -eq 0 ]; then
9561027
return 0
9571028
fi
9581029

@@ -1063,15 +1134,31 @@ set_alsa_settings()
10631134
reset_sof_volume()
10641135
{
10651136
# set all PGA* volume to 0dB
1066-
amixer -Dhw:0 scontrols | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1067-
while read -r mixer_name
1068-
do
1069-
if is_ipc4; then
1070-
amixer -Dhw:0 -- sset "$mixer_name" 100%
1071-
else
1072-
amixer -Dhw:0 -- sset "$mixer_name" 0dB
1073-
fi
1074-
done
1137+
if [[ "$SOF_ALSA_TOOL" = "alsa" ]]; then
1138+
amixer -Dhw:0 scontrols | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1139+
1140+
while read -r mixer_name
1141+
do
1142+
if is_ipc4; then
1143+
amixer -Dhw:0 -- sset "$mixer_name" 100%
1144+
else
1145+
amixer -Dhw:0 -- sset "$mixer_name" 0dB
1146+
fi
1147+
done
1148+
elif [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
1149+
tinymix -D0 controls | sed -e "s/^.*'\(.*\)'.*/\1/" |grep -E 'PGA|gain' |
1150+
1151+
while read -r mixer_name
1152+
do
1153+
if is_ipc4; then
1154+
tinymix -D0 set "$mixer_name" 100%
1155+
else
1156+
tinymix -D0 set "$mixer_name" 0dB
1157+
fi
1158+
done
1159+
else
1160+
echo "Unknown alsa tool $SOF_ALSA_TOOL"
1161+
fi
10751162
}
10761163

10771164
DO_PERF_ANALYSIS=0

env-check.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ out_str="" check_res=0
8383
printf "Checking for some OS packages:\t\t"
8484
func_check_pkg expect
8585
func_check_pkg aplay
86+
func_check_pkg sox
87+
func_check_pkg tinycap
88+
func_check_pkg tinyplay
8689
func_check_pkg python3
8790
# jq is command-line json parser
8891
func_check_pkg jq

0 commit comments

Comments
 (0)