#!/bin/bash
echo "recording started"
if test -z $1; then
 echo Use: rec-line-in.sh num_seconds mp3-filename
 exit
fi

if test -z $2; then
 echo Use: rec-line-in.sh num_seconds mp3-filename
 exit
fi

TMPWAVF=/home/music/tmp/rectmp.wav 
TMPMP3F=/home/music/tmp/rectmp.mp3 

#sox -v 1.8 -t ossdsp -r 44100 -w -c2 /dev/dsp -t wav - | notlame -h -b 96 - $2 &

sox -v 1.8 -t ossdsp -r 44100 -w -c2 /dev/dsp -t wav $TMPWAVF &

REC_PID=$!
#echo "PID is $REC_PID"
#echo "falling asleep"
sleep $1
#echo "waking up"
kill  $REC_PID

nice -19 lame -S -h -b 112 $TMPWAVF $TMPMP3F
# -S: silent, -h: high-quality

mv $TMPMP3F $2
rm $TMPWAVF

#
