asound.config 虚拟声卡

kehuadong / 2023-08-04 / 原文

defaults.pcm.rate_converter "speexrate_medium"
#defaults.pcm.carplay_period_size 3000

pcm.!default {
	type asym
	playback {
		pcm "softvol-default"
	}
	capture {
		pcm "maininput"
	}
}

# 虚拟设备 ================================================

# 默认
pcm.!softvol-default {
    type plug
    slave {
        pcm "default_softvol"
        channels 2
    }
}

pcm.!default_softvol {
    type softvol
    slave.pcm "dmix_virtual"
    control {
        name "softvol-default"
        count 2
    }
}

# 本地多媒体
pcm.!mainaudio {
    type plug
    slave {
        pcm "mainaudio_softvol"
        channels 2
    }
}

pcm.!mainaudio_softvol {
    type softvol
    slave.pcm "dmix_virtual"
    control {
        name "mainaudio"
        count 2
    }
}


# 蓝牙音乐
pcm.!bt_a2dp {
    type plug
    slave {
        pcm "bt_a2dp_softvol"
        channels 2
    }
}

pcm.!bt_a2dp_softvol {
    type softvol
    slave.pcm "dmix_virtual"
    control {
        name "bt_a2dp"
        count 2
    }
}

# 蓝牙电话
pcm.!bt_hfp {
    type plug
    slave {
        pcm "bt_hfp_softvol"
        channels 4
    }
    route_policy duplicate
}

pcm.!bt_hfp_softvol {
    type softvol
    slave.pcm "dmix"
    control {
        name "bt_hfp"
        count 4
    }
}

# CarPlay音乐
pcm.!cp_main {
    type plug
    slave {
        pcm "cp_main_softvol"
        channels 2
    }
}

pcm.!cp_main_softvol {
    type softvol
    slave.pcm "dmix_virtual"
    control {
        name "cp_main"
        count 2
    }
}

# CarPlay导航和按键音
pcm.!cp_alt {
    type plug
    slave {
        pcm "cp_alt_softvol"
        channels 4
    }
    route_policy duplicate
}

pcm.!cp_alt_softvol {
    type softvol
    slave.pcm "dmix"
    control {
        name "cp_alt"
        count 4
    }
}

# CarPlay语音
pcm.!cp_speech {
    type plug
    slave {
        pcm "cp_speech_softvol"
        channels 4
    }
    route_policy duplicate
}

pcm.!cp_speech_softvol {
    type softvol
    slave.pcm "dmix"
    control {
        name "cp_speech"
        count 4
    }
}

# CarPlay通话
pcm.!cp_call {
    type plug
    slave {
        pcm "cp_call_softvol"
        channels 4
    }
    route_policy duplicate
}

pcm.!cp_call_softvol {
    type softvol
    slave.pcm "dmix"
    control {
        name "cp_call"
        count 4
    }
}

# CarPlay来电铃声
pcm.!cp_ring {
    type plug
    slave {
        pcm "cp_ring_softvol"
        channels 4
    }
    route_policy duplicate
}

pcm.!cp_ring_softvol {
    type softvol
    slave.pcm "dmix"
    control {
        name "cp_ring"
        count 4
    }
}

# Radio/Aux播放到虚拟声卡的dmix(2通道)
pcm.!radio {
    type plug
    slave {
        pcm "radio_softvol"
		channels 2
    }
}

pcm.!radio_softvol {
    type softvol
    slave.pcm "dmix_virtual"
    control {
        name "radio"
        count 2
    }
}

# 从虚拟声卡录回来,进行EQ处理后,(2通道转4通道)播放到物理声卡的dmix
pcm.!eq_playback {
    type plug
    slave {
        pcm "eq_playback_softvol"
		channels 4
    }
    route_policy duplicate
}

pcm.!eq_playback_softvol {
    type softvol
    slave.pcm "dmix"
    control {
        name "eq_playback"
        count 4
    }
}

# 参考声
pcm.!refinput {
	type plug
	slave {
		pcm "refmic"
	}
}

pcm.!refmic {
	type dsnoop
	ipc_key 2222
	slave {
		pcm "hw:snddaudio2"
		rate 48000
		channels 4
	}
	bindings.0 0
}

# 虚拟声卡的dmix
pcm.!dmix_virtual {
	type dmix
	ipc_key 1110
	ipc_perm 0666

	slave {
		pcm hw:snddaudio1
		rate 48000
		channels 2
		#period_size 1024
		periods 4
	}
}

pcm.!dmix {
	type dmix
	ipc_key 1111
	ipc_perm 0666

	slave {
		pcm hw:snddaudio2
		rate 48000
		channels 4
		#period_size 1024
		periods 4
	}
}


# 插件 ================================================

pcm.!maininput {                     
	type plug                    
	slave {                      
		pcm "micinput"
	}                            
} 

pcm.!linein {
	type plug
	slave {
		pcm "record"
	}
}


# ================================================

pcm.!micinput {
	type dsnoop              
	ipc_key 5778             
	slave {
		pcm "hw:audiocodec"
		rate 48000
		channels 1
	}
	bindings.0 0
}

# Radio/Aux录音
pcm.!record {
	type dsnoop
	ipc_key 5779
	slave {
			pcm "hw:audiocodec"
			rate 48000
			channels 3
			period_size 1024
			periods 4
	}
	#bindings.0 0
}


pcm.Playback {
    type plug
    slave.pcm {
        type softvol
        slave.pcm PlaybackDmix
        control {
            name "Soft Volume Master"
            card snddaudio2
        }
        min_dB -51.0
        max_dB 0.0
        resolution 256
    }
    slave.rate 48000
    slave.format S16_LE
}

pcm.PlaybackDmix {
    type plug
    slave.pcm {
        type dmix
        ipc_key 1111
        ipc_perm 0666
        slave {
            pcm "hw:snddaudio2"
            format S16_LE
            rate 48000
            channels 2
            period_size 960
            periods 8
        }
    }
}

pcm.PlaybackEQ {
    type plug
    slave.pcm {
        type awequal
        slave.pcm "Playback"
        config_file "/etc/awequal.conf"
        tuning_support false
        verbose true
    }
    slave.rate 48000
    slave.format S16_LE
    slave.channels 2
}

pcm.PlaybackAec {
    type plug
    slave.pcm {
        type softvol
        slave.pcm PlaybackAecDmix
        control {
            name "PlaybackAec Soft Volume Master"
            card snddaudio2
        }
        min_dB -51.0
        max_dB 0.0
        resolution 256
    }
    slave.rate 48000
    slave.format S16_LE
    slave.channels 1
}

pcm.PlaybackAecDmix {
    type plug
    slave.pcm {
        type dmix
        ipc_key 1111
        ipc_perm 0666
        slave {
            pcm "hw:snddaudio2"
            format S16_LE
            rate 48000
            channels 1
            period_size 960
            periods 8
        }
    }
}

pcm.CaptureDsnoop {
    type plug
    slave.pcm {
        type dsnoop
        ipc_key 2222
        ipc_perm 0666
        slave {
            pcm "hw:audiocodec"
#            rate 16000
            rate 48000
            channels 3
            period_size 640
            periods 4
        }
    }
}

pcm.CaptureDsnoop1 {
    type hooks
    slave.pcm {
        type dsnoop
        ipc_key 2222
        ipc_perm 0666
        slave {
            pcm "hw:audiocodec"
            rate 48000
#            rate 16000
            channels 3
            period_size {
                @func refer
                name defaults.pcm.carplay_period_size
                default 640
            }
            periods {
                @func refer
                name defaults.pcm.carplay_periods
                default 4
            }
        }
    }
    hooks.0 {
        type ctl_elems
        hook_args [
        {
            name "ADC1 Input FMINL Switch"
            optional true
            value 1
        }
        {
            name "ADC1 Input LINEINL Switch"
            optional true
            value 0
        }
        {
            name "ADC1 Input MIC1 Boost Switch"
            optional true
            value 0
        }
        {
            name "ADC2 Input FMINR Switch"
            optional true
            value 1
        }
        {
            name "ADC2 Input LINEINR Switch"
            optional true
            value 0
        }
        {
            name "ADC2 Input MIC2 Boost Switch"
            optional true
            value 0
        }
        {
            name "ADC3 Input MIC3 Boost Switch"
            optional true
            value 1
        }
        ]
    }
}

pcm.CaptureDaudio2 {
    type hooks
    slave.pcm {
        type dsnoop
        ipc_key 4444
        ipc_perm 0666
        slave {
            pcm "hw:snddaudio2"
            rate 48000
            #rate 16000
            channels 2
            period_size {
                @func refer
                name defaults.pcm.carplay_period_size
                default 640
            }
            periods {
                @func refer
                name defaults.pcm.carplay_periods
                default 4
            }
        }
    }
    hooks.0 {
        type ctl_elems
        hook_args [
        {
            name "sunxi daudio loopback debug"
            optional true
            value 1
        }
        ]
    }
}

pcm.CaptureMulti1 {
    type plug
    slave.pcm {
        type multi
        slaves {
            a { pcm "CaptureDsnoop1" channels 3 }
            b { pcm "CaptureDaudio2" channels 2 }
        }
        bindings {
            0 { slave a channel 2 }
            1 { slave b channel 0 }
            2 { slave b channel 1 }
        }
    }
    ttable.0.0 1
    ttable.1.1 1
    ttable.2.1 1

}

pcm.nfecnr_capture {
    type plug
    slave.pcm {
        type aw_nfecnr
        slave.pcm "CaptureMulti1"

        config_file "/etc/audio_ecnr_value.xml"
        verbose false
        dump_file true
        dsp_period_time 10

#        rate 16000
        rate 48000
        format S16_LE
        in_channels 2
        out_channels 1
    }
    slave.rate 48000
#    slave.rate 16000
    slave.channels 2
    slave.format S16_LE
}

pcm.aweq_playback {
    type plug
    slave.pcm {
        type aw_eq
        slave.pcm "hw:snddaudio2"

        config_file "/etc/eq.conf"
        verbose false
        dump_file true
        dsp_period_time 125

        rate 48000
        format S16_LE
        channels 2
    }
    slave.rate 48000
    slave.channels 2
    slave.format S16_LE
}
pcm.CaptureMultiLineIn {
    type plug
    slave.pcm {
        type multi
        slaves {
            a { pcm "CaptureDsnoop1" channels 3 }
        }
        bindings {
            0 { slave a channel 0 }
            1 { slave a channel 1 }
        }
    }
    ttable.0.0 1
    ttable.0.1 1
}

pcm.CaptureMultiMic {
    type plug
    slave.pcm {
        type multi
        slaves {
            a { pcm "CaptureDsnoop1" channels 3 }
        }
        bindings {
            0 { slave a channel 2 }
        }
    }
    ttable.0.0 1
}