#!/bin/bash

for wave in sine white-noise pink-noise gaussian-noise
do
	echo > ${wave}.dat
	for n in 1 2 4 8 16
	do
		cmdline="gst-launch adder name=add ! audio/x-raw-float,rate=16384,width=64 ! fakesink num-buffers=10000 sync=false $(yes " audiotestsrc wave=${wave} ! add." | head -n $n)"
		echo $n $wave
		(time -p ${cmdline}) 2>&1 | sed -n 's/real //p' >> ${wave}.dat
	done
done

python <<EOF
import pylab
n = (1, 2, 4, 8, 16)
for wave in ("gaussian-noise", "white-noise", "pink-noise", "sine"):
	data = pylab.loadtxt(wave + ".dat")
	pylab.semilogy(n, data, '-o', label=wave)
pylab.xlabel('number of instances of audiotestsrc')
pylab.ylabel('running time (s)')
pylab.grid()
pylab.legend(loc='upper left')
pylab.title('audiotestsrc benchmark')
pylab.savefig('bench.pdf')
EOF