Linux Audio Codec Tips
Although I started playing with digital audio on some of my earliest computers (both PCs and Macs)
it's actually taken a number of years for both the quality and the cost of hardware to improve to
the point where the average person can afford it (see the Linux
Audio Tips page here, or other sources). The current state of open source software is also
such that many things are not only possible, but also straight-forward (and in many cases downright
easy... :)
Of course, there's still the issue of knowledge in general, including the physics of sound, AD and
DA conversion (ie, the properties of digital audio), audio codecs, and then higher level tasks such
as multi-track digital recording, editing and mixing, midi, etc. I can't possibly cover all of that
here, however, I can try to cover the basics of recording, editing, and the best of the free audio
codecs (plus a few other tools). Whether you want to record something yourself or just enjoy the
music there should be something of interest. Potential sources of audio include:
- Your own collections of CDs/DVDs, tapes, or vinyl - Since CDs and DVDs are already in a digital
format, you just need a ripping tool that does DAE (Digital Audio Extraction, which most do).
The latter is basically digitizing/recording an analog audio source, which is where decent
audio hardware comes in...
- Free downloads (really free) from your favorite artist's web site and elsewhere. The second
category includes more than you might think, since artists such as
Phish and
The Grateful Dead have allowed recording and sharing of
their live performances for many years. Many of these are available on the
Open Source Audio Archive
(either the main section or the live music section). Other non-copyrighted materials
(eg, "harvested BBC archive recordings" of Pink Floyd... yummy...) are available
via several torrent and blog sites such as Mininova
and
Mindwarp Pavillion
. Feel free to browse, and you can make your own decision as to the "free-ness" of the
latter material...
Hardware:
Unless you already have a decent audio card (meaning at least an Audigy2 or better) the best bet for
recording live audio is a USB audio interface. Avoid the $10 USB audio devices, and splurge the $40
for one of the Behringer models mentioned on the
Linux Audio Tips page. This will get you basic 2-channel (stereo)
recording with high quality microphone and line-level inputs, but another $100 will get you a very
high quality multi-channel USB recording interface such as the
Lexicon Alpha or even something Envy24-based from
M-Audio. I'm amazed at the quality and
Linux compatibility of both Lexicon and Behringer. Highly recommended...
You should also have at least one or two decent CD/DVD burners for ripping and burning digital audio,
and either one of the above audio interfaces or one of the many specialty items for recording from
tapes or vinyl (yes Martha, they make USB turntables and tapedecks). However, if you record vinyl
using a standard turntable connected to your audio interface, don't forget to use a pre-amp in between
(remember that turntables output the standard RIAA curve, so you'll need a real phono input to process
it correctly).
Lastly, if you want to record anything live, you'll need at least two decent microphones (or one stereo
mic). We won't go into condenser mics vs. dynamic mics here; just make sure they can handle the sound
pressure levels without distortion and watch your record levels to avoid clipping.
Formats and Codecs:
All digital files have a format and possibly a compression and/or storage codec (mostly due to the size
or content) and digital audio is no different. Even though your average PC .wav file is uncompressed,
it must still represent the data in some known way, and it usually includes some kind of file header
for metadata; in this case we're taking PCM (Pulse Code Modulation) to represent the data, and a wave
file header to describe the file contents, such as mono/stereo, the sampling rate, etc. There are also
many other formats for the PC platform, as well as other Unix architectures, PowerPC/Macintosh, etc.
Suffice to say that you don't really need to know all of this (but you'll pick it up along the way
whether you want to or not :)
Some useful reference sites:
- Understanding the basic physics of sound is important, whether from a
physics standpoint, or a
musical
one (or google up your own).
- Understanding the basics of analog and digital signals in both time and frequency domain is also
important, and I do mean basics (more is up to you). All the data on your disk, CD, or DVD is
digital; it's analog coming out of the speakers and going into the microphone, but your audio
device is equipped with one or more
A/D and D/A converters
(of varying quality). This allows the seamless conversion of audio data in both directions,
ie, whether recording or listening, at various
sampling rates and
bit-depths (the
number of bits of data per sample). These factors affect both the quality and size of the
resultant digital audio files, and will strongly influence how they sound.
You'll pretty much always be ripping or recording to PCM .wav files, as well as editing them;
even when ripping AC-3 or other surround formats from a DVD, you'll probably want to convert
it to PCM stereo if you just want the audio track (but if you're working with audio and video
together, then maybe not).
- The next part involves choosing an encoding method for either storage or playback (or both).
The codec itself can be either
lossy or lossless
with the difference being lossy encoding methods actually throw away (or lose) data,
mostly to increase storage efficiency, whereas lossless encoding will preserve every
bit of information. This also greatly affects how the resulting audio sounds when
played back, especially with a good amplifier and speakers.
- There are literally dozens of codecs out there (of both types) some open source, some
"free", and some proprietary. I have an extensive MP3 collection of my CDs and DVDs,
mostly lame encoded at various bit-rates,
plus a handful of others, which I've recently begun converting to
flac, which basically means going back to
the original source and re-ripping everything (since MP3 is a lossy codec).
- There are several other
lossless
codecs, but overall, flac seems the best choice as a fairly well-supported, mature, open
source software package. The average compression ratio is about 2:1, but storage is cheap
(right? ;) and there's actually more
hardware that supports flac than
you might think. Pretty cool... I use flac for listening at home, and convert to
MP3 for the car or portable (using a cool fuse-based tool called
mp3fs which acts like an mp3 share mounted
on your flac collection that automatically converts flac to MP3 just by reading or
copying the files, using the bit-rate specified on the mount options). Now *that's* cool...
For any of the above options, you'll need to have your kernel configured for USB and ALSA, and
possibly an external kernel driver (eg, Line6 Pod). You'll also need several tools and applications,
depending on what you want to do. Many current applications will work for both recording and jamming,
including MIDI, USB, and Digital Audio, again, depending on your particular hardware setup (at the
least you should have USB and basic audio line in/out).
The default alsa configuration should work for basic ripping, recording/editing, and playback, but
you may want to disable legacy desktop audio servers such as esd or arts (notorious for latency
problems). If you need a modern low-latency sound server, then check out
pulse audio (but if you're just starting out, stick with
alsa and check out the .asoundrc configuration options).
Applications:
In addition to lame, flac, etc, you'll want to check out the the DVD ripping tools on the
DVD audio rip page, as well as make sure your
cd kit is complete (ie, cdrtools, grip, brasero or k3b, etc). A nice command-line utility
for querying, converting, and otherwise working with directories full of audio files, is
shntool. If you go ahead and install
the required utilities, you'll have a fairly complete toolbox for working with digital audio
files.
- Jack Audio Connection Kit - The Jack-of-all
Linux audio toolkits, provides a virtual patch bay (among other things).
- Audacity - Digital audio recording
and editing. Free, open source software for recording and editing sounds in Linux,
Mac OS X, and other.
- Ardour - Hard disk recording
(a multichannel digital audio workstation for Linux)
- ECA Tools - ecawave, ecamegapedal, etc,
provide multi-track audio processing, audio editing, and effects processing.
- Sox - Digital audio editing and processing
tool (the swiss army knife of sound processing programs).
Complete Linux-based Audio Workstations
My preferred platform is Gentoo Linux, but if you already use RedHat or Debian, feel free to try
one of these:
- Planet CCRMA at home - A
low-latency kernel and set of audio applications to build an audio workstation on top
of Fedora or CentOS. Uses both apt and rpm to access the Planet CCRMA mirrors.
- 64 Studio - A GNU/Linux distribution tailor-made
for digital content creation, including audio, video, graphics and publishing tools.
64 Studio is based on Debian with X.org, the Gnome desktop, Linux kernel 2.6.2x with
realtime preemption patches (including a realtime SMP kernel for AMD64 and Intel 64 dual
core and multi-processor machines) and a selection of creative applications for audio and
multimedia (comes in both free and commercial versions).