#!/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=10.3
BITRATE=32
VOLUME=1.0

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

exec 2>&1 >/dev/null

# Use VBR
# exec lame -S -r -s 16 --bitwidth 16 --signed -m m --scale "$VOLUME" --vbr-new -V 0 --abr "$BITRATE" - "$file"

# For hardware players
exec lame -S -r -s 16 --bitwidth 16 -m m --scale "$VOLUME" -b "$BITRATE" -F -q 0 - "$file"
