owntone / owntone-server

Linux/FreeBSD DAAP (iTunes) and MPD media server with support for AirPlay 1 and 2 speakers (multiroom), Apple Remote (and compatibles), Chromecast, Spotify and internet radio.
https://owntone.github.io/owntone-server
GNU General Public License v2.0
2.01k stars 232 forks source link

Volume control is broken with some ALSA outputs #343

Open main-- opened 7 years ago

main-- commented 7 years ago

I use the JACK sound server and while forked-daapd works fine with JACK's ALSA interface, volume control doesn't work. The player always plays at full volume regardless of what I select.

I'm guessing this happens because unlike most ALSA outputs, JACK doesn't come with a ctl module. Of course I can have forked-daapd play to pulseaudio, alsa, jack, alsa, headphones. But obviously that's far from perfect.

The mpv media player deprecated output-specific volume control a while ago in favor of "softvol" (where the player just alters the audio stream's volume).

ejurgensen commented 7 years ago

Not sure what the ctl module is, tbh. Forked-daapd uses alsa's mixer for volume adjustment, is that generally not working in this setup? Can you adjust volume with alsamixer?

main-- commented 7 years ago

I'm not too familiar with this but in .asoundrc you would typically define things like this:

pcm.!default {
    type pulse
}
ctl.!default {
    type pulse
}

I used pulseaudio for this example because it shows the issue quite clearly: Every output should have both a pcm and a ctl section. The modules are loaded from /usr/lib/alsa-lib/, in this case it's libasound_module_pcm_pulse.so and libasound_module_ctl_pulse.so. Now the pcm part is basically just for playing sound - the ctl part appears to be where all the configuration (volume especially) happens. In the case of pulseaudio, this just works as the module can translate most ALSA operations into pulseaudio. JACK however doesn't support setting volume and doesn't even have an ALSA ctl module at all. All you can do is output audio.

My .asoundrc doesn't have a ctl section so I'm guessing forked-daapd just gets some random default mixer from the onboard sound that's not in use.

JACK doesn't appear in alsamixer because it's not an actual device but even if it did, there would be no way to change the volume. Whether it's through ALSA or the actual JACK API, volume has to be handled entirely inside forked-daapd for this to work.

But this is not entirely JACK-specific - there are several cases where your default ALSA device would not have a proper ctl (I'm not sure about dmix but the fact that most default configurations just forward it to the sound card directly leads me to believe that this would be broken as well).