librespot icon indicating copy to clipboard operation
librespot copied to clipboard

ALSA: support selection of ALSA mixer - for (hardware-based) volume control

Open arigit opened this issue 9 years ago • 3 comments

Some DAC cards support hardware-based volume control. Example: HiFiBerry DAC+ pro on Raspberry. Using librespot (v20161230-7fd8503) from: https://github.com/herrernst/librespot/releases

On raspberry pi + OSMC (raspbian) + above mentioned DAC. Works very well out of the box.

Running the client with:

/home/osmc/librespot/librespot --name Raspberry --cache /tmp --bitrate 320 --backend alsa --device hw:0

I notice using alsamixer and librespot in verbose mode that changing that volume changes in the client causes some events in librespot,

DEBUG:librespot::spirc: kMessageTypeVolume ... ...

the audio volume does change, increase/decrease, however alsamixer doesn't show any actual mixer volume change at all in any of its mixers, which seems to indicate that the volume change is done by librespot itself as a "software volume change". Higher end DACs can control volume via hardware which is preferable. In the case of the HiFiBerry DAC pro, the Alsa mixer is called "Digital" (shows up as one of the mixers displayed by the "alsamixer" tool)

When using spotify-connect-web, running it as:

spotify-connect-web --key /home/your-user/your-key.key --name Raspberry --bitrate 320 --playback_device hw:0 --mixer Digital

...any volume change in the spotify client causes the alsamixer "Digital" mixer to reflect the change (value between 100 and 0), which indicates that the volume change is being done via hardware. Note that spotify-connect-web also supports "software-based volume control" if desired

arigit avatar Jan 05 '17 04:01 arigit

This is definitely a frequent request (#128 and #75). Originally, librespot only supported PortAudio, which doesn't have any sort of volume control.

@joerg-krause had an implementation for ALSA at some point. It would need to be adjusted to at least fallback to software volume control for other backends

plietar avatar Jan 05 '17 13:01 plietar

Noticed that today's binary release for raspberry by @herrernst supports a "--mixer" option! Tried it & librespot crashed like so:

/home/osmc/librespot# /home/osmc/librespot/librespot --name Raspberry --cache /tmp --bitrate 320 --backend alsa --device hw:0 --mixer Digital INFO:librespot: librespot 6f1b785 (2017-03-26). Built on 2017-03-26. thread 'main' panicked at 'Invalid mixer', /buildslave/rust-buildbot/slave/stable-dist-rustc-cross-host-linux/build/src/libcore/option.rs:715 note: Run with RUST_BACKTRACE=1 for a backtrace.

Amixer shows that the "Digital" mixer exists:

... Simple mixer control 'Digital',0 Capabilities: pvolume pswitch Playback channels: Front Left - Front Right Limits: Playback 0 - 207 Mono: Front Left: Playback 207 [100%] [0.00dB] [on] Front Right: Playback 207 [100%] [0.00dB] [on] ...

Tried with other mixers shown by alsamixer & amixer, and they all crash librespot

Wondering if the --mixer command line switch is not yet ready for use, or if it's meant to be used differently

arigit avatar Mar 26 '17 18:03 arigit

It's meant to use different. For now, there is only one mixer supported: softmixer. --mixer is not the ALSA mixer device name.

joerg-krause avatar Mar 27 '17 05:03 joerg-krause