Thursday, September 20, 2012

Pulseaudio Fun

One of the really nice thing that Pulseaudio offers is the ability to treat sound output as sound input. For each audio device Pulseaudio has an input device which ends in .monitor that can be used for input. This allows basic things such as recording audio for screencasting, but also more fun things such as quick&dirty sound forwarding over the network via:

parec -d alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | aplay -f S16_LE -c 2 -r 44.1

Combined with another ability of Pulseaudio, the null-sink, things become even more interesting. The null-sink is essentially a virtual sound card and can be loaded from command line via:

pactl load-module module-null-sink

Each load-module will create another virtual soundcard. The name of the soundcard can be given via sink_name=myname. One can unload them again via:

pactl unload-module INT

Where INT is the number returned by the initial load-module command. A list of all of Pulseaudios current state, including loaded modules, available soundcards and such can be optained via:

pactl list

Back to the null-sink, everything that goes to the null-sink gets discarded by default, but just like any real soundcard, the null-sink does also have a monitor device. So it is possible to record the sound that goes to a null device via something like:

parec -d null.monitor

Which can be useful when trying to record something non-interactively or without blocking the soundcard.

With the help of pavucontrol, a GUI volume control for Pulseaudio, one can even redirect application audio streams at runtime, thus one can send the sound of an application that is currently playing on the regular soundcard to another soundcard or even the virtual null device. Same is true for currently running recordings.

There are plenty  more modules to play around with, the Pulseaudio Wiki has a list.

1 comment:

adiba akter said...
This comment has been removed by a blog administrator.