Posts: 111
Joined: Sat Aug 09, 2014 11:48 pm

Set up ALSA to use dmix and softvol

Sat Apr 15, 2017 7:03 am

So, encountering a problem I had with running an install script for a sound card (not that it was necessarily their script or their method at fault, I installed some options I did not want and so could have been my further adjustments that caused the problem of aplay intermittent hangs but I am not going back through another test install to prove it either way...) and the hifiberry web site only giving you a very basic asound.conf file which does not even have softvol I did some hunting around

dmix allows alsa to mix streams from multiple concurrent sources and softvol gives you a volume control in alsamixer

(though seems a bug in alsamixer that remembers controls from previous asound.conf control tags even after you have removed that tag from asound.conf)

after a lot of hunting around on the net and trying to understand the massive set of config options for ALSA I happened across the perfect example which with a bit more hunting for how to get that to work on raspberry makes it work. So thanks to those guys. ... ter_volume

this works for sound cards based on hifiberry-dac driver and seems no reason why it should not an any i2s dac without hardware volume controls.

these instructions only tested on raspbian jessie lite

I think pulse audio might be configured on the full version of raspbian jessie

in /boot/config.txt
comment out dtparam=audio=on
Add the following line at end

then create this /etc/asound.conf

Code: Select all

pcm.!default {
    type            plug
    slave.pcm       "softvol"   #make use of softvol

pcm.softvol {
    type            softvol
    slave {
        pcm         "dmix"      #redirect the output to dmix (instead of "hw:0,0")
    control {
        name        "PCM"       #override the PCM slider to set the softvol volume level globally
        card        0
or a simple asound.conf without dmix just a softvol (so for this config you can skip adding the dtoverlay=i2s-mmap to /boot/config.txt)

Code: Select all

pcm.!default  {
 type plug     
 slave.pcm "speakerphat"

ctl.!default {
 type hw card 0

pcm.speakerphat {
  type softvol
  slave.pcm "plughw:0" "Master"
  control.card 0
actually in this second example you want to use "PCM" as mpd uses that tag to control volume via alsa... so using something like GMPC you can set the volume remotely on the pi running mpd

and in second example "speakerphat" is a tag you can define for yourself... so for example "i2sdac0" would work just as well regardless of what actual i2s hat it was running on and would reflect it was card (device) 0 which is the key thing.

Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: Set up ALSA to use dmix and softvol

Sun Apr 16, 2017 4:04 pm

Thank you for providing this, it has solved my question in another part of the forum: viewtopic.php?p=1128700#p1128700

Best regards, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

Posts: 16
Joined: Tue Mar 17, 2015 1:03 pm

Re: Set up ALSA to use dmix and softvol

Mon May 08, 2017 8:30 am

I've discovered this issue with the Adafruit stereo bonnet - I didn't realise volume control was going to be such a headache!

I've tried your changes below but I don't seem to have the desired results, I might be suffering from the alsamixer bug that you mentioned, did you find a solution to resolve this bug? I was going to clean reinstall to see if that resolved the issue, but that would be a bit of a headache.
skypi wrote:though seems a bug in alsamixer that remembers controls from previous asound.conf control tags even after you have removed that tag from asound.conf
Just to make sure I understand the desired result, if the changes are working correctly I should be able to change the volume in Alsamixer to the desired volume and this will affect any sound from the Pi, for example would the speaker test be affected by this volume change? or will some applications ignore the volume set in Alsamixer?

Thanks for your help

Return to “Advanced users”