# linux jack audio config ## linux audio `ALSA` is kernel module 必選 {jack, pulseaudio, pipewire} 是 usermode audio server, 三選一。又因為 jack realtime 最好,可以優先使用。 alsa-->jack-->mpd 這個打通了 but, since ubuntu expect pipewire, alsa(remained audio card)-->pipewire-->system desktop app 被強制用hdmi。 由於pipewire 移除可能會問題,所以最佳解是。 1. 讓 jack 管理盡量多的 audio 介面 1. 讓 pipewire 做為jack 的 二級server,而非直接和alsa 對接(只有jack 可以)。 Wireplumber 是什麼? > WirePlumber is a powerful session and policy manager for PipeWire 簡單說就是要一起才能工作。 ideal 的 情況是 alsa --> jack --> pipewire --> wireplumber --> gnome-control-center ### jack config jackd 啟動時只能選一個 device。然後用 alsa_in, alsa_out 去加入其他device。 jack2 == jackdmp == jackd `aplay -l` ```ini #/etc/systemd/system/jack.service [Unit] Description=JACK Audio Connection Kit Documentation=man:jackd(1) After=sound.target local-fs.target StartLimitIntervalSec=3 StartLimitBurst=5 [Service] Type=notify #EnvironmentFile=-/etc/jack/%i.conf #EnvironmentFile=-%h/.config/jack/%i.conf User=morgana Environment="JACK_NO_AUDIO_RESERVATION=1" ExecStart=/usr/bin/jackd -P95 -dalsa -dhw:2,0 -r44100 -n3 -p512 #ExecStart=@PREFIX@/bin/jackd $JACK_OPTIONS -d $DRIVER -d $DEVICE $DRIVER_SETTINGS ExecStartPost=/usr/local/bin/add-jack-devices.sh Restart=on-failure LimitRTPRIO=95 LimitRTTIME=infinity LimitMEMLOCK=infinity [Install] WantedBy=multi-user.target ``` ```sh #!/bin/bash # filepath: /usr/local/bin/add-jack-devices.sh # Add HDMI 1 from card 0 (HDA NVidia) #alsa_in -j "HDMI_1_Nvidia" -d hw:0,7 & alsa_out -j "HDMI_1_Nvidia" -d hw:0,7 & # Add HDMI 1 (ASUS VZ27V) from card 1 (HD-Audio Generic) #alsa_in -j "HDMI_1_ASUS" -d hw:1,7 & alsa_out -j "HDMI_1_ASUS" -d hw:1,7 & # Add ALC897 Analog from card 2 (HD-Audio Generic) #already add #alsa_in -j "ALC897_Analog" -d hw:2,0 & #alsa_out -j "ALC897_Analog" -d hw:2,0 & exit 0 ``` ### pipewire config [pipewire.conf](https://docs.pipewire.org/page_man_pipewire_conf_5.html#pipewire_conf__drop-in_configuration_files) ```yaml #/home/morgana/.config/pipewire/pipewire.conf.d/custom.conf context.properties = { default.clock.rate = 48000 default.clock.allowed-rates = [ 48000 ] default.clock.quantum = 1024 default.clock.min-quantum = 128 default.clock.max-quantum = 2048 } context.modules = [ { name = libpipewire-module-jack-tunnel } { name = libpipewire-module-jackdbus-detect } ] ``` ```yaml # /home/morgana/.config/pipewire/jack.conf.d/custom.conf jack.properties = { rt.prio = 88 node.latency = 1024/48000 node.lock-quantum = true jack.show-monitor = true jack.merge-monitor = true jack.show-midi = true jack.short-name = false jack.self-connect-mode = allow jack.default-as-system = true } ``` [jack.conf](https://docs.pipewire.org/page_man_pipewire-jack_conf_5.html) 就能 設定 pipewire `pw-cli`(Interact with a PipeWire instance.) if you need restart `systemctl --user restart pipewire` may work ### wireplumber 最後是 wirePlumber(一般 pipewire 對就ok) `wpctl status` > `systemctl --user status xdg-desktop-portal` > `systemctl --user status wireplumber` 最後其實要確定是否對接到 `gnome-control-center` 要注意 `pulseaudio` 和 `pipewire-pulse` 會 二選一 自動 install。所以不要 uninstall `pipewire-pulse` ## mpd > 可能改成 系統當 output,在 系統控管下會更好 ``` # ~/.config/mpd/mpd.conf music_directory "~/Music/mpd" playlist_directory "~/.config/mpd/playlists" db_file "~/.config/mpd/database" # Uncomment to enable the functionalities #playlist_directory "~/.config/mpd/playlists" #pid_file "~/.config/mpd/pid" #state_file "~/.config/mpd/state" #sticker_file "~/.config/mpd/sticker.sql" #user "mpd" #group "audio" bind_to_address "0.0.0.0" auto_update "yes" follow_outside_symlinks "yes" follow_inside_symlinks "yes" zeroconf_enabled "yes" zeroconf_name "Music Player @ %h" input { plugin "curl" } decoder { plugin "hybrid_dsd" enabled "no" } decoder { plugin "wildmidi" enabled "no" } # mpd with jack in root priviledge is buggy. use it with user mode. #[mpc can't control volume?](https://forums.raspberrypi.com/viewtopic.php?t=150505) audio_output { type "jack" name "jack output" client_name "mpd" mixer_type "software" } # An example of an ALSA output: # minor bug: mixer: Failed to read mixer for 'My ALSA Device': no such mixer control: PCM # still work. # make sure jack doens't start. # audio_output { # type "alsa" # name "My ALSA Device" # # device "hw:0,0" # optional # device "hw:CARD=sofhdadsp,DEV=0" #this will work # # mixer_type "hardware" # optional # # mixer_device "default" # optional # # mixer_control "PCM" # optional # # mixer_index "0" # optional # } filesystem_charset "UTF-8" ``` `systemctl --user status mpd.service` * [Problem starting JACK server "Jack Server is not running or cannot be started"](https://askubuntu.com/questions/557906/problem-starting-jack-server-jack-server-is-not-running-or-cannot-be-started)