title: ALSA combine mic inputs and speaker outputs for Skype
body: <p>I'm trying to merge two mic inputs and two outputs to use in Skype, Linux CentOS7
  I know I can do it with a hardware mixer, but I want to try to do it by software.</p>
  
  <p>Just finished a bash script to combine outputs, and it's running well. I'm getting crazy trying to combine inputs.</p>
  
  <p>This is the name of the two usb soundcard mic inputs:
  alsa_input.usb-C-Media_Electronics_Inc._USB_Audio_Device-00-Device.analog-mono
  alsa_input.usb-C-Media_Electronics_Inc._USB_Audio_Device-00-Device_1.analog-mono</p>
  
  <p>I found a lot of on pacmd / pactl info, and tested a lot of commands, but nothing works.</p>
  
  <pre><code>#!/bin/bash
  
  function getOutputs {
      index=""
      name=""
      #declare -A sinks_list
  
      # Get dirty sinks list
      raw_sinks=`pacmd list-sinks`
  
      # Parse the sources list
      while IFS= read -r line
      do
          #Check if index and name are populated
          if [ -n "$index" ] &amp;&amp; [ -n "$name" ]
          then
              sinks_list[$index]=$name
              index=""
              name=""
          fi
          # Get indexs and index number
          if grep -q index: &lt;&lt;&lt;"$line"
          then
              index=$(echo "$line" | sed 's/[^0-9]*//g')
          fi
          # Get sound card output name and remove other than c-media soundcards
          if grep -q name: &lt;&lt;&lt;"$line" &amp;&amp; grep -q stereo &lt;&lt;&lt;"$line" &amp;&amp; grep -q C-Media_Electronics_Inc._USB_Audio_Device &lt;&lt;&lt;"$line"
          then
              name=$(echo "$line" | sed -e "s/name://" | sed 's|[&lt;&gt;,]||g'| tr -d '[:space:]')
          fi
      done &lt;&lt;&lt; "$raw_sinks"
  }
  
  function getInputs {
      index=""
      name=""
      #declare -A sources_list
  
      # Get dirty sources list
      raw_sources=`pacmd list-sources`
  
      # Parse the sources list
      while IFS= read -r line
      do
          #Check if index and name are populated
          if [ -n "$index" ] &amp;&amp; [ -n "$name" ]
          then
              sources_list[$index]=$name
              index=""
              name=""            
          fi
          # Get indexs and index number
          if grep -q index: &lt;&lt;&lt;"$line"
          then
              index=$(echo "$line" | sed 's/[^0-9]*//g')
          fi
          # Get sound card output name and remove other than c-media soundcards
          if grep -q name: &lt;&lt;&lt;"$line" &amp;&amp; grep -q mono &lt;&lt;&lt;"$line" &amp;&amp; grep -q C-Media_Electronics_Inc._USB_Audio_Device &lt;&lt;&lt;"$line"
          then
              name=$(echo "$line" | sed -e "s/name://" | sed 's|[&lt;&gt;,]||g'| tr -d '[:space:]')
          fi
      done &lt;&lt;&lt; "$raw_sources"
  }
  
  function combineOutputs {
      soundcard_names=""
  
      for K in "${!sinks_list[@]}"; 
      do
          # Set device default volume
          pacmd set-sink-volume ${sinks_list[$K]} 65536
          soundcard_names+=${sinks_list[$K]},
      done
  
      pacmd load-module module-combine-sink sink_name=MySink slaves=$soundcard_names
  
      # Set default volume
      pacmd set-sink-volume MySink 65536
  
      # Set as default source
      pacmd set-default-sink MySink
  }
  
  function combineInputs {
      # Create a null sink to merge signals
      pacmd load-module module-null-sink sink_name=MyLoopSink
  
      # One by one add mics to the null sink
      for K in "${!sources_list[@]}"; 
      do
          pactl load-module module-loopback source=$K sink=MyLoopSink
      done
  
      pacmd set-default-source MyLoopSink.monitor
      # Create a virtual source. Note: using uplink_sink=MyLoopSink removes all the devices
      pacmd load-module module-virtual-source source_name=loop_source
  
      # Set as default source
      pacmd set-default-source loop_source
  }
  
  # First restart pulseaudio to get sure we are working with a clean configuration
  pulseaudio -k
  sleep 10
  
  # Combine Inputs
  declare -A sources_list
  getInputs
  # Loop through array values
  echo "Soundcard's inputs:"
  for K in "${!sources_list[@]}"; 
  do
      echo $K --- ${sources_list[$K]}
  done
  combineInputs
  
  # Combine Outputs
  declare -A sinks_list
  getOutputs
  # Loop through array values
  echo "Soundcard's outputs:"
  for K in "${!sinks_list[@]}"; 
  do
      echo $K --- ${sinks_list[$K]}
  done
  combineOutputs
  </code></pre>
  
  <p>Any clues? Thanks in advance.</p>