Here is some code. For you.
Shell script I saved as ~/bin/m4rify to convert arbitrary audio files to iPhone ringtones:
#! /bin/bash
if [ $1p == 'p' ]
then
echo USAGE: $0 filename.mp3
exit
fi
out_file=${1%%.*}.m4r
tmp_file=$1.converttemp
mplayer -ao pcm $1 -ao pcm:file=$tmp_file
faac $tmp_file -o $out_file -w
rm $tmp_file
Works fine in Ubuntu.