Skip to content
Will Stott edited this page Jul 2, 2019 · 25 revisions

librespot supports various audio backends. Multiple backends can be enabled at compile time by enabling the corresponding cargo feature. By default, only Rodio is enabled.

Building

A specific backend can selected at runtime using the --backend switch.

cargo build --release --features portaudio-backend
target/release/librespot [...] --backend portaudio

The following backends are currently available:

  • Rodio (Default)
    • Uses ALSA on linux, so development packages are required to build.
    • Mac OS Windows should work without any dependencies.
  • ALSA
    • Linux build dependencies: libasound2-dev on Debian and alsa-lib-devel on Fedora
  • PortAudio
  • PulseAudio
  • JACK
  • Pipe
  • SDL

Usage

Most backends don't require specific setup. Some however do.

ALSA

The right device needs to be passed to librespot via the --device flag. The alsa terminology of hw:X,Y is used, where X is the card number, and Y is the device number. This can be determined by:

~/librespot$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC3234 Analog [ALC3234 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

# To determine the right mixer name for your card, try
~/librespot$  amixer --device "hw:0" --card "0" # Results truncated here 
Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 87
  Mono: Playback 64 [74%] [-17.25dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
Simple mixer control 'PCM',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 2 [1%] [-50.60dB]
  Front Right: Playback 2 [1%] [-50.60dB]

Thus, in this example the settings would be:

./target/release/librespot [] --backend alsa  \
        --device="hw:0,0" \
        --mixer="alsa" --mixer-card="hw:0" --mixer-name="Master" \

NOTE: librespot you might want to turn on --linear-volume when utilising a hardware mixer.

Pipe

The pipe back-end requires very minimal setup provided you have an audio player which can accept and process the output correctly.

The pipe outputs the data as raw stereo 16bit 44.1KHz bytes. This is true for any bitrate (quality) setting.

Clone this wiki locally