From ef5d67624a657954983e0d5b0416b7509444c973 Mon Sep 17 00:00:00 2001 From: encode42 Date: Tue, 9 Jun 2026 17:01:33 -0400 Subject: [PATCH] Update and enhance noise suppression config with gate --- hardware/audio/noise-cancellation.nix | 42 ----------- hardware/audio/noise-suppression.nix | 100 ++++++++++++++++++++++++++ hosts/encryption/default.nix | 12 ++++ 3 files changed, 112 insertions(+), 42 deletions(-) delete mode 100644 hardware/audio/noise-cancellation.nix create mode 100644 hardware/audio/noise-suppression.nix diff --git a/hardware/audio/noise-cancellation.nix b/hardware/audio/noise-cancellation.nix deleted file mode 100644 index 87f493a..0000000 --- a/hardware/audio/noise-cancellation.nix +++ /dev/null @@ -1,42 +0,0 @@ -{ pkgs, ... }: - -{ - imports = [ - ./pipewire.nix - ]; - - services.pipewire.extraConfig.pipewire."99-deepfilter-mono-source" = { - "context.modules" = [ - { - name = "libpipewire-module-filter-chain"; - - args = { - "node.description" = "DeepFilter Noise Canceling Source"; - "media.name" = "DeepFilter Noise Canceling Source"; - - "filter.graph" = { - nodes = [ - { - type = "ladspa"; - name = "DeepFilter Mono"; - label = "deep_filter_mono"; - - plugin = "${pkgs.deepfilternet}/lib/ladspa/libdeep_filter_ladspa.so"; - - control = { - "Attenuation Limit (dB)" = 100; - }; - } - ]; - }; - - "audio.rate" = 48000; - "audio.position" = "[MONO]"; - - "capture.props"."node.passive" = true; - "playback.props"."media.class" = "Audio/Source"; - }; - } - ]; - }; -} diff --git a/hardware/audio/noise-suppression.nix b/hardware/audio/noise-suppression.nix new file mode 100644 index 0000000..efb2459 --- /dev/null +++ b/hardware/audio/noise-suppression.nix @@ -0,0 +1,100 @@ +# { device = { object; channel?; }; threshold; } +{ + device, + threshold, +}: + +{ + pkgs, + lib, + ... +}: + +{ + imports = [ + ./pipewire.nix + ]; + + services.pipewire = { + extraLadspaPackages = with pkgs; [ + deepfilternet + ladspaPlugins + ]; + + # TODO: Ability to pass multiple devices + # Currently, this only supports noise suppression on one device. + extraConfig.pipewire."99-noise-suppression-mono-source" = { + "context.modules" = [ + { + name = "libpipewire-module-filter-chain"; + + flags = [ "nofail" ]; + + args = { + "node.description" = "Noise Suppression Source"; + "media.name" = "Noise Suppression Source"; + + "filter.graph" = { + inputs = [ "DeepFilter:0" ]; + + nodes = [ + { + name = "DeepFilter"; + + type = "ladspa"; + plugin = "libdeep_filter_ladspa"; + label = "deep_filter_mono"; + + control = { + "Attenuation Limit (dB)" = 72; + }; + } + { + name = "Noise Gate"; + + type = "ladspa"; + plugin = "gate_1410"; + label = "gate"; + + control = { + "Threshold (dB)" = threshold; + + "Attack (ms)" = 3.0; + "Hold (ms)" = 500.0; + "Decay (ms)" = 333.0; + }; + } + ]; + + links = [ + { + output = "DeepFilter:0"; + input = "Noise Gate:0"; + } + ]; + + outputs = [ "Noise Gate:0" ]; + }; + + "audio.rate" = 48000; + "audio.channels" = 1; + "audio.position" = "[MONO]"; + + "capture.props" = { + "node.name" = "capture.noise_suppression_source"; + "node.passive" = true; + + "target.object" = device.object; + "audio.position" = lib.optional (device ? channel) [ device.channel ]; + }; + + "playback.props" = { + "node.name" = "noise_suppression_source"; + "media.class" = "Audio/Source"; + }; + }; + } + ]; + }; + }; +} diff --git a/hosts/encryption/default.nix b/hosts/encryption/default.nix index 383c081..de3468c 100644 --- a/hosts/encryption/default.nix +++ b/hosts/encryption/default.nix @@ -5,6 +5,16 @@ ... }: +let + noiseSuppressionModule = import (flakeRoot + /hardware/audio/noise-suppression.nix) { + device = { + object = "alsa_input.usb-Audient_EVO4-00.pro-input-0"; + channel = "AUX0"; + }; + + threshold = -40; + }; +in { imports = [ nixos-hardware.nixosModules.msi-b350-tomahawk @@ -22,6 +32,8 @@ (flakeRoot + /config/desktop/environments/gnome.nix) (flakeRoot + /config/desktop/system/gamemode.nix) + noiseSuppressionModule + ./users ]; -- 2.51.2