Search:  
Gentoo Wiki

HOWTO_Largefile_Sound_Recording_and_Cutting

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc


Please format this article according to the guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article


Contents

Preresiquites

Introduction

Months ago I felt the need to record my favorite radio programs, and archive them for a later date. These programs play at different times throughout the day. I have one server, which is records daily, all day. It took me a while to figure out the perfect way to get this done. The way I have found puts a great amount of buffer on the stream, to make sure I don't get xruns.

This HOWTO is also limited in scope. Recording will happen in the 'raw' format, at channels 2, srate 44100, interleaved, 16bit, little endian. For the time being anything else is beyond the scope of this HOWTO.

This HOWTO is very minimal and will get everything done quickly so you can get back to work. Add steps as necessary.

Computer Setup

When I was running ecasound in the beginning I was getting many underruns, leading me to believe I need a realtime kernel. This is simply not the case, with a fairly modern computer. You need to make sure you have 'Preemptible Kernel' in your kernel options. Also, ensure that you are not putting any of your IDE drives to sleep, because this will lock your IO for about 5 seconds during wakeup and cause xruns.

Recording

ecasound is an extremely powerful program to record and do different effects and conversions. You will probably find that writing a wrapper shell script to handle things. Here's a simple example of a wrapper script for ecasound.

Running with root privileges or enough to get SCHED_FIFO:50 is recommended to prevent underruns.

ecawrapper.sh:

#!/bin/bash
WAVDATE=$(date)
WAVDIR="/mnt/aux/Tmp/new_wavs/$WAVDATE"
WAVLOG="$WAVDIR/ecasound.log"
CURRENT_FILE="$WAVDIR/$1.raw"

echo $DATE>$WAVDIR/start_time
while pgrep ecasound
do
  kill `pgrep ecasound`
done

# Buffer like crazy! 
ecasound -r -i alsa,default -z:db,500000 -z:intbuf -o $CURRENT_FILE&>$WAVLOG

Now that's done a simple crontab, for once a day to restart with a fresh file.

0 0 * * *       /root/scriptbin/ecawrapper.sh my-favorite-radio-program

Cutting

Now, I don't need to do much in the way of editing, I really have more to do with just cutting my program out of the 24 hour raw file I have produced. Since we started recording at midnight, it would be useful to make a script to take just the part we want to keep out of the file.

The following is an extremely simple starter example, there are less cpu intensive ways to deal with this that require much more complex scripts:

Don't forget that the time everything started was at $WAVDIR/start_time.

This could also be easily done with 'split' if wanted/needed.

File: raw_dd_split.sh
#!/bin/bash
RAWBPS="176400"
LARGEFILE_LIMIT=$((1024*1024*1024*4))

if [ ! $# == 2 ]; then
  echo "Usage: $0 [filename] [begin min] [end min]"
  echo "$0 /home/sbh/blah.raw 90 120"
fi

if [[ $(($RAWBPS*$3)) > $LARGEFILE_LIMIT ]]; then
   echo 'Cannot create a file that large due to limitations of wavbreaker'
   exit 1
fi

# Divide by 512 due to the way dd handles blocks
dd skip=$((($2*60*$RAWBPS)/512)) count=$((($3-$2)/512)) if=$1 of="`basename $1`"

# Convert the file from raw to wav
/usr/bin/ecasound -i:"`basename $1`" -o:"`basename $1 | sed -e s/.raw/.wav/`"

Editing

wavbreaker is a simple tool to cut out the final details you don't need, for instance near the beginning and end. Get rid of any excess you had from the file you just made with dd.

After using wavbreaker 0.7.0 for a good long time there are two issues that I have come upon:

Finishing up

Finally you will probably want to convert the final wav file to a flac or mp3, etc..

For more advanced examples

I use many advanced scripts to take care of mine, they're much more complicated and less 'ready for others' than the sample scripts above. My scripts also take less than half the time of processing that the sample scripts from above would take me. Feel free to contact me at avuton@gmail.com and I will give you a link to some of these more enhanced scripts.

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Largefile_Sound_Recording_and_Cutting"

Last modified: Fri, 06 Apr 2007 06:24:00 +0000 Hits: 7,267