#!/bin/sh
# Generate test audio files in a variety of formats.

input="$1"
if [ "$input" = "" ]; then
	echo "Usage: make-test-files INPUT.wav"
	exit 1
fi

prefix="test-files/test"
rm -fr test-files
mkdir -p test-files

for chans in 1 2 4; do
for rate in 8000 44100 48000 96000; do
for end in b l; do
for fmt in u8 s16 s24 s32 f32; do
	a="-c $chans -r $rate"

	if [ $fmt = 8 -a $end != b ]; then
		continue
	fi

	case $end in
	b)
		a="$a --endian big"
		;;
	l)
		a="$a --endian little"
		;;
	esac

	case $fmt in
	f*)
		a="$a -e floating-point"
		;;
	u*)
		a="$a -e unsigned-integer"
		;;
	s*)
		a="$a -e signed-integer"
		;;
	esac
	a="$a -b `echo $fmt | sed 's,^.,,'`"

	output="${prefix}-${chans}-${rate}-${fmt}-${end}"
	echo "Creating $output"
	sox "$input" $a -t wav "${output}.wav"

	# Many of these won't succeed.
	flac "${output}.wav"
	shorten "${output}.wav" "${output}.shn"
	# In libavcodec, .ra is planar, .shn isn't.
	ffmpeg -i "${output}.wav" "${output}.ra"
	oggenc "${output}.wav"
	lame -V2 "${output}.wav"
	opusenc "${output}.wav" "${output}.opus"
	# should also do: aac, mp2, mpc, speex
done
done
done
done
