Recording Sound with Linux
This is a record of my first attempts to get the LINE-IN and MIC working on an IBm laptop running Ubuntu.
My goal is to record two separate channels of sound, and to have the ability to adjust the gain for each channel independently. One channel will have a local microphone recording ambient sound, the other channel will have an AM radio channel being recorded.
With Ubuntu, it appears that ALSA is being used.
I wanted a real time visualization of the signal levels without a graphical application running, and I found it with vu, a curses based graph program that works really well.
vu is pretty easy to use - it reads from stdin and writes out to stdout, whilst giving an easy display on the terminal line.
So, to just give a live dump of 1000 seconds from the microphone or line-in, you run something like:
arecord -f cd -D hw:0,0 -d 1000 | ./vu > /dev/null
And to record 1 hour's worth of audio data, you can do something like this:
arecord -f cd -D hw:0,0 -d 3600 | ./vu > one_hour.wav
Diagnosing and using ALSA
First things first, MAKE SURE YOU HAVE THE VOLUME TURNED UP! I forgot that my laptop has a manually controlled volume at the top left hand side, and so I spent two hours mutterin under my breath wondering why the sound card was apparently working but I was hearing no sound.
ALSA is not very intuitive at all. For the card in my laptop, ALSA has about fifteen gain controls - and it's not at all obvious what is going on.
The two commands I've been working with are aplay and arecord. arecord
needs a device name, specified with a -D flag. Trying to find out what
the device name is, though, is very damn difficult.
I found by trial and error that you specify the devices with hw:0,0
where the first number is the card number, and the second one is the
device number. acreord -l gives a list of devices but it might as well
be gibberish. I've just played music into the line-in and mic jacks and
experimented.
NOTE that you may have to unmute the microphone and Line-in for them
to receive the input signals. alsamixer is a terminal based mixer,
which means that there are all these bloody controls and no indication
of how to select with them.
? get the help
Esc exit alsamixer
F1 ? show Help screen
F2 / show /proc info screen
F3 show Playback controls only
F4 show Capture controls only
F5 show all controls
Tab toggle view mode
Return return to main screen
Space toggle Capture facility
m M toggle mute on both channels
< > toggle mute on left/right channel
Up increase left and right volume
Down decrease left and right volume
Right move (scroll) to the right next channel
Left move (scroll) to the left next chann
The command line I use for capturing AM radio data and sound with a boosted microphone is:
arecord -f cd -D hw:0,0 -d 30 | ./vu > `date +"%F-%H%M%S"`_radio.wav
The volume of the radi is adjusted so that the background noise level is about 1000.
The microphone amplifier I am trying out is the:
http://www.kitsrus.com/pdf/k17.pdf which works well with a battery, has a variable pot for input gain, and a jumper to boost the gain of the IC used but amplifies IC noise too.