#!/bin/bash
set -e

# SoX Resampler Library       Copyright (c) 2007-15 robs@users.sourceforge.net
# Licence for this file: LGPL v2.1                  See LICENCE for details.

# Tests rate conversion time for qualities 0..7 & variable-rate.

tool=./3-options-input-fn
ext=f32; e=0
c=2
q1=0; q2=7
rates="48000 77773 96000"

for rate0 in $rates; do
	rate1=$rate0
	rate2=44100
	for n in 1 2; do
		rate1n=`expr $rate1 / 2`
		sox -r $rate1 -n -c $c 0.$ext synth 5: sin 0:$rate1n gain -1

		for q in `seq $q1 $q2`; do
			echo $rate1 '-->' $rate2 c=$c q=$q
			time $tool $rate1 $rate2 $c $e $e $q < 0.$ext > /dev/null;
		done

		echo $rate1 '-->' $rate2 c=$c q=v
		time $tool $rate1 $rate2 $c $e $e 4 20 < 0.$ext > /dev/null

		rate1=44100
		rate2=$rate0
	done
done

rm 0.$ext
