#!/bin/bash

if [ ${#} -ne "2" ] ; then
	echo "Usage: ${0} <input file> <output file>"
	return 1
fi

TMPFILE="convert.tmp"

ffmpeg -i ${1} -f s16be -ar 16k -ac 1 -acodec pcm_s16be ${TMPFILE}
SIZE=$(( $(stat -c "%s" ${TMPFILE}) / 2 ))
echo -ne "\0$(printf %o $(($SIZE % 256)) )\0$(printf %o $(( ($SIZE / 256) % 256)) )\0$(printf %o $(( ($SIZE / 256**2) % 256)) )\0$(printf %o $(( ($SIZE / 256**3) % 256)) )" | cat - ${TMPFILE} > ${2}
rm ${TMPFILE}
