#!/bin/sh

# Sample script for interfacing to the TCT datlink program naplay.

# Run InfoAudio to determine the format of an audio file.  This script
# parses that information and sets up the appropriate parameters for naplay.

if [ $# -gt 1 ]; then
  echo "Error: Only a single audio file is allowed" 1>&2
  exit 1
fi

file=$1
line=`InfoAudio -b $file | sed -n 's/^File name: //p; \
	s/^Header length: //p; s/^Sampling frequency: //p; \
	s/^No. channels: //p; s/^Data type: //p; \
	s/^Data swap: //p'`
if [ "$line" = "" ]; then
  exit 1
fi

set $line
file=$1
hlen=$2
sfreq=$3
nchan=$4
dtype=$5
dswap=$6

if [ "$dtype" = "mu-law8" ]; then
  encoding=ULAW
elif [ "$dtype" = "integer16" ]; then
  encoding=LINEAR
elif [ "$dtype" = "float32" ]; then
  encoding=IEEE
else
  echo "Error: Unknown data format" 1>&2
  exit 1
fi

if [ "$nchan" -eq 1 ]; then
  chan=mono
elif [ "$nchan" -eq 2 ]; then
  chan=stereo
else
  echo "Error: Unsupported number of channels" 1>&2
fi

# Test version, only echoes the command
echo naplay -c $encoding -f $dswap -o $chan -r ${hlen}: -s $sfreq $file
