1

I have 2 playback device where one is HDMI and the other is HAT sound card. The requirement is to play audio from card 0 or 1 without rebooting the system.

aplay -l

**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]                                  
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: sndrpistest [snd_rpi_s5_adcdac], device 0: Test HiFi tlv320aic31xx-hifi-0 []         
  Subdevices: 0/1
  Subdevice #0: subdevice #0

1) If I configure the following in ~./asoundrc and reboot, the audio is playing from HDMI

pcm.!default {
    type hw
    card 0                      ----> HDMI
}

ctl.!default {
    type hw           
    card 0                     ----> HDMI
}

If I configure the following in ~./asoundrc and reboot, the audio is playing from HAT sound card

pcm.!default {
    type hw
    card 1                      ----> HAT sound card
}

ctl.!default {
    type hw           
    card 1                     ----> HAT sound card
}

Is there is a way to configure the sound card from card 0 card 1 or vise versa without rebooting?

1

You can play from either, as long as the kernel modules for both are loaded.

The method for doing this is as follows :

  1. Stop lxpanel
  2. Unload the audio drivers (rmmod or modprobe -r)
  3. Load the audio drivers (modprobe)
  4. Start lxpanel

The reason why you have to disable or stop/start lxpanel is that the volume plugin hangs the system when you try to unload audio modules.

In this example, I will remove the volume plugin from lxpanel and pulse audio.

  1. Uninstall pulseaudio

    sudo apt remove pulseaudio

  2. Disable the volume plugin from lxpanel

    sed -i 's/\=volumealsa/\=REMOVEvolumealsa/' .config/lxpanel/LXDE-pi/panels/panel

  3. Reload your audio drivers

sudo modprobe -r snd_soc_audioinjector_pi_soundcard                             
sudo modprobe -r snd_soc_wm8731                                                 
sudo modprobe snd_soc_wm8731                                                    
sudo modprobe snd_soc_audioinjector_pi_soundcard   

It should now be working with the card you reloaded. In my case, I unloaded the audio injector stereo sound card and reloaded it. In your case, you should unload the sound card you have running in the "modprobe -r" calls and load in the other card.

You can see what snd modules are loaded using the lsmod command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.