# This is the ALSA device setup for my desktop PC with Gigabyte B450 Aorus Pro and Motu M4 USB audio interface.

pcm.system_default = "pcm.combo"
ctl.system_default = "ctl.hda_hw"

#############################
########## SPECIAL ##########
#############################

pcm.combo {
    type asym
    playback.pcm "hda_softvol"
    capture.pcm "m4_in_mix_44100"
    hint {
        show on
        description "HDA out / M4 in"
    }
}

###########################################
########## HDA INTEGRATED AUDIO ###########
###########################################

# HDA hardware digital out and analog in/out.
pcm.hda_hw {
    type hw
    card Generic
    device 0
    subdevice 0
}
ctl.hda_hw {
    type hw
    card Generic
}

# HDA hardware digital out.
pcm.hda_digital_hw {
    type hw
    card Generic
    device 1
    subdevice 0
}
ctl.hda_digital_hw {
    type hw
    card Generic
}

# Asymmetric device @ 44.1 kHz.
pcm.hda {
    type asym
    playback.pcm "hda_out_mix_44100"
    capture.pcm "hda_in_mix_44100"
    hint {
        show on
        description "HDA asymmetric @ 44.1 kHz"
    }
}

# Mixing output device.
pcm.hda_out_mix_44100 {
    type plug
    slave.pcm {
        type dmix
        ipc_key 20000
        slave {
            pcm "hda_hw"
            format S32_LE
            rate 44100
            periods 4
            period_size 512
        }
    }
    hint {
        show on
        description "HDA mix out"
    }
}

# Mixing input device.
pcm.hda_in_mix_44100 {
    type dsnoop
    ipc_key 30000
    slave {
        pcm "hda_hw"
        format S32_LE
        rate 44100
        periods 4
        period_size 512
    }
    hint {
        show on
        description "HDA mix in"
    }
}

#############################
########## MOTU M4 ##########
#############################

pcm.m4_hw {
    type hw
    card M4
    device 0
    subdevice 0
}
ctl.m4_hw {
    type hw
    card M4
}

pcm.m4_quad {
    type plug
    slave {
        format S32_LE
        pcm "m4_hw"
    }
    hint {
        show on
        description "M4 1/2/3/4 quad"
    }
}

pcm.m4 {
    type plug
    slave {
        format S32_LE
        pcm {
            type multi
            slaves.out.pcm "m4_quad"
            slaves.out.channels 4
            bindings.0.slave out
            bindings.0.channel 0
            bindings.1.slave out
            bindings.1.channel 1
            bindings.2.slave out
            bindings.2.channel 2
            bindings.3.slave out
            bindings.3.channel 3
        }
    }
    ttable {
        0.0 1
        1.1 1
        0.2 1
        1.3 1
    }
    hint {
        show on
        description "M4 1/2+3/4 dual stereo"
    }
}

pcm.m4_mix {
    type asym
    playback.pcm "m4_out_mix_44100"
    capture.pcm "m4_in_mix_44100"
    hint {
        show on
        description "M4 asymmetric @ 44.1 kHz"
    }
}

pcm.m4_out_mix_44100 {
    type plug
    slave.pcm {
        type dmix
        ipc_key 40000
        slave {
            pcm "m4_hw"
            rate 44100
            periods 4
            period_size 512
        }
    }
    hint {
        show on
        description "M4 out mix 44.1 kHz"
    }
}

pcm.m4_in_mix_44100 {
    type plug
    slave.pcm {
        type dsnoop
        ipc_key 50000
        slave {
            pcm "m4_hw"
            rate 44100
            periods 4
            period_size 512
        }
    }
    hint {
        show on
        description "M4 in mix 44.1 kHz"
    }
}

# Note that both pcm.m4_softvol and hda_softvol use the same control "Virtual Master".
# This is to have a single master volume for two audio interfaces, controllable from the system tray via volumeicon for example.
# The use case for this is a setup where the HDA output is monitored via the M4.
pcm.m4_softvol {
    type softvol
    slave {
        pcm "m4"
    }
    control {
        name "Virtual Master"
        card "M4"
    }
    hint {
        show on
        description "M4 software volume control"
    }
}

pcm.hda_softvol {
    type softvol
    slave {
        pcm "hda"
    }
    control {
        name "Virtual Master"
        card "M4"
    }
    hint {
        show off
        description "HDA software volume control"
    }
}
