#!/bin/sh

# This script is a part of Rbook package.
# It's purpose is to encode sound stream coming to the standard input
# to mp3.
#
# -f <value> -- Sampling frequency of the original sound stream in kHz.
# -b <value> -- Wanted bitrate.
# -v <value> -- Volume scale factor.

# Output file name must be determined in the command line.

# Default parameters:
FREQUENCY=10000
BITRATE=64
VOLUME=1.0

# Command line parsing:
while test $1
do case $1 in
     -f) shift
         FREQUENCY=$1
         ;;
     -b) shift
         BITRATE=$1
         ;;
     -v) shift
         VOLUME=$1
         ;;
      *) file=$1
         ;;
   esac
   shift
done

sox -t raw -r $FREQUENCY -b -s -c 1 - -t wav -r 16000 -b -s -c 1 - 2> /dev/null | lame -b $BITRATE --scale $VOLUME -F -q 0 - $file > /dev/null 2> /dev/null
