How to set ALSA Master Volume

Hi all,
I am running CE NO on a Odroid N2+ with sound been handled by a Khadas Toneboard. I have a few annoying issues;

  • on switch on of the Toneboard it does a very annoying pop. This has gotten to be more of an issue recently because my new amp has a higher gain so the pop is frighteningly loud.

-the volume on the toneboard resets to maximum on each reboot, which again is a much bigger issue since my amps gain could blow my speakers.

Coreelec’s built in sound controls allow you to set a default volume on the HDMI output and it sticks between reboots, but with an external DAC this is ignored. I want to set this is the config files for ALSA, but by default there is no user configurable ALSA Config. I messed about with “amixer” with the intention of setting the Master volume in the autostart.sh file - but this did nothing.

Anyone have any understanding of how ALSA is configured in CE ?

Shoog

This works when put into my autostart.sh

#!/bin/sh

amixer sset --quiet --card=1 'Khadas Tone Control ’ toggle

sleep 5

amixer sset --quiet --card=1 'Khadas Tone Control ’ toggle

amixer sset --quiet --card=1 'Khadas Tone Control ’ 70%

It unfortunately has an unanticipated side effect of capping the volume at the set value such that when using the volume control within Coreelec a 100% on the scale is 70% of the Khadas Tone Board volume.

I attempted to use mute/unmute as the amixer parameter - but once you have muted the toneboard, issuing unmute does nothing. Toggle however switches between mute and unmute as desired.

So a sort of solution but not great. It seems that ALSA has direct control of the soundcards volume mixer, but that Kodi functions as an abstraction layer over the top of the ALSA controls. This has the effect of meaning that Kodi doesn’t have direct control of the sound card, this suggests the volume function in Kodi is a software function rather than direct hardware control.

Just to close this out, amixer sets the upper limit of the Kodi volume range. However if you go into controls whilst the media is playing in most cases it offers you an option to amplify the volume which allows you to go above the limit set by amixer. It also allows you to set the amplified limit for all media (a little bit flakey this as sometimes it doesn’t stick). However this setting sometimes doesn’t show up when playing music tracks.

The scarily loud pop at power on and power off seems to be a “feature” of the toneboard and there is no solution - nice.

Did you asked at Khadas what could be the solution with CE?

The loud pop is a Toneboard issue and is baked in - no solution possible.
The Volume issue is definitely a CE issue as it didn’t use to behave like this, that is to say that on older version it always remembered the volume between reboot. Its an issue that has crept in with the latest cycle of nightlies. You wouldn’t need to mess with the ALSA settings if CE just remembered the volume of external DACs at power off. It does this for HDMI so its a bug.

The plot thickens.

I upgraded the firmware on the Khadas Toneboard and this changed the name that ALSA identifies the card by. So I set that as the card on my Kodi system settings and that works. However it doesn’t stick between reboots. So I added a asound.conf file to set the sound card as per the standard ALSA procedure - but the Elec family of OS don’t do things in the standard ALSA way and instead use a self discovery script - this changes the card away from the soundcard that ALSA has set as default in asound.conf and sets it in an obscure Coreelec config file which is updated every single reboot. So there is literally no simple configuration file available to set a default card which both Coreelec will respect and which will not be overridden by the self discovery script.
I have been digging into this all day - and though a few people have had similar issues with USB sound cards in the past - no solution are suggested or currently applicable.

Seriously messed up basic functionality. I suspect the only thing that might resolve it is a complete reinstall to clear out some obscure undocumented setting that is grabbing the sound card and pushing it back onto AML-HDMI sound system every reboot.

Maybe this file overwritten thing after reboot can be fixed somehow. Just tell exactly which file or something like that.

I am going over my work so far to see if I have made any mistakes.

Update: You can set the default ALSA sound card by the standard ALSA method of defaults.
However nothing is obliged to use that default to output sound - and Coreelec uses its own sound configuration script to select its output. This, in my case at least, is always set to AML-HDMI. You can override this in Kodi system settings - but this is not in my case remembered by CE between boots. The probable reason for this is that it has set the HDMI output for sound - before it has detected that there is a USB sound card attached. Bluetooth and Pulse Audio can also upset the selection as it will frequently switch back to HDMI even after the USB_Sound card is selected. I disabled pulseaudio to eliminate this.

There is no configuration file or simple CMD that you can issue to change the default card once the system has completely booted up and settled - the only obvious way is to reset the sound card in the system settings of Kodi manually. There maybe other things going on as well (I noticed calls from programs in the docker folders which appeared in dmesg and I don’t even use Docker).

Frankly its a pathetic way to hand a core function as the way it is implemented breaks many of the standard ALSA tools for persistence between reboots.

UPDATE:
I found a combination of commands which achieved reliable discovery of my USB-sound card.

Discover your sound card number by using aplay -l

In my case the ToneBoard is card 1

Create a ascound.conf file in /storage/.config/ folder containing:

defaults.pcm.card 1
defaults.ctl.card 1

Then add to or create autostart.sh in /storage/.config/

#!/bin/sh

amixer -D default -c 1 set 'Tone1 ',0 90%

Ensure you make autostart.sh executable by issuing command

chmod+x /storage/.config/autostart.sh

Hope that helps someone. Still not satisfactory that you have to do this in order to get CE to reliably choose a USB-soundcard at boot.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.