Problems Adjusting Pipewire Sample Rate NixOS

I have a NixOS configuration that employs pipewire, I am trying to get chrome to play higher quality audio in the 192khz range, overcoming the systems default 48khz.

services = {
    pipewire = {
      enable = true;
      alsa.enable = true;
      alsa.support32Bit = true;
      pulse.enable = true;
      jack.enable = true;
      extraConfig.pipewire = {
        context.properties = {
          default.clock.rate = 192000;
          #defautlt.allowed-rates = [ 192000 48000 44100 ];
          defautlt.allowed-rates = [ 192000 ];
          default.clock.quantum = 32;
          default.clock.min-quantum = 32;
          default.clock.max-quantum = 32;
        };
      };
    };
};

This rebuilds fine but when I run pw-top,
Pw-top says chrome is running @ 48000. Additionally when I check the pipewire settings with pw-metadata it returns

Found "settings" metadata 32
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:'1024' type:''
update: id:0 key:'clock.min-quantum' value:'32' type:''
update: id:0 key:'clock.max-quantum' value:'2048' type:''
update: id:0 key:'clock.force-quantum' value:'0' type:''
update: id:0 key:'clock.force-rate' value:'0' type:''

It seems as if the settings aren’t being modified. I also checked /etc/pipewire with the tree command and it showed that there were 6 directories but no files ( . pipewire-pulse.conf pipewire.conf jack.conf client.conf client-rt.conf ) . These are obviously symlinks to the /nix/store. When I checked actual store path, I found that pipewire.conf.d has a one file called context.conf. With the proper setup from my nixos configuration file, but it isn’t symlinked anywhere.

{
  "properties": {
    "default": {
      "clock": {
        "max-quantum": 32,
        "min-quantum": 32,
        "quantum": 32,
        "rate": 192000
      }
    },
    "defautlt": {
      "allowed-rates": [
        192000
      ]
    }
  }
}

Is there something additional I need to do for this file to be put into /etc/pipewire and have the actual pipewire daemon run it?

I thought the pipewire module changed last year and basically gave up on structured settings. I just do this now (with NixOS 23.11):

  environment.etc."pipewire/pipewire.conf.d/99-rates.conf".text = ''
    context.properties = {
      default.clock.rate = 44100
      default.clock.allowed-rates = [ 44100 48000 88200 96000 ]
    }
  '';

I’m on 24.05, but I’ll try this way. Thanks!
Do I have to do anything special to active this profile once its installed or should pw-top and pw-metadata show these changes after a rebuild?

Update:
In 24.05 environment.etc.pipewire is no longer supported.

You probably just have to restart pipewire? Not sure if activate will pick up on that.

Hmm, I haven’t looked at what’s coming in 24.05 yet but I’m surprised that’s not supported. Is pipewire configured to not look in /etc/pipewire anymore?

What was your fix for getting this to work on 24.05?

1 Like

I fixed my conversion problem like so:

  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # enale the pipewire config to use noise supression
    extraConfig.pipewire."99-input-denoising" = { source = json.generate "99-input-denoising.conf" rnnoise_config; };
  };

So I just converted enviroment.etc."pipewire/pipewire.conf.d/<name>" = ... to services.pipewire.extraConfig.pipewire."<name>" = ....

The last example in the docs helped a lot.

When you check the sample rate with pw-top and pw-metadata does it show the proper sample rate? For me, nixos rebuilds would complete but the change in sample rate wouldn’t be reflected.

Dots in pipewire do not mean nested attr set they are just part of the attribute name and so need to be escaped to not be interpreted by nix, also extraConfig.pipewire is an attrset of file names containing pipewire settings.

You also need to restart pipewire to load the config.

services = {
    pipewire = {
      enable = true;
      alsa.enable = true;
      alsa.support32Bit = true;
      pulse.enable = true;
      jack.enable = true;
      extraConfig.pipewire.adjust-sample-rate = {
        "context.properties" = {
          "default.clock.rate" = 192000;
          #"defautlt.allowed-rates" = [ 192000 48000 44100 ];
          "defautlt.allowed-rates" = [ 192000 ];
          "default.clock.quantum" = 32;
          "default.clock.min-quantum" = 32;
          "default.clock.max-quantum" = 32;
        };
      };
   };
};
1 Like

My solution I posted didn’t work. It just didn’t throw an error. I mistook that with it working. I contacted the nixos matrix channel and someone there helped me. Disclaimer: I am doing sth else as the OP, therefore my answer is not especially for his/her solution.

This is my config:

  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # enale the pipewire config to use noise supression
    extraConfig.pipewire."99-input-denoising" = rnnoise_config;
  };

I had to just use extraConfig.pipewire."99-input-denoising" = rnnoise_config and not extraConfig.pipewire."99-input-denoising" = { source = json.generate "99-input-denoising.conf" pw_rnnoise_config; };

You are awesome. I have been looking for this for months. Thanks!

Works on 24.05.

Edit:
I had to comment out the quantum rates due to so distortion and cut outs of my audio.

services = {
    pipewire = {
      enable = true;
      alsa.enable = true;
      alsa.support32Bit = true;
      pulse.enable = true;
      jack.enable = true;
      extraConfig.pipewire.adjust-sample-rate = {
        "context.properties" = {
          "default.clock.rate" = 192000;
          #"defautlt.allowed-rates" = [ 192000 48000 44100 ];
          "defautlt.allowed-rates" = [ 192000 ];
          #"default.clock.quantum" = 32;
          #"default.clock.min-quantum" = 32;
          #"default.clock.max-quantum" = 32;
        };
      };
   };
};