#!/bin/sh

# checksum tests to verify that captured audio is correct.

. $(dirname $0)/functions

TKINDS="mono stereo"
OFMTS_mono="wav raw w64"
OFMTS_stereo="wav w64"

ofiles=""
extractaudio_RFILES="call1_alaw call1_ulaw call1_g722 call1_g729 call1_gsm"

for tkind in ${TKINDS}
do
  if [ ${tkind} = "mono" ]
  then
    EXTRACTAUDIO_ARGS=""
    OFMTS="${OFMTS_mono}"
    CHFMT="m"
  else
    EXTRACTAUDIO_ARGS="-s"
    OFMTS="${OFMTS_stereo}"
    CHFMT="s"
  fi
  for rfile in ${extractaudio_RFILES}
  do
    for ofmt in ${OFMTS}
    do
      DFMTS=`cat extractaudio/extractaudio.${CHFMT}.${ofmt}.dfmts`
      for dfmt in ${DFMTS}
      do
        wfile="${rfile}.${tkind}.${dfmt}.${ofmt}"
        if [ -e "${wfile}" ]
        then
          rm "${wfile}"
        fi
        ${EXTRACTAUDIO} -F ${ofmt} -D ${dfmt} ${EXTRACTAUDIO_ARGS} ${rfile} ${wfile} 2>/dev/null >/dev/null || continue
        test -s ${wfile}
        report "${rfile} -> ${wfile}"
        sha256_verify ${wfile} extractaudio/extractaudio.checksums
      done
    done
  done
done
