title: Alsa : loop with dmix
body: <p>I'm using snd-aloop to record currently played sound.
  I'm able to play a sound, hear it and record it. 
  But I've lost software mixing feature : I cannot anymore play multiple sounds at a time.</p>
  
  <p>Here is my working configuration with sound play and record (no mixing) :</p>
  
  <pre><code>pcm.multi {
      type route;
      slave.pcm {
          type multi;
          slaves.a.pcm "output";
          slaves.b.pcm "loopin";
          slaves.a.channels 2;
          slaves.b.channels 2;
          bindings.0.slave a;
          bindings.0.channel 0;
          bindings.1.slave a;
          bindings.1.channel 1;
          bindings.2.slave b;
          bindings.2.channel 0;
          bindings.3.slave b;
          bindings.3.channel 1;
      }
  
      ttable.0.0 1;
      ttable.1.1 1;
      ttable.0.2 1;
      ttable.1.3 1;
  }
  
  pcm.!default {
          type plug
          hint.description "default with sound loop"
          slave.pcm "multi"
  }
  
  pcm.output {
          type hw
          card 0
  }
  
  pcm.loopin {
          type plug
          slave.pcm "hw:1,0,0"
  }
  
  pcm.loopout {
          type plug
          slave.pcm "hw:1,1,0"
  }
  </code></pre>
  
  <p>I've tried different configurations  <a href="https://unix.stackexchange.com/questions/194547/how-can-i-use-alsa-dmix-and-multi-plugins-together" title="Solution for mixing">https://unix.stackexchange.com/questions/194547/how-can-i-use-alsa-dmix-and-multi-plugins-together</a></p>
  
  <p>I've tested with this config : </p>
  
  <pre><code>pcm.snd_card { # my usual sound card
      type hw
      card 0
  }
  
  ctl.!default { # default control; alsamixer and such will use this
      type hw
      card 0
  }
  
  # software mixer for sound card
  pcm.dmixer {
      type dmix
      ipc_key 1024
      ipc_perm 0666 # allow other users
      slave.pcm "snd_card"
      slave {
          period_time 0
          period_size 1024
          buffer_size 4096
          channels 2 # must match bindings
      }
      bindings {
          0 0
          1 1
      }
  }
  
  # software mixer for loopback device
  pcm.dmixerloop {
      type dmix
      ipc_key 2048
      ipc_perm 0666 # allow other users
      slave.pcm "hw:1,0,0"
      slave {
          period_time 0
          period_size 1024
          buffer_size 4096
          channels 2 # must match bindings
      }
      bindings {
          0 0
          1 1
      }
  }
  
  
  pcm.!default {
      type plug
    hint.description "default with sound loop"
      slave.pcm "out"
  }
  
  # Multi, splitting onto usual card and loopback
  pcm.out {
      type plug
      slave.pcm {
          type multi
          slaves {
              a { channels 2 pcm "dmixer" }
              b { channels 2 pcm "dmixerloop" }
          }
          bindings {
              0 { slave a channel 0 }
              1 { slave a channel 1 }
              2 { slave b channel 0 }
              3 { slave b channel 1 }
          }
      }
      ttable [
          [ 1 0 1 0 ]   # left  -&gt; a.left,  b.left
          [ 0 1 0 1 ]   # right -&gt; a.right, b.right
      ]
  }
  </code></pre>
  
  <p>Here is result of commands using different pcms :</p>
  
  <pre><code>aplay -D default /tmp/test.wav
  ALSA lib pcm_dmix.c:1109:(snd_pcm_dmix_open) unable to open slave
  aplay: main:788: erreur à l'ouverture audio: Argument invalide
  &gt; :( $ aplay -D dmixer /tmp/test.wav
  ALSA lib pcm_dmix.c:1109:(snd_pcm_dmix_open) unable to open slave
  aplay: main:788: erreur à l'ouverture audio: Argument invalide
  &gt; :( $ aplay -D snd_card /tmp/test.wav
  Lecture WAVE '/tmp/test.wav' : Signed 16 bit Little Endian, Fréquence 48000 Hz, Stéréo
  </code></pre>
  
  <p>From these tests, I do not understant several points :</p>
  
  <ul>
  <li>I cannot open "dmixer" pcm slave i.e. "snd_card", but I can play a
  sound using "snd_card". Why doesn't "dmixer" pcm open its slave? </li>
  <li>I can play several sounds using pcm "snd_card"    ( I call at a same
  time several  <code>aplay -D snd_card /tmp/test.wav</code> )    and I hear a mix
  of sounds. Where is software mixing done? when I    play on
  "snd_card" dmix plugin is not used</li>
  </ul>
  
  <p>How can I have software mixing and loopback?</p>