NotAShelf / nyx

My overengineered NixOS flake. Desktops, laptops, servers and everything else that can run an OS.
https://nyx.notashelf.dev/
GNU General Public License v3.0
287 stars 8 forks source link

Low latency setup not working? #67

Closed VeilSilence closed 1 month ago

VeilSilence commented 1 month ago

Greetings. I'm a newbie in NixOS, so I am bit clueless about how thing work on NixOS.

As title says, low latency setup not working at all, or at least for me? Initially, I followed the low-latency setup outlined in the official wiki. I set the quantum to 64 for example. After nh os switch, I did pw-top to check my quant level. In the QUANT column, pw-top show 2048 instead of 64.

For instance, when I ran pw-metadata -n settings 0 clock.force-quantum 64, it successfully changed to 64 in pw-top. I began to wonder if I misunderstood something in the wiki, so I decided to try your low-latency setup, but encountered the same issue in the end. I inspect your low-latency setup closely, and noticed this:

 wireplumber = {
          enable = true;
          configPackages = let
            # generate "matches" section of the rules
            matches = 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 = toLua {} {
              "audio.format" = "S32LE";
              "audio.rate" = rate * 2;
              "api.alsa.period-size" = 2;
            };

After a bit of research, I found that the configuration file format changed in 0.5 version Wireplumber. Lua no longer supported by it.

Maybe you can provide assistance about this? Is pw-top show correct quant on your side? Do I misunderstand something?

Your flake looks amazing btw, much more useful than nix wiki, so that's why I decide to ask here about this. Thank you so much for this amazing flake.

NotAShelf commented 1 month ago

I'd generally recommend avoiding NixOS wiki(s). Both the official and the unofficial ones lack any sort of quality assurance, and the information on there is generally out of date.

After a bit of research, I found that the configuration file format changed in 0.5 version Wireplumber. Lua no longer supported by it.

That is correct, and I seem to have missed WP 0.5 merge entirely - which means my configuration is out of date. I'll take a look at that later, but you probably want to read the migration docs and move the lua config to their new conf format.

NotAShelf commented 1 month ago

Migrated to the new API ın https://github.com/NotAShelf/nyx/commit/0197527c06215d88e40f80e85555764b101ad901

VeilSilence commented 1 month ago

/> Migrated to the new API ın 0197527

Sorry for reopen, but is your new low latency setup working for you? If it is, i'm gonna looking for answers elsewhere, just to make sure...

I copy-pasted your updated low-latency module again and edit just a bit ( changed quant to 64, clock to 44100) for the test. I verified everything what I could possibly think of which include: 1: Verified that device.name, node.name is right.

for example

device.name = "alsa_card.usb-SteelSeries_Arctis_Pro_Wireless-00" device.name = "alsa_card.pci-0000_0b_00.1" device.name = "alsa_card.usb-Kingston_HyperX_Quadcast_4110-00" node.name = "alsa_output.usb-SteelSeries_Arctis_Pro_Wireless-00.stereo-game" node.name = "alsa_input.usb-SteelSeries_Arctis_Pro_Wireless-00.mono-chat" node.name = "alsa_input.usb-Kingston_HyperX_Quadcast_4110-00.analog-stereo" node.name = "alsa_output.pci-0000_0d_00.4.analog-stereo"

With that in mind, I assume that rules in your low-latency module should be correct for my case also. 2: after nh os switch, pipewire directory symlink created in etc. 92-low-latency.conf and other conf exist and not empty. 3:Verified that pipewire and wireplumber start without erros about conf.

systemctl --user status pipewire.service

```shell systemctl --user status pipewire.service ● pipewire.service - PipeWire Multimedia Service Loaded: loaded (/etc/systemd/user/pipewire.service; enabled; preset: enabled) Drop-In: /nix/store/5s2xsb45dsfcnx30q09gwmzpdn4xn6ia-user-units/pipewire.service.d └─overrides.conf Active: active (running) since Wed 2024-05-08 15:13:20 +03; 4min 46s ago TriggeredBy: ● pipewire.socket Main PID: 2310 (pipewire) Tasks: 2 (limit: 76965) Memory: 26.7M (peak: 27.1M) CPU: 249ms CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/pipewire.service └─2310 /nix/store/wjxawc5kg90ijr011i8r1br5wpxx10ky-pipewire-1.0.5/bin/pipewire May 08 15:13:20 Nix systemd[2275]: Started PipeWire Multimedia Service. May 08 15:13:20 Nix pipewire[2310]: mod.jackdbus-detect: Failed to receive jackdbus reply: org.freedesktop.DBus.Error.ServiceUnknown: The name is not activatable ```

systemctl --user status wireplumber

```shell systemctl --user status wireplumber.service plumber ● wireplumber.service - Multimedia Service Session Manager Loaded: loaded (/etc/systemd/user/wireplumber.service; enabled; preset: enabled) Drop-In: /nix/store/5s2xsb45dsfcnx30q09gwmzpdn4xn6ia-user-units/wireplumber.service.d └─overrides.conf Active: active (running) since Wed 2024-05-08 15:13:20 +03; 5min ago Main PID: 2313 (wireplumber) Tasks: 8 (limit: 76965) Memory: 9.3M (peak: 10.0M) CPU: 1.182s CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/wireplumber.service └─2313 /nix/store/mfz79x57mga5q0ykysv41wr6fvi3s0dg-wireplumber-0.5.2/bin/wireplumber May 08 15:13:20 Nix systemd[2275]: Started Multimedia Service Session Manager. May 08 15:13:21 Nix wireplumber[2313]: The decibel volume range for element 'Speaker' (-4000 dB - -900 dB) has negative maximum. Disabling the decibel range. May 08 15:13:21 Nix wireplumber[2313]: The decibel volume range for element 'Speaker' (-4000 dB - -900 dB) has negative maximum. Disabling the decibel range. May 08 15:13:21 Nix wireplumber[2313]: The decibel volume range for element 'Speaker' (-4000 dB - -900 dB) has negative maximum. Disabling the decibel range. May 08 15:13:21 Nix wireplumber[2313]: The decibel volume range for element 'Speaker' (-4000 dB - -900 dB) has negative maximum. Disabling the decibel range. May 08 15:13:22 Nix wireplumber[2313]: failed: failed to activate item: Object activation aborted: proxy destroyed May 08 15:13:22 Nix wireplumber[2313]: [0:00:20.445084009] [2313] INFO IPAManager ipa_manager.cpp:143 libcamera is not installed. Adding '/nix/store/src/ipa' to the IPA search path May 08 15:13:22 Nix wireplumber[2313]: [0:00:20.445214469] [2313] INFO Camera camera_manager.cpp:284 libcamera v0.2.0 ```

This is what I got after switch. Small part of pw-mon output:

Details

```shell type: PipeWire:Interface:Core cookie: 4074249876 user-name: "veil" host-name: "Nix" version: "1.0.5" name: "pipewire-0" * properties: * config.name = "pipewire.conf" * link.max-buffers = "16" * core.daemon = "true" * core.name = "pipewire-0" * module.jackdbus-detect = "true" * module.x11.bell = "true" * module.access = "true" * cpu.max-align = "32" * default.clock.rate = "48000" * default.clock.quantum = "1024" * default.clock.min-quantum = "32" * default.clock.max-quantum = "2048" * default.clock.quantum-limit = "8192" * default.clock.quantum-floor = "4" * default.video.width = "640" * default.video.height = "480" * default.video.rate.num = "25" * default.video.rate.denom = "1" * log.level = "2" * clock.power-of-two-quantum = "true" * mem.warn-mlock = "false" * mem.allow-mlock = "true" * settings.check-quantum = "false" * settings.check-rate = "false" * object.id = "0" * object.serial = "0" ```

pm-mon output have nothing about 92-low-latency and other settings. It's basically equal to default settings in:

cat "$(nix eval pipewire.outPath | sed 's/"//g')/share/pipewire/pipewire.conf"

pw-top also confirms that clock and quant settings not applied. Is services.pipewire.extraConfig.pipewire broked, or I'm missing something crucial here? NixOS 24.05.

NotAShelf commented 1 month ago

I have updated the configuration again, will push the changes shortly.

NotAShelf commented 1 month ago

See if https://github.com/NotAShelf/nyx/commit/3ff41102374958a077bb63d3ec524fa8171538de helps. I haven't paid much attention, but according to pw-top and pw-metadata -n settings 0 the values seem to be inline with my configuration.

NotAShelf commented 1 month ago

I stand corrected. the values are not inline, and seem to follow the defaults as you have mentioned.

NotAShelf commented 1 month ago

After an hour, I've found the issue. Latest commit should work as intended, cheers.

pw-metadata -n settings
Found "settings" metadata 35
update: id:0 key:'log.level' value:'2' type:''
update: id:0 key:'clock.rate' value:'48000' type:''
update: id:0 key:'clock.allowed-rates' value:'[ 48000 ]' type:''
update: id:0 key:'clock.quantum' value:'64' type:''
update: id:0 key:'clock.min-quantum' value:'64' type:''
update: id:0 key:'clock.max-quantum' value:'64' type:''
update: id:0 key:'clock.force-quantum' value:'0' type:''
update: id:0 key:'clock.force-rate' value:'0' type:''
VeilSilence commented 1 month ago

Well, it take too long for me, but i found the way:

Example

```nix { config, pkgs, lib, ... }: let inherit (lib) isx86Linux; inherit (lib.modules) mkIf; inherit (lib.lists) optionals; cfg = config.modules.system.sound; dev = config.modules.device; in { config = mkIf (cfg.enable && dev.hasSound) { # If the device advertises sound enabled, and pipewire is disabled # for whatever reason, we may fall back to PulseAudio to ensure # that we still have audio. Although we should always use # PipeWire where available. hardware.pulseaudio.enable = !config.services.pipewire.enable; # Able to change scheduling policies, e.g. to SCHED_RR. # Sound servers use RealtimeKit (rtkit) to acquire # realtime priority. security.rtkit.enable = config.services.pipewire.enable; # Enable the threadirqs kernel parameter to reduce audio latency # See boot.kernelParams = ["threadirqs"]; # Enable pipewire and configure it for low latency. # PIPEWIRE_LATENCY=256/48000 jack_simple_client to set per application if needed. services.pipewire.configPackages = [ ( pkgs.writeTextDir "share/pipewire/pipewire.conf.d/92-custom-properties.conf" '' context.properties = { core.daemon = true # listening for socket connections #core.name = pipewire-low-latency # core name and socket name default.clock.rate = 48000 default.clock.allowed-rates = [ 48000 96000 ] default.clock.quantum = 64 default.clock.min-quantum = 64 default.clock.max-quantum = 64 default.clock.quantum-limit = 64 } '' ) ]; }; } ``` Oh, nvm just saw that you figured.

VeilSilence commented 1 month ago

Small note. I saw that steam also brings his pipewire.conf in .steam/steam/steamapps/common/SteamLinuxRuntime_sniper/sniper_platform_0.20240415.84603/files/share/pipewire/ for example Something tells me that steam might ignore system settings for pipewire. I didn't test it. Either way, thank you for assisting.

NotAShelf commented 1 month ago

pkgs.writeTextDir is certainly an option. I've elected to avoid it, because string interpolation becomes a pain with it. Using extraConfig, albeit finicky, works as intended.