Mixing different audio sources

 

Mixing different audio sources

The Raspberry Pi ASoc sound subsystem does not allow concurrent access to the sound card from multiple processes. Therefore if you already have a process running that uses your HiFiBerry sound card to play back something, you can’t have another process accessing the driver. Depending on the program you use, you will get a more or less readable error message. This even happens if one process isn’t really playing something, but has blocked the sound card. Many programs do this.

There are some workaround to deal with this kind of problem. One is using Pulseaudio. However, while Pulseaudio is very powerful it is also extremely resource-intense on the Raspberry Pi.

Our user Steven has provided the following guide how to use the dmix ALSA module to create a ALSA device that allows simultaneous playback. We provide this guide “as is”, we can’t give individual support for it.

1. Enable mmap

The dmixer module uses a specific interface to send data to the sound card called mmap. The use of this is disabled on the Raspberry Pi by default as it is experimental. Note that we can’t guarantee that this will work flawless with a specific kernel version. Future kernel might break this feature!

Add the following line to /boot/config.txt and reboot:

dtoverlay=i2s-mmap

2. ConfigureĀ /etc/asound.conf (or .asoundrc in your home directory)

pcm.hifiberry { 
  type hw card 0 
}

pcm.!default { 
  type plug 
  slave.pcm "dmixer" 
}

pcm.dmixer { 
  type dmix 
  ipc_key 1024 
  slave { 
    pcm "hifiberry" 
    channels 2 
  } 
}

ctl.dmixer { 
  type hw 
  card 0 
}
Last updated: October 4, 2019