4

I have a raspberry pi 3 with usb dac for plug my microphone and I have a usb speacker too.

I installed on my pi, mopidy and other litle project.

I modified my ~/.asoundsrc for

pcm.!default {
  type asym
   playback.pcm {
     type plug
     slave.pcm "hw:1,0"
   }
   capture.pcm {
     type plug
     slave.pcm "hw:0,0"
   }
}

Everything work and when I reboot I have a new configuration added in the end of my .asoundrc file

pcm.!default {
      type asym
       playback.pcm {
         type plug
         slave.pcm "hw:1,0"
       }
       capture.pcm {
         type plug
         slave.pcm "hw:0,0"
       }
    }



    pcm.!default {
            type hw
            card 2
    }

    ctl.!default {
            type hw
            card 2
    }

With this modification, my litle project doesn't work, I must to delete

pcm.!default {
        type hw
        card 2
}

ctl.!default {
        type hw
        card 2
}

Do you know why, this configuration is added every reboot ?

Maybe this, can you help you to help me :)

cat /proc/asound/modules
   0 snd_usb_audio
   1 snd_usb_audio
   2 snd_bcm2835

Thanks

timothylhuillier
  • 43
  • 1
  • 1
  • 5
  • Just for testing, I would like you to try this. We are going to disable the onboard audio. To do that, type this in your terminal: sudo nano /boot/config.txt Page down to the bottom of the file and look for two lines that read: # Enable audio (loads snd_bcm2835) dtparam=audio=on Place a (pound sign #) in front of the line that reads: dtparam=audio=on To look like: #dtparam=audio=on Press CTRL + x and then press Enter to save your file. Also, you will need to reboot. What we want to know is if there is a conflict with the usb audio and the onboard. Good Luck! – Jason Woodruff Aug 30 '16 at 01:41
  • Hi Thanks for your answer and help. your modification don't resolve my problem but, now when I reboot pcm.!defaultand ctl.!defaultdon't have card 2 but card 0. – timothylhuillier Aug 30 '16 at 20:53

6 Answers6

1

The way I solved this problem was to run sudo raspi-config then go to Advanced Options and then Audio. This was set to Auto. When I changed this option to "Force 3.5mm headphone jack", it stopped overwriting my .asoundrc file on reboot.

1

This is an old problem that regularly re-surface, most recently after an upgrade to the latest kernel and firmware, for Raspian Stretch, 4.14.30-v7+.

It seem that it may have something to do with both how Raspberry Pi's are using the systemd services when boot and shutting down and how the ALSA daemons and services have been setup initially (or after system upgrade). My best guess is that the post install scripts for something is not recognizing that you already have an /home/pi/.asoundrc file and then tries to restore it to some default. It is unclear from where this default is coming from. Certainly not what's written in the comments of the many ALSA or system services config files or related man pages. But it seem to be coming from a bug in the lxpanels volume applet.

In my case, the following seem to have resolved the issue:

  • First remove the Volume Applet from the lxpanel, then:
# Make sure your .asoundrc is correct, then do:
alsactl kill save_and_quit
sudo shutdown now

PS. It also seem important to use shutdown, and not reboot!


Debugging attempts

If the above doesn't work, then read this.

As a side, there seem to be a bug in how systemctl is handling services. The FS in the pi is different (by missing parts) from other Debian based systems, so where the service scripts are located and handled is not fully according its own man pages.

To see the relevant ALSA related services, do:

sudo systemctl status alsa-restore alsa-state

Under normal circumstances you should be able to shutdown the suspected static services by something like:

sudo systemctl mask --system alsa-state.service --now
sudo systemctl mask --system alsa-restore.service --now

However, the runtime locations of [system,user,runtime, global] which are:

/etc/systemd/system-preset/*.preset
/run/systemd/system-preset/*.preset
/lib/systemd/system-preset/*.preset
/etc/systemd/user-preset/*.preset
/run/systemd/user-preset/*.preset
/usr/lib/systemd/user-preset/*.preset

are not respected as described in man systemd.preset.
To see all services and their current state, use:

systemctl list-unit-files -t service -all

You can also the reverse dependencies with:

systemctl list-dependencies --reverse alsa-restore.service

alsa-restore.service
● └─basic.target
●   └─multi-user.target
●     └─graphical.target

In any case, when disabling the service with mask, it should replace the file with a symlink to /dev/null, only that this doesn't happen in the right place (according to above). So instead we have to remove the file manually (backup it before) and then create the link.

cp /etc/systemd/system/alsa-restore.service ~/alsa-restore_service.bak
cd /etc/systemd/system/
sudo rm alsa-restore.service
sudo ln -s /dev/null alsa-restore.service

# It should look something like: 
ls -al /lib/systemd/system |grep alsa

lrwxrwxrwx  1 root root    9 Apr 25 13:23 alsa-restore.service -> /dev/null
lrwxrwxrwx  1 root root    9 Apr 25 13:26 alsa-state.service -> /dev/null
lrwxrwxrwx  1 root root    9 Jan 23  2017 alsa-utils.service -> /dev/null

Now make sure to repeat the above also for alsa-state.service,and the same files in the directory: /lib/systemd/system/ if not already there.

DISCLAIMER

The above is most likely not the correct way to do this, so please regard this as a very experimental work-around until that buggy beahviour has been resolved. It may very likely break your ALSA functionality altogether.

not2qubit
  • 1,407
  • 2
  • 14
  • 23
1

I had resolved such as similar situation by updating Raspberry pi environment. the steps are ,

  • Backup your data from Raspberry pi
  • check your current version $uname -a
  • update package information $sudo apt-get update
  • update installed packages $sudo apt-get upgrade
  • update to latest distribution $sudo apt-get dist-upgrade
  • update raspberry pi firm ware $sudo rpi-update
  • reboot $sudo reboot
  • check youe latest version $uname -a

After that, on my Raspberry pi was resolved such as "modified .asoundrc was rewriten after reboot". The NOOBS version was updated to 2.8.1 on 2018-4-24. Just my opinion, that it was a kind of ALSA Bug because I tried and failed and gather some informations about those phenomenon.

seedodge
  • 19
  • 2
1

Ok so I had a similar issue, I was connecting to my Pi with a bluetooth speaker, if the speaker was not on before I booted it would re-set the .asoundrc file. So irritating. I tried all of the above then I thought what if I just set the correct settings then make it readonly. Oddly enough this worked. All I did was: sudo chmod 0444 ./.asoundrc and that's it. all is well now.

Mick
  • 11
  • 1
  • 1
    This worked for me on Raspbian Stretch. Strange that setting permissions works, as i would have thought it was the system (ie. root) changing the file. – Lee Melbourne Aug 31 '19 at 23:53
  • Although now I am getting the below error when calling pyaudio. Things still seem to be working though. "Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 924" – Lee Melbourne Sep 01 '19 at 00:03
0

If you change default audio device from menu > preferences > Audio Device Settings > Sound Card select Sound Card > make default your ~/.asoundrc file will be changed

Manoj
  • 1
  • This seems to be my problem. Overwrite of .asoundrc on reboot with Stretch. Any ideas where I can 'undo' the checking of this box so the system no longer overwrites? – Lee Melbourne Aug 31 '19 at 22:41
-1

Undo what I asked you to do. After that, reboot. Once your RPi is back up, let's create a file:

sudo nano /etc/asound.conf

In that file, place this in it:

pcm.!default {
 type asym
   playback.pcm {
     type plug
     slave.pcm "hw:1,0"
   }
   capture.pcm {
     type plug
     slave.pcm "hw:0,0"
   }
}

Once done, save your file, then reboot.

Aurora0001
  • 6,308
  • 3
  • 23
  • 38
Jason Woodruff
  • 431
  • 4
  • 8
  • Thanks Jason but, no. nobody change I have already pcm.!default and ctl.!default I try to delete /home/pi/.asoundrc but pcm et ctl come back whitout my configuration in /etc/asound.conf – timothylhuillier Aug 31 '16 at 16:12