# Audio setup for a computer with one or two stereo audio cards

pcm.!default {
  type asym
  playback.pcm {
    type plug
    # Uncomment this to duplicate audio to both devices
    #slave.pcm "both"
    # Use this to output audio only on the internal card
    slave.pcm "internalcard"
  }
  capture.pcm {
    type plug
    # You should probably tweak this to select the correct mic
    slave.pcm "hw:1,0"
  }
}

ctl.!default {
  type hw
  card 0
}

pcm.both {
  type route;
  slave.pcm {
    type multi;
    slaves.a.pcm "internalcard";
    slaves.b.pcm "externalcard";
    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; # front left
  ttable.1.3 1; # front right
}

pcm.internalcard {
  type dmix
  ipc_key_add_uid true

  ipc_key 1024
  ipc_perm 0660
  ipc_gid audio

  slave {
    # 2 for stereo, 6 for surround51, 8 for surround71
    channels 6
    pcm {
      # mplayer chooses S32_LE, but others usually S16_LE
      #format S32_LE
      format S16_LE

      # 44100 or 48000
      # 44100 for music, 48000 is compatible with most h/w
      #rate 44100
      rate 48000

      # http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
      # Maybe helps
      nonblock true

      type hw
      card 0
      device 0
      subdevice 0
    }

    # mplayer2 chooses 1024
    # period_size 512 with buffer_size 16384 stops crackling in xmame
    # 320 breaks flash - https://bbs.archlinux.org/viewtopic.php?id=129458
    #period_size 512
    period_size 1024
    #period_size 512

    # 4096 might make sound crackle
    # mplayer2 chooses 8192. Half-Life 2 chooses 16384.
    # If too large, use CONFIG_SND_HDA_PREALLOC_SIZE=2048
    buffer_size 16384
  }
  bindings {
    0 0
    1 1
  }
}

pcm.externalcard {
  type dmix
  ipc_key_add_uid true

  ipc_key 2048
  ipc_perm 0660
  ipc_gid audio

  slave {
    # 2 for stereo, 6 for surround51, 8 for surround71
    channels 6
    pcm {
      # mplayer chooses S32_LE, but others usually S16_LE
      #format S32_LE
      format S16_LE

      # 44100 or 48000
      # 44100 for music, 48000 is compatible with most h/w
      #rate 44100
      rate 48000

      # http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
      # Maybe helps
      nonblock true

      type hw
      card 1
      device 0
      subdevice 0
    }

    # mplayer2 chooses 1024
    # period_size 512 with buffer_size 16384 stops crackling in xmame
    # 320 breaks flash - https://bbs.archlinux.org/viewtopic.php?id=129458
    #period_size 512
    period_size 1024
    #period_size 512

    # 4096 might make sound crackle
    # mplayer2 chooses 8192. Half-Life 2 chooses 16384.
    # If too large, use CONFIG_SND_HDA_PREALLOC_SIZE=2048
    buffer_size 16384
  }
  bindings {
    0 0
    1 1
  }
  bindings {
    0 0
    1 1
  }
}

ctl.internalcard {
  type hw
  card 0
}

ctl.externalcard {
  type hw
  card 1
}