icosa.gif

[] Home
henry12t.jpg Introduction
[] The Labyrinth
[] Social Media
[] Terms
[] Contact

get in shape
Hits: 81641

random hull

audio
bio
decal4linux
diet
dictionary

electronic
find-target
fixboot
halloween
home
hosting
installation
isoedit
kernel
links
nVidia
oldies
pollution
playcd
playdvd
quines
rpmsign
scite
shortcuts
social media
software
terms
the labyrinth
wine
zotero

The Nerd Show

Audio Playback and Recording on Linux

An updated, yet simplified look at using and recording with alsa and Pulseaudio on modern GNU/Linux architectures.

Henry Kroll 3D

Tue Nov 17 2009

Under Construction: Video not available yet.

Budget Recording Studio

This presentation will be about recording decent sounding audio on a budget. Now if people are serious about making good audio recordings and videos and money exists, somebody should probably buy some professional recording equipment.

So, getting back to doing more with less, a computer sound card can make surprisingly good quality recordings, with the right software. Prior to putting this presentation together, I had been using audacity, the free and open source multi-track recording software to do my recording. It does a pretty good job, but I found that I kept having to go back and boost, filter and normalize each audio track and remove noise. Unfortunately, there is no easy way to automate all those editing steps. So for this project I have written a small script that uses Sox, a command line audio recording utility, to apply all those effects automatically.

These free programs are available for windows, but I will be using Fedora, a free GNU/Linux operating system. The problem that I see with recording on Linux is that on most distributions there are several competing software sound systems and they can be all interoperating at the same time! There is Jack, ESD, Arts, Gstreamer, Pulseaudio, alsa, and OSS. Jack is really nice and I use it for songwriting because it links the transport between various programs, so when I press play, all the separate programs, like the drum machine and the sequencer cue up at the same time.

To simplify things, we will focus on Pulseaudio and ALSA, since mainstream distributions, like Ubuntu and Fedora have these enabled and configured by default. If Pulseaudio is set up properly, it should be completely transparent. In other words, we can forget it's there and just focus on alsa. Here is the simplified diagram:


mic->card->alsa->sox->wav

Pulseaudio is like a giant octopus. In typical Linux fashion, it is built for the greatest common denominator of users. In its attempt to please everyone and do everything. It inserts itself into the ALSA layer, mixes in the desktop sounds and any music, movies or CDs that are playing, adjusts all the sample rates to fit the hardware, adjusts the levels of each program independently, and even ships audio out across the network to other PCs. Unfortunately all this complexity makes it difficult for those who are new to Linux and rather than explaining how to use it, many are told to simply disable it. This is bad advice because with Pulseaudio disabled, the sound may not work at all.

The diagram of Pulseaudio on Wikipedia is very complicated. It seems like it's more to impress people than anything else. The daring may check it out. This simplified diagram is my attempt to narrow down that mess to just the audio systems that are actually installed on a freshly installed system, that is Pulseaudio and ALSA:

mic->alsa->pulseaudio->sox->wav

I'm not sure what good it is to have networked audio. Maybe if a wireless IP phone supports Pulseaudio somebody can use it as a poor-quality wireless mic... As we can see above, audacity now records through Pulseaudio and Sox still uses alsa, only Pulseaudio intercepts the audio through libalsa-Pulse. It's transparent, remember? We can forget about it. Well, almost. The problem with this is there are 2 mixers, the Pulseaudio mixer and the ALSA mixer. So, if the audio is muted in either place, there will be very faint audio or nothing. These are common complaints.

For recording, and to sort these problems out, we will need a better mixer. Type:

su -c 'yum install alsa-utils sox audacity'

Once that installs, we will have access to the advanced mixer controls and some basic recording software. Start alsamixer, use the following commands:

alsamixer #this sets the simplified Pulseaudio mixer controls
alsamixer -c0 #this sets up the actual ALSA sound card levels

The -c0 tells it that we will be setting up the first sound card in the system. Most systems will only have one soundcard.

Press 'h' for help and read the instructions. Some people can fiddle with the sliders all day and still not get audio, however. So we will make it even simpler. The following command sets the Pulseaudio capture and volume to 100% and un-mutes them so we can hear and perhaps record something.

amixer sset Master 0dB unmute #un-mute the main Pulseaudio volume control
amixer sset Capture 0dB cap #start cap (capturing) audio

The Linux desktop often forgets these settings upon reboot, so put them in a script somewhere or in .bashrc.

Now that Pulseaudio is uncrippled, we can forget about it and concentrate on ALSA.

amixer -c0 sset Master 0dB unmute   #un-mute the main ALSA (card 0) volume control

# choose one of these
amixer -c0 cset iface=MIXER,name='Input Source',index=1 'Front Mic' # (Record from Front Mic)
amixer -c0 cset iface=MIXER,name='Input Source',index=1 Mic         # (Record from Rear Mic)
amixer -c0 cset iface=MIXER,name='Input Source',index=1 Line        # (record from Line In)

# IMPORTANT: set Capture to 0dB and leave it alone if possible
amixer -c0 sset Capture 0dB

# more info
amixer -c0   # see all devices
man amixer   # look at the man page

Now just fire up alsamixer -c0 and fiddle with the mic boost and start recording! Routing pulseaudio through the network is a bit too advanced for this page, but doable if padevchooser is installed.