hw/gaming: add pipewire low latency settings from nix-gaming

This commit is contained in:
Aly Raffauf 2024-12-19 17:20:11 -05:00
parent 5fc7eeb369
commit 44c2f58082

View file

@ -48,6 +48,85 @@
extraArgs = lib.mkDefault ["-M" "409600,307200" "-S" "409600,307200"];
};
pipewire = let
rate = 48000;
quantum = 64;
qr = "${toString quantum}/${toString rate}";
in {
# Make sure PipeWire is enabled.
enable = true;
# Write extra config.
extraConfig.pipewire = {
"99-lowlatency" = {
context = {
properties.default.clock.min-quantum = quantum;
modules = [
{
name = "libpipewire-module-rtkit";
flags = ["ifexists" "nofail"];
args = {
nice.level = -15;
rt = {
prio = 88;
time.soft = 200000;
time.hard = 200000;
};
};
}
{
name = "libpipewire-module-protocol-pulse";
args = {
server.address = ["unix:native"];
pulse.min = {
req = qr;
quantum = qr;
frag = qr;
};
};
}
];
stream.properties = {
node.latency = qr;
resample.quality = 1;
};
};
};
};
# Ensure WirePlumber is enabled explicitly (defaults to true while PW is enabled)
# + write extra config to ship low latency rules for alsa.
wireplumber = {
enable = true;
configPackages = let
# Generate "matches" section of the rules
matches = lib.generators.toLua {
multiline = false; # Looks better while inline
indent = false;
} [[["node.name" "matches" "alsa_output.*"]]]; # Nested lists are to produce `{{{ }}}` in the output.
# Generate "apply_properties" section of the rules.
apply_properties = lib.generators.toLua {} {
"audio.format" = "S32LE";
"audio.rate" = rate * 2;
"api.alsa.period-size" = 2;
};
in [
(pkgs.writeTextDir "share/lowlatency.lua.d/99-alsa-lowlatency.lua" ''
-- Generated by nix-gaming
alsa_monitor.rules = {
{
matches = ${matches};
apply_properties = ${apply_properties};
}
}
'')
];
};
};
udev.extraRules = ''
# Significantly improved I/O performance
## SSD