#! /bin/tcsh

# Define input and output

set INP = $1
set OUT = $2

# Extract MFCC, pitch, and voicing class

../bin/ExtAdvFrontEnd -q -F RAW -fs 8 $INP $OUT.ftr_o $OUT.pit_o $OUT.vc_o

# Encode 

#../bin/ExtCoder_VAD $OUT.ftr_o $OUT.pit_o $OUT.vc_o $OUT.bs_o $OUT.pit_q_o $OUT.txt -freq 8 -VAD
../bin/ExtCoder $OUT.ftr_o $OUT.pit_o $OUT.vc_o $OUT.bs_o $OUT.pit_q_o $OUT.txt -freq 8 -VAD


# Transmit through the channel

cp $OUT.bs_o $OUT.bs


# Decode

#../bin/ExtDecoder_VAD $OUT.bs $OUT.ftr_e $OUT.pit_q_e $OUT.vc_e $OUT.es -VAD
../bin/ExtDecoder $OUT.bs $OUT.ftr_e $OUT.pit_q_e $OUT.vc_e $OUT.es -VAD


# Handle errors

../bin/error_handle $OUT.ftr_e $OUT.pit_q_e $OUT.vc_e $OUT.es $OUT.ftr $OUT.pit_q $OUT.vc_q $OUT.loge


# Track pitch

../bin/PitchTrack -ip $OUT.pit_q -ie $OUT.loge -op $OUT.pit -iv $OUT.vc_q -ov $OUT.vc -q


# Reconstruct

../bin/Reconstruct -cep $OUT.ftr -pit $OUT.pit -vc $OUT.vc -out $OUT.rec -s8


# Cleanup

/bin/rm -f $OUT.ftr_o $OUT.pit_o $OUT.vc_o
/bin/rm -f $OUT.bs_o $OUT.txt $OUT.pit_q_o
/bin/rm -f $OUT.bs $OUT.pit_q_e $OUT.vc_e $OUT.es
/bin/rm -f $OUT.loge $OUT.ftr $OUT.pit_q $OUT.vc_q

# Do not remove the following files if they are needed for recognition
/bin/rm -f $OUT.ftr_e $OUT.pit $OUT.vc *.vad

