Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Hardware volume resetting
#1
Hello! 

I am using mo0de 4.4 with the onboard audio of a PI3B (for now, at least). The following may be expected behaviour, but I would still appreciate an understanding of it, and possibly a workaround.

I use hardware mixing for MPD. When I start playing through SpotifyConnect, the hardware volume maxes out to 0dB after about 1 second. If I pause, it goes back to the previous level of the MPD, and when I resume, maxes out again. 

I have the same issue with Bluetooth connections. When a paired device connects, hardware volume maxes out (with or without anything playing), and returns to previous value when it disconnects. 

Airplay does not have this behaviour. (Interestingly, however, if I'm playing Spotify through Airplay and switch to SpotifyConnect directly -- without stopping or pausing or disconnecting -- the hardware volume maxes out after 1 second, and returns to the previous level after 1 more second...) 

What can I do to prevent this maxing out? If I cannot prevent the resetting of the hardware level when SpotifyConnect or BT connections are made, can I at least set the "reset level" to something less than 0dB?

I hope I was able to pose the issue clearly enough :-)

Cheers!
Reply
#2
Hi,

This is because Spotify and Bluetooth only support Software volume and thus if the audio device supports Hardware volume we end up with two volume controls in the audio chain. The first is a Software volume control on the client (Spotify app, etc) and the second is a hardware volume control on the audio device.

In order to ensure that a volume setting of 100% on the client yields 0dB output from the audio device its necessary to initially set the Hardware volume to 100%. The same would be done if MPD volume control were set to Software. You would see that ALSA (Hardware) volume is set to 100%.

The Airplay receiver defaults to supporing Hardware volume and like MPD when it's set to Hardware volume, will directly control the audio devices hardware volume controller. In this case ALSA (Hardware) volume is not initially set.

You can configure Airplay to only use Software volume via a setting on the Airplay config screen, then it will behave like Spotify and Bluetooth.

-Tim
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
Wow, thanks Tim!

Now I understand the discrepant behavior. It is great to know when there is a clear reason for any behaviour :-) Why the ALSA level reset bothers me is that I get clipping distortion at max level (which I referred to as 0dB earlier, but it's indicated as 4dB in alsamixer). I suppose that's what you get if you use the onboard audio?

I am happy with Airplay's behaviour of not resetting the hardware level. And you might be interested to know that I get this behaviour *despite* having software mixing in the Airplay config. 

Anyways, I was hoping I could "fix" this behaviour by adding a line of the sort "amixer set PCM %90" into some script, or something similarly easy with a configuration file, but I guess that's not the case. 

Thanks a lot!

/Cem
Reply
#4
Thats interesting, I also see 4 dB gain at ALSA 100% for the on-board audio device. It could be a Kernel bug.

I'll do some checking...
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#5
(12-20-2018, 07:09 PM)Tim Curtis Wrote: Thats interesting, I also see 4 dB gain at ALSA 100% for the on-board audio device. It could be a Kernel bug.

I'll do some checking...

Granted I was trying understand the software (not hardware) volume, ALSA configs are not the source for where the volume is set to 100% with 4dB gain.  Instead I discovered default levels are set by "/var/www/command/worker.php".  Line 566 of worker.php is where I found modifying the end of sysCmd from 100 to 95 achieved the desired result since setting volume from the web interface is not persistent with reboots.  The problem may be illustrated by running an example of the same command that "/var/www/command/util.sh" will call on line 84.

Example of current problem:

    pi@moode:~ $ amixer -c 0 sset "'PCM'" 100%
    Simple mixer control 'PCM',0
    Capabilities: pvolume pvolume-joined pswitch pswitch-joined
    Playback channels: Mono
    Limits: Playback -10239 - 400
    Mono: Playback 400 [100%] [4.00dB] [on]

versus adding the parameter to specify gain dB in addition to volume percent gets this result, which is what I was looking for to avoid clipping.

    pi@moode:~ $ amixer -c 0 sset "'PCM'" 0,100%
    Simple mixer control 'PCM',0
    Capabilities: pvolume pvolume-joined pswitch pswitch-joined
    Playback channels: Mono
    Limits: Playback -10239 - 400
    Mono: Playback 0 [96%] [0.00dB] [on]

*Notice that 0 dB gain plus 100% volume translates to 96%.  Adding " 0," on line 566 of "/var/www/command/worker.php" should fix this bug to prevent clipping as a default persistent state after rebooting.

Bottom line quick fix, edit line 566 of "/var/www/command/worker.php" to the following

$result = sysCmd('/var/www/command/util.sh set-alsavol ' . '"' . $_SESSION['amixname']  . '"' . ' 0,100');

** I still experienced some noticeable clipping at 100% on an rPi2 model B, so playing it safe at 96% in my own config.
Reply
#6
Hi,

The 0,100% parameter does something different when used with a DAC board for example Hifiberry DAC+. It sets the left and right channel levels independently rather than adjusting the overall volume level for 0dB.

Here is link to your PR
https://github.com/moode-player/moode/pull/31

I'm still of the opinion that it is a kernel bug that is responsible for +4dB at 100% ALSA volume for the on-board audio device.

-Tim
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#7
(05-20-2019, 11:50 PM)Tim Curtis Wrote: Hi,

The 0,100% parameter does something different when used with a DAC board for example Hifiberry DAC+. It sets the left and right channel levels independently rather than adjusting the overall volume level for 0dB.

Here is link to your PR
https://github.com/moode-player/moode/pull/31

I'm still of the opinion that it is a kernel bug that is responsible for +4dB at 100% ALSA volume for the on-board audio device.

-Tim

Agreed, this is a bug with ALSA, the kernel, or something beyond my understanding.  Thank you for the feedback!
Reply


Forum Jump: