Linux Audio and Streaming
ALSA and Pulse Audio
I know of two major audio systems for linux: ALSA and Pulse audio. ALSA deals directly with hardware, and pulse audio is an abstraction layer that sits on top of Alsa. The process of getting audio into your computer will vary according to which system you use.
Getting audio in to alsa
In ALSA, you'll have to find a hardware device number. To see a list of hardware devices:
$ arecord --list-devices **** List of CAPTURE Hardware Devices **** card 0: Intel [HDA Intel], device 0: CX20561 Analog [CX20561 Analog] Subdevices: 1/1 Subdevice #0: subdevice #0
Above, we see one audio card (numbered "card 0"), and one subdevice (numbered subdevices #0). We'll specify this as "hw:0,0" -- hardware: card 0 ,subdevice 0.
Now, try to record some audio:
$ arecord -f cd --device hw:0,0 --vumeter=stereo sound.wav Recording WAVE 'sound.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
This creates a file named sound.wav, using input from device hw:0,0. The "--vumeter=stereo" option instructs arecord to display a textual VU meter. This is a useful way to get an idea of what the audio levels are.
When setting audio levels (via something like alsamixer), you'll probably see "microphone", and "microphone boost". Start with "microphone boost" all the way down, and increase only if needed. Adding too much gain with microphone boost tends to lead to distortion, at least in my experience.
After recording for a little while, press Ctrl-C to stop the recording.
To play the file back:
$ aplay sound.wav Playing WAVE 'sound.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
One thing to note about arecord: it requires exclusive access to your computer's audio input device. This seems to be true of any ALSA-type input, and it means that only one program at a time can consume audio.
Pulse Audio
Pulse audio is an abstraction layer that sits above the hardware. This gives pulse some advantages. Pulse can (exclusively) access the audio hardware, then distribute the digital audio signal to several programs (called "sinks"). For example, one sink can stream audio, while another sink displays a vu meter.
To see a list of sources:
$ pactl list sources | grep Name Name: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor Name: alsa_input.pci-0000_00_1b.0.analog-stereo
To make a simple recording:
$ parecord --device=alsa_input.pci-0000_00_1b.0.analog-stereo --record sound2.wav
While this is running,
$ pavumeter --record
Now we've got two audo sinks ("consumers"). One is making a recording, and one is displaying a VU meter.
Press Ctrl-C to interrupt parecord. Then
$ aplay sound2.wav
to play it back.
There: we've just identified audio sources, and used them to make a simple recording. This is the audio equivelent to "hello world", and it's the first step in getting ready to stream audio.