@@ -752,17 +752,84 @@ 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+ # 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+ # (e.g., 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' " $dev " | cut -d ' :' -f2 | cut -d ' ,' -f1)
767+
768+ # Extract the device number (e.g., "10" from hw:0,10)
769+ dev_nr=$( printf ' %s' " $dev " | cut -d ' ,' -f2)
770+ }
771+
772+ # Function to extract the numeric format value from the $fmt_elem option
773+ extract_format_number () {
774+ # (e.g., extracting '16' from 'S16_LE')
775+ # shellcheck disable=SC2154
776+ format=$( printf ' %s' " $fmt_elem " | grep ' [0-9]\+' -o)
777+ }
778+
779+ # Initialize the parameters using for audio testing.
780+ initialize_audio_params ()
781+ {
782+ # shellcheck disable=SC2034
783+ channel=$( func_pipeline_parse_value " $idx " channel)
784+ # shellcheck disable=SC2034
785+ rate=$( func_pipeline_parse_value " $idx " rate)
786+ # shellcheck disable=SC2034
787+ fmts=$( func_pipeline_parse_value " $idx " fmt)
788+ # shellcheck disable=SC2034
789+ dev=$( func_pipeline_parse_value " $idx " dev)
790+ # shellcheck disable=SC2034
791+ pcm=$( func_pipeline_parse_value " $idx " pcm)
792+ # shellcheck disable=SC2034
793+ type=$( func_pipeline_parse_value " $idx " type)
794+ # shellcheck disable=SC2034
795+ snd=$( func_pipeline_parse_value " $idx " snd)
796+
797+ : ${SOF_ALSA_TOOL:= " alsa" }
798+ if [[ " $SOF_ALSA_TOOL " = " tinyalsa" ]]; then
799+ parse_audio_device
800+ fi
801+ }
802+
755803aplay_opts ()
756804{
757- dlogc " aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $* "
758- # shellcheck disable=SC2086
759- aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS " $@ "
805+ if [[ " $SOF_ALSA_TOOL " = " tinyalsa" ]]; then
806+ dlogc " tinyplay $* "
807+ # shellcheck disable=SC2154
808+ sox -n -r " $rate " -c " $channel " noise.wav synth " $duration " white
809+ tinyplay -D " $card_nr " -d " $dev_nr " -i wav noise.wav
810+ elif [[ " $SOF_ALSA_TOOL " = " alsa" ]]; then
811+ dlogc " aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $* "
812+ # shellcheck disable=SC2086
813+ aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS " $@ "
814+ else
815+ printf ' %s' " Unknown alsa tool: $SOF_ALSA_TOOL "
816+ fi
760817}
818+
761819arecord_opts ()
762820{
763- dlogc " arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $* "
764- # shellcheck disable=SC2086
765- arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $@ "
821+
822+ if [[ " $SOF_ALSA_TOOL " = " tinyalsa" ]]; then
823+ dlogc " tinycap $* "
824+ extract_format_number
825+ tinycap " $file " -D " $card_nr " -d " $dev_nr " -c " $channel " -t " $duration " -r " $rate " -b " $format "
826+ elif [[ " $SOF_ALSA_TOOL " = " alsa" ]]; then
827+ dlogc " arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $* "
828+ # shellcheck disable=SC2086
829+ arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS " $@ "
830+ else
831+ printf ' %s' " Unknown alsa tool: $SOF_ALSA_TOOL "
832+ fi
766833}
767834
768835die ()
0 commit comments