Skip to content

Instantly share code, notes, and snippets.

@J-Rios
Created May 28, 2020 22:34
Show Gist options
  • Save J-Rios/955f236e713576bb8f65eed2a0cddcaa to your computer and use it in GitHub Desktop.
Save J-Rios/955f236e713576bb8f65eed2a0cddcaa to your computer and use it in GitHub Desktop.
Linux Mixing Multiple Audio Streams (play audios from different applications at same time).

Linux Mixing Multiple Audio Streams

We are going to create a virtual sound device that allows mix audio streams from multiples sources, so it can let you play audios from different applications at same time.

First we need to install next alsa packages:

sudo apt-get install alsa-oss alsaplayer mpg321 alsaplayer-alsa alsa-base

Then, we need to create/modify user ".asoundrc" file: nano ~/.asoundrc

pcm.my_card {
    type hw
    card 2
    # mmap_emulation true
}

pcm.dmixed {
    type dmix 
    ipc_key 1024 
    #  ipc_key_add_uid false   # let multiple users share
    #  ipc_perm 0666           # IPC permissions for multi user sharing (octal, default 0600)
    slave {
    pcm "my_card" 
    #   rate 48000
    #   period_size 512
    }
}

pcm.dsnooped {
    type dsnoop 
    ipc_key 2048 
    slave {
    pcm "my_card" 
    #   rate 48000
    #   period_size 128
    }
}

pcm.asymed {
    type asym 
    playback.pcm "dmixed" 
    capture.pcm "dsnooped"
}

pcm.pasymed {
    type plug 
    slave.pcm "asymed"
}

pcm.dsp0 {
    type plug
    slave.pcm "asymed"
}

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

Due we have setup a "!default" device, it will be used in commons softwares. If we want to use this in a custom software, we need to make sure to open that "!default" device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment