@@ -1534,47 +1534,114 @@ restore_topology() {
15341534 check_topology
15351535}
15361536
1537+ # Check aplay output for warnings
1538+ # Arguments: 1-aplay output
1539+ check_for_aplay_warnings ()
1540+ {
1541+ # dlogi "$1"
1542+ if echo " $1 " | grep -q " Warning:" ; then
1543+ dlogw " Caught aplay warning! Look for previous logs."
1544+ return 1
1545+ fi
1546+ return 0
1547+ }
1548+
15371549# Play sound and record it
15381550# Arguments: 1-arecord options 2-aplay options
15391551play_and_record ()
15401552{
1541- dlogi " Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 ] and capture sound [arecord $1 ]"
1553+ errors=0
1554+
1555+ arecord_log=$( mktemp)
1556+ aplay_log=$( mktemp)
1557+ dlogi " Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 ] and capture sound [arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 ]"
1558+
15421559 # shellcheck disable=SC2086
1543- arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 & PID=$!
1560+ arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 2>&1 | tee " $arecord_log " &
1561+ PID=$!
1562+ sleep 1
1563+
15441564 # shellcheck disable=SC2086
1545- aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2
1546- wait $PID
1565+ aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 2>&1 | tee " $aplay_log "
1566+ aplay_ret=${PIPESTATUS[0]}
1567+ [ $aplay_ret -ne 0 ] && errors=$(( errors+ 1 ))
1568+
1569+ wait " $PID "
1570+ arecord_ret=$?
1571+ [ $arecord_ret -ne 0 ] && errors=$(( errors+ 1 ))
1572+
15471573 sleep 1
1574+ arecord_output=$( < " $arecord_log " )
1575+ aplay_output=$( < " $aplay_log " )
1576+
1577+ check_for_aplay_warnings " $aplay_output " || errors=$(( errors+ 1 ))
1578+
1579+ rm -f " $arecord_log " " $aplay_log "
1580+
1581+ if [ " $errors " = 0 ]; then
1582+ return 0
1583+ fi
1584+ return 1
15481585}
15491586
1550- # Analyze files to look for glitches.
1587+ # # Play sound and record it
1588+ # # Arguments: 1-arecord options 2-aplay options
1589+ # play_and_record()
1590+ # {
1591+ # errors=0
1592+ # dlogi "Play [aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2] and capture sound [arecord $1]"
1593+ # # shellcheck disable=SC2086
1594+ # arecord $SOF_ALSA_OPTS $SOF_ARECORD_OPTS $1 & PID=$!
1595+ # # shellcheck disable=SC2086
1596+ # aplay_output=$(aplay $SOF_ALSA_OPTS $SOF_APLAY_OPTS $2 2>&1) || errors=$((errors+1))
1597+ # wait $PID || errors=$((errors+1))
1598+ # sleep 1
1599+ # check_for_aplay_warnings "$aplay_output" || errors=$((errors+1))
1600+
1601+ # if [ "$errors" = 0 ]; then
1602+ # return 0
1603+ # fi
1604+ # return 1
1605+ # }
1606+
1607+ # Analyze file to look for glitches.
15511608# Returns exit code 0 if there are no glitches, 1 if there are.
1552- # Arguments: the list of filenames
1609+ # Arguments: filename
15531610check_soundfile_for_glitches ()
15541611{
1555- glitched_files=0
1612+ if [ -f " $result_filename " ]; then
1613+ dlogi " Analyzing $result_filename file..."
1614+ if python3 " $SCRIPT_HOME " /tools/analyze-wav.py " $result_filename " ; then
1615+ dlogi " $result_filename file is correct"
1616+ else
1617+ dlogw " GLITCHED FILE: $result_filename "
1618+ return 1
1619+ fi
1620+ else
1621+ dlogw " MISSING FILE: $result_filename "
1622+ return 1
1623+ fi
1624+ }
1625+
1626+ # Check list of soundfiles for glitches
1627+ # Returns exit code 0 if there are no glitches, 1 if there are.
1628+ # Arguments: list of filenames
1629+ check_soundfiles_for_glitches ()
1630+ {
1631+ failures=0
15561632 # shellcheck disable=SC2154
15571633 for result_filename in " ${all_result_files[@]} "
15581634 do
1559- if [ -f " $result_filename " ]; then
1560- dlogi " Analyzing $result_filename file..."
1561- if python3 " $SCRIPT_HOME " /tools/analyze-wav.py " $result_filename " ; then
1562- dlogi " $result_filename file is correct"
1563- else
1564- dlogw " Found issues in $result_filename file"
1565- glitched_files=$(( glitched_files+ 1 ))
1566- fi
1567- else
1568- dlogw " $result_filename file not found, check for previous errors"
1569- glitched_files=$(( glitched_files+ 1 ))
1635+ if ! check_soundfile_for_glitches " $result_filename " ; then
1636+ failures=$(( failures+ 1 ))
15701637 fi
15711638 done
15721639
1573- if [ $glitched_files -eq 0 ]; then
1574- dlogi " Analysis finished, no issues found "
1640+ if [ " $failures " = 0 ]; then
1641+ dlogi " All files correct "
15751642 return 0
15761643 else
1577- dlogi " $glitched_files files corrupted"
1644+ dlogw " Found $failures corrupted files "
15781645 return 1
15791646 fi
15801647}
0 commit comments