#!/usr/local/plan9/bin/rc

rfork s
if(~ $debugjuke yes) echo >[1=2] jukeplay rx - $jukerx - file $*
switch($1){
case *.ogg
	# with oggdec 1.0.1 (vorbis-tools 1.1.1) can read from stdin and output pcm 
	$jukerx cat $1 | oggdec -Q -R -b 16 -o /dev/stdout - 
case *.m4a
	# with my local changes to faad, can play aac files (not mp4)
	# from standard input, so run faad on the remote machine
	# to extract an aac stream and stick *that* in your pipe and play it.
	$jukerx faad -q -a - $1 | faad -q -f2 -b1 -s44100 -d -w - 
case *.mp3
	# can use "mpg123 -s - $1" here, but doesn't work well
	# when file is standard input.  some small skips at 
	# beginning and occasional very large skips.
	# mpg321 is similarly broken (same code base).
	# madplay works well.
	$jukerx cat $1 | madplay -q -S -o raw:/dev/stdout - 
case *.flac
	# reset endianness and sign in need.
	$jukerx cat $1 | flac -d -c -s --force-raw-format --endian'='little \
		--sign'='signed >[2]/dev/null
case *
	echo jukeplay: unrecognized file extension $1 >[1=2]
	exit oops
}
