@@ -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+
755800aplay_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+
761813arecord_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
768827die ()
0 commit comments