#!/bin/sh
#
# This script takes a filename as an argument, and outputs signed,
# little-endian, 16-bit, 2 channel audio on standard output. Errors
# to standard error.
#
# You can adjust this script yourself to customise the support for
# different file formats and codecs.

FILE=$1
TYPE=`echo "$FILE" | sed -e 's/^.*\.//'`

case "$TYPE" in

'ogg')
    echo "Calling Ogg decoder..." >&2
    exec oggdec -Q --bits 16 --endianness 0 --sign 1 --raw --output - "$FILE"
    ;;

'aac')
    echo "Calling AAC decoder..." >&2
    exec faad -b 1 -f 2 -w "$FILE"
    ;;

'cdaudio')
    echo "Calling CD extract..." >&2
    exec cdparanoia -r `cat "$FILE"` -
    ;;

'mp3')
    echo "Calling MP3 decoder..." >&2
    exec mpg123 -q -s "$FILE"
    ;;

'flac')
    echo "Calling FLAC decoder..." >&2
    exec flac -d -c -s --force-raw-format --sign=signed --endian=little "$FILE"
    ;;

*)
    echo "Calling fallback decoder..." >&2
    exec ffmpeg -v 0 -i "$FILE" -f s16le -
    #exec sox "$FILE" -t raw -s -
    ;;

esac
