#!/bin/sh
#
# RJP 28.9.2025  audio card test script for FreeBSD
# Packages xterm and yad must be installed
#
# 
cat /dev/sndstat | awk '{print $1,$3,$4,$5,$6}' > /tmp/adevice-full.txt
sed -i -e ''' s/Installed//g' /tmp/adevice-full.txt
sed -i -e ''' s/No installed from userspace.//g' /tmp/adevice-full.txt
AUDIO=$(/tmp/adevice-full.txt)
choose=$(cat /tmp/adevice-full.txt | \
yad --list --text="Choose audio device" --title="Choose audio device" --height=500 --width=600 --center \
--column="")
--button=Exit:1
cat "$choose" 2> /tmp/audio2.txt
cat /tmp/audio2.txt | awk '{print $2}' > /tmp/audiodevice
tr -dc '0-9' < /tmp/audiodevice > /tmp/audio.txt

yad --center --width=300 --height=100 --text-align=center --title="QUESTION" --text="Test selected card"
if [ $? = 0 ];
then
yad --center --width=700 --height=200 --text-align=center --title="MESSAGE" --text="        INFO:

If you hear the noise, /dev/dsp$(cat /tmp/audio.txt) should be workable audio output. Press Ctrl c above Terminal to stop test noise if not stopped." | xterm -e "cat /dev/random > /dev/dsp$(cat /tmp/audio.txt)" & sleep 5s; kill $!
else
exit 0

fi
sleep 1
cd /tmp && rm audio2.txt audio.txt adevice-full.txt audiodevice adevice-full.txt-e
