tomclegg.net


Diary
Examples
Hire Tom
Mostly Mozart
Patches
School
Scrapbook
Software
    allaboutme
    byteswap
    checksocks
    djbdns-ipv6
    dsprec
    fresnel
    fresnel
  >logger<
    mail-transport-agent
    maildirpop3d
    mp3cat
    qmail-bmf-wildcard
    rawrms
    stationbreak
Telephones




colocation
comments
davidireland
edsgranola
faq
funsites
goodlooking
goodmovies
google-earth-saucy-amd64
houserules
liberating
resume
resume2
scratch
shopping
snacks
todo
university
warisbogus

Audio Logger and MP3 Streaming Service
Posted May 3, 2003

Install FreeBSD (make sure you install the kernel source code).

Log in as root.

Build a new kernel with sound support, install it, and reboot to load it.

cd /usr/src/sys/i386/conf
cp -p -i GENERIC MYKERNEL
echo device pcm >>MYKERNEL
config MYKERNEL
cd ../../compile/MYKERNEL
make
make install
reboot

Install psmisc from ports (optional).

cd /usr/ports/sysutils/psmisc
make install clean

Install daemontools from ports.

cd /usr/ports/sysutils/daemontools
make install clean

Arrange for svscan to start automatically on reboot.

mkdir /service /var/service
cat <<'EOF' >/usr/local/etc/rc.d/000.svscan.sh
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
case "$1" in
start)
  exec env - PATH="$PATH" \
  svscan /service 2>/dev/null >/dev/null &
  ;;
stop)
  killall svscan
  cd /service
  svc -dx *
  svc -dx */log
  ;;
esac
EOF
chmod +x /usr/local/etc/rc.d/000.svscan.sh

Start svscan by rebooting, or by doing this:

/usr/local/etc/rc.d/000.svscan.sh start

Install ucspi-tcp from ports.

cd /usr/ports/sysutils/ucspi-tcp && make install clean

Install lame from ports.

cd /usr/ports/audio/lame && make install clean

Install dsprec and mp3cat.

cd /usr/local/src
fetch http://tomclegg.net/software/dsprec-0.2.tar.gz
tar xzf dsprec-0.2.tar.gz
cd dsprec-0.2
make
make install

cd /usr/local/src
fetch http://tomclegg.net/software/mp3cat-0.4.tar.gz
tar xzf mp3cat-0.4.tar.gz
cd mp3cat-0.4
make
make install

Set up a logging service. Raw audio is read from /dev/dsp. 32 kbps MP3 files are stored in /var/log/mp3log/. A separate cleaning service in /var/service/mp3log-clean/ removes old MP3 files.

cd /var/service
pw useradd mp3log -d /nonexistent -s /usr/bin/true
pw useradd mp3logl -d /nonexistent -s /usr/bin/true
mp3log-conf mp3log mp3logl /var/service/mp3log /var/log/mp3log /dev/dsp 32

Start the MP3 logging and cleaning services.

chown root:mp3log /dev/dsp
chmod 660 /dev/dsp
ln -s /var/service/mp3log /service/
ln -s /var/service/mp3log-clean /service/

Optional: set up an MP3 streaming service.

cd /var/service
pw useradd mp3stream -d /nonexistent -s /usr/bin/true
pw useradd mp3streaml -d /nonexistent -s /usr/bin/true
mp3stream-conf mp3stream mp3streaml /var/service/mp3stream /var/log/mp3log YOUR.IP.ADDR.HERE

Start the MP3 stream service.

ln -s /var/service/mp3stream /service/

Wait 5 seconds for svscan to notice the mp3stream service. If you installed psmisc then pstree -u should show something like this:

     |-svscan-+-supervise---multilog(mp3streaml)
     |        |-supervise---tcpserver(mp3stream)
     |        |-supervise---sh(mp3log)---sleep
     |        |-supervise---multilog(mp3logl)
     |        `-supervise---sh(mp3log)-+-dsprec
     |                                 |-lame
     |                                 `-mp3cat

Listen to the stream by opening http://YOUR.IP.ADDR.HERE/ in your sound player program (mpg123, Winamp, Sonique, etc.)

uname -a | mail -s 'my logger works!' tom@tomclegg.net