#!/bin/sh

# (todo) use a function

if [ -z "$1" ]; then
 echo "Usage: ./upload_varichain.sh <path_to_sample_directory> <remote_name>"
 exit
fi

if [ -z "$2" ]; then
 echo "Usage: ./upload_varichain.sh <path_to_sample_directory> <remote_name>"
 exit
fi

SAMPLE_DIR="$1"
REMOTE_NAME="$2"

shift
shift


pad=0
#pad=2000

pushd . && cd "$SAMPLE_DIR" && mkdir -p 48k && cd 48k && find ../ -name \*.wav -print0 | xargs -0 printf "%s\n" >srclist.txt && rm -f filelist.txt && while read d ; do sox "${d}" -r 48000 -b 16 -c 1 "`basename "$d"`"; echo "`basename "$d"`" >>filelist.txt ; done <srclist.txt && tks app:sds -varichain filelist.txt -name "$REMOTE_NAME" -pad $pad -indev "$SDS_INDEV" -outdev "$SDS_OUTDEV" $* && cd .. && ls -1 48k/*.wav && popd

