Skip to content

Commit 64eacc1

Browse files
committed
TinyAlsa: Add support for testing using tinycap and tinyplay..
The parameter has been added to the lib.sh library, allowing the selection of tinyalsa as the testing tool. Signed-off-by: Arkadiusz Cholewinski <arkadiuszx.cholewinski@intel.com>
1 parent e7c456d commit 64eacc1

File tree

2 files changed

+69
-8
lines changed

2 files changed

+69
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ Usage: ./check-playback.sh [OPTION]
5353
...
5454
```
5555

56-
Some tests support SOF_ALSA_OPTS, SOF_APLAY_OPTS and SOF_ARECORD_OPTS,
56+
Some tests support SOF_TINY_ALSA, SOF_ALSA_OPTS, SOF_APLAY_OPTS and SOF_ARECORD_OPTS,
5757
work in progress. Where supported, optional parameters in SOF_APLAY_OPTS
5858
and SOF_ARECORD_OPTS are passed to all aplay and arecord
5959
invocations. SOF_ALSA_OPTS parameters are passed to both aplay and
60-
arecord. Warning these environments variables do NOT support parameters
60+
arecord. SOF_TINY_ALSA is used to select tinyalsa as testing tool.
61+
Set SOF_TINY_ALSA to true to force using tinyasla.
62+
Warning these environments variables do NOT support parameters
6163
with whitespace or globbing characters, in other words this does NOT
6264
work:
6365

case-lib/lib.sh

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,17 +752,76 @@ 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_TINY_ALSA:
756+
# If set to true, the function will use the tinyalsa instead of alsa to test audio.
757+
# When SOF_TINY_ALSA is not true, the functions use alsa with the provided ALSA options.
758+
759+
# Function to extract the card number and device number from $dev option (e.g., hw:0,10)
760+
parse_audio_device() {
761+
# Extract the card number (e.g., "0" from hw:0,10)
762+
card_nr=$(printf '%s' "$dev" | cut -d ':' -f2 | cut -d ',' -f1)
763+
764+
# Extract the device number (e.g., "10" from hw:0,10)
765+
dev_nr=$(printf '%s' "$dev" | cut -d ',' -f2)
766+
}
767+
768+
# Function to extract the numeric format value from the $fmt_elem option
769+
extract_format_number() {
770+
# (e.g., extracting '16' from 'S16_LE')
771+
# shellcheck disable=SC2154
772+
format=$(printf '%s' "$fmt_elem" | grep '[0-9]\+' -o)
773+
}
774+
775+
# Initialize the parameters using for audio testing.
776+
initialize_audio_params()
777+
{
778+
# shellcheck disable=SC2034
779+
channel=$(func_pipeline_parse_value "$idx" channel)
780+
# shellcheck disable=SC2034
781+
rate=$(func_pipeline_parse_value "$idx" rate)
782+
# shellcheck disable=SC2034
783+
fmts=$(func_pipeline_parse_value "$idx" fmt)
784+
# shellcheck disable=SC2034
785+
dev=$(func_pipeline_parse_value "$idx" dev)
786+
# shellcheck disable=SC2034
787+
pcm=$(func_pipeline_parse_value "$idx" pcm)
788+
# shellcheck disable=SC2034
789+
type=$(func_pipeline_parse_value "$idx" type)
790+
# shellcheck disable=SC2034
791+
snd=$(func_pipeline_parse_value "$idx" snd)
792+
# shellcheck disable=SC2034
793+
duration=$(func_pipline_parse_value "$idx" duration)
794+
795+
if [[ "$SOF_TINY_ALSA" = true ]]; then
796+
parse_audio_device
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_TINY_ALSA" = true ]]; then
803+
dlogc "tinyplay $*"
804+
sox -n -r "$rate" -c "$channel" noise.wav synth "$duration" white
805+
tinyplay -D "$card_nr" -d "$dev_nr" -i wav noise.wav
806+
else
807+
dlogc "aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $*"
808+
# shellcheck disable=SC2086
809+
aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS "$@"
810+
fi
760811
}
812+
761813
arecord_opts()
762814
{
763-
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
764-
# shellcheck disable=SC2086
765-
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
815+
816+
if [[ "$SOF_TINY_ALSA" = true ]]; then
817+
dlogc "tinycap $*"
818+
extract_format_number
819+
tinycap "$file" -D "$card_nr" -d "$dev_nr" -c "$channel" -t "$duration" -r "$rate" -b "$format"
820+
else
821+
dlogc "arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $*"
822+
# shellcheck disable=SC2086
823+
arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS "$@"
824+
fi
766825
}
767826

768827
die()

0 commit comments

Comments
 (0)