LinuxCommandLibrary

alsaloop

Routes audio between ALSA soundcard devices

SYNOPSIS

alsaloop [options] -P <playback_device> -C <capture_device>

PARAMETERS

-P
    Specifies the ALSA PCM device for playback. Example: hw:0,0.

-C
    Specifies the ALSA PCM device for capture. Example: hw:1,0.

-r
    Sets the sample rate in Hz. Example: 44100.

-f
    Sets the sample format. Examples: S16_LE, S32_LE.

-c
    Sets the number of channels. Example: 2.

-B
    Sets the buffer size in milliseconds.

-Z
    Sets the period size in milliseconds.

-t
    Sets the loop time in milliseconds. Loop terminates after this time.

-S
    Sets the synchronization mode. Values: async, sync.

-L
    Sets the log level. (0=silent, 1=errors, 2=warnings, 3=infos, 4=debug).

-v
    Enables verbose output.

-d
    Daemonizes the process (runs in the background).

--help
    Displays help information and exits.

DESCRIPTION

alsaloop is a command-line utility from the alsa-utils package designed to create a real-time audio loop between two ALSA PCM (Pulse Code Modulation) devices. It acts as an intermediary, taking audio data from one ALSA device (either playback or capture) and sending it to another ALSA device (the opposite type, or even the same type if the driver supports it). This allows for flexible audio routing, enabling scenarios such as redirecting an application's output to another application's input, creating virtual soundcards for testing, or simply monitoring audio paths.

alsaloop can handle various audio parameters including sample rate, format (e.g., S16_LE), and number of channels, performing on-the-fly conversions if necessary. It offers fine-grained control over buffer and period sizes, and provides different synchronization modes to minimize latency and avoid xruns (underruns/overruns). While ALSA offers a kernel module (snd-aloop) for direct loopback, alsaloop provides more control over parameters and can be used when the kernel module isn't an option or when specific conversion or routing needs to be applied between different physical or virtual devices.

CAVEATS

  • Resource Usage: alsaloop can consume significant CPU resources, especially when performing real-time sample rate, format, or channel conversions.
  • Latency: Depending on buffer sizes and system load, alsaloop can introduce noticeable audio latency. Careful tuning of -B and -Z parameters is often required.
  • Synchronization: Achieving perfect synchronization between devices can be challenging, particularly with different clock sources. Xruns (underruns/overruns) may occur if parameters are not optimized.
  • Permissions: Accessing ALSA devices might require appropriate user permissions or running alsaloop with root privileges, though this is generally discouraged.

COMMON USE CASES

  • Routing audio from one application (e.g., a web browser playing a video) to another application (e.g., a recording software).
  • Creating a "virtual microphone" from a system's playback output.
  • Testing ALSA drivers and device configurations by looping audio back to a capture device on the same sound card.
  • Bridging between different physical sound cards or configurations.

DEVICE NAMING

ALSA device names can be complex. Common examples include hw:0,0 (first sound card, first digital audio interface), default, or plug:dmix.

HISTORY

alsaloop is an integral part of the alsa-utils package, which provides various command-line tools for managing and interacting with the Advanced Linux Sound Architecture (ALSA). ALSA itself has been the standard low-level audio framework for Linux systems since the early 2000s, replacing the older OSS (Open Sound System). alsaloop has evolved alongside ALSA, providing a flexible software-based audio looping mechanism that complements the kernel's snd-aloop module. Its development has focused on robust real-time performance and versatile audio parameter handling to meet diverse audio routing and testing needs on Linux.

SEE ALSO

aplay(1), arecord(1), amixer(1), jackd(1), pulseaudio(1), pw-loopback(1)

Copied to clipboard