Electric guitar interface setup: Difference between revisions

initial creation: Guide for low-latency electric guitar setup
 
update: fixed PipeWire/Pulse config, switched to sessionVariables for GUI plugin paths, added memlock limits, expanded software guide with categorized explanations
Line 1: Line 1:
= Electric guitar interface setup =
= Electric guitar interface setup =


This guide covers setting up an electric guitar with NixOS to achieve professional, low-latency audio processing. It targets live playing with round-trip latency under 6 ms using the modern PipeWire/JACK stack.
This guide covers setting up an electric guitar with NixOS to achieve professional, low-latency audio processing. It targets live playing with round-trip latency (RTL) under 6 ms using the modern PipeWire/JACK stack.
 
'''⚠️ Safety Warning''': Always start with monitoring volume at minimum when testing new signal chains. A sudden, loud feedback loop can be generated during loopback testing. Increase volume gradually only after the plugin is open and stable.


== Introduction ==
== Introduction ==
Line 9: Line 11:
# '''Analog-to-Digital conversion''' via an external audio interface.
# '''Analog-to-Digital conversion''' via an external audio interface.
# '''Real-time processing''' on NixOS using a low-latency kernel and specialized software.
# '''Real-time processing''' on NixOS using a low-latency kernel and specialized software.
'''Note''': Software-reported latency values are often inaccurate. Physical measurement via loopback test is mandatory for verification.


== Installation ==
== Installation ==
Line 14: Line 18:
=== System Configuration ===
=== System Configuration ===


Add the following to your `/etc/nixos/configuration.nix`. This configuration is optimized for high-performance CPUs like the '''AMD Ryzen 7 9700X'''.
Add the following to your <code>/etc/nixos/configuration.nix</code>. This configuration is optimized for high-performance CPUs like the AMD Ryzen 7 9700X (Zen 5 architecture).


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ pkgs, ... }:
{ pkgs, config, ... }:


{
{
Line 24: Line 28:
     enable = true;
     enable = true;
     alsa.enable = true;
     alsa.enable = true;
     alsa.support32Bit = true;
     alsa.support32Bit = true; # Required for yabridge/wine VST bridging
     pulse.enable = true;
     pulse.enable = true;
     jack.enable = true;
     jack.enable = true;
     wireplumber.enable = true;
     wireplumber.enable = true;
      
      
     # Global low-latency defaults
     # Global low-latency defaults for native JACK clients
     extraConfig.pipewire."92-low-latency" = {
     extraConfig.pipewire."92-low-latency" = {
       "context.properties" = {
       "context.properties" = {
         "default.clock.rate" = 48000;
         "default.clock.rate" = 48000; # Fixed rate avoids resampling latency
         "default.clock.quantum" = 128;      # ~5ms latency
         "default.clock.quantum" = 128;      # ~5ms latency at 48kHz
         "default.clock.min-quantum" = 64;  # ~2.5ms latency
         "default.clock.min-quantum" = 64;  # ~2.5ms latency at 48kHz
         "default.clock.max-quantum" = 512;
         "default.clock.max-quantum" = 512;
      };
    };
    # Crucial: Match low-latency for PulseAudio clients (browsers, Steam/Rocksmith)
    extraConfig.pipewire-pulse."92-low-latency" = {
      "pulse.properties" = {
        "pulse.min.req" = "64/48000";    # Start with 64, not 32, for stability
        "pulse.default.req" = "64/48000";
        "pulse.max.req" = "128/48000";
       };
       };
     };
     };
   };
   };


   # 2. Real-time Scheduling and Privileges
   # 2. Real-time Scheduling
  # RTKit handles real-time privileges via D-Bus/Polkit.
   security.rtkit.enable = true;
   security.rtkit.enable = true;
   users.users.yourname.extraGroups = [ "audio" "realtime" ];
 
  # Critical: Allow unlimited memlock for real-time audio buffers
  security.pam.loginLimits = [
    {
      domain = "@audio";
      item = "memlock";
      type = "-";
      value = "unlimited";
    }
    {
      domain = "@audio";
      item = "rtprio";
      type = "-";
      value = "95";
    }
  ];
 
   users.users.yourname.extraGroups = [ "audio" ]; # Replace 'yourname' with your username


   # 3. Kernel and Performance Tweaks
   # 3. Kernel and Performance Tweaks
   boot.kernelPackages = pkgs.linuxPackages_zen;  
   boot.kernelPackages = pkgs.linuxPackages_zen;  
   boot.kernelParams = [  
   boot.kernelParams = [  
     "preempt=full"  
    "threadirqs"
     "threadirqs"  
     "preempt=full"             # Optional: add if experiencing Xruns
     "usbcore.autosuspend=-1"  
     "amd_pstate=passive"       # Zen 4/5: passive + performance governor = stable freq
     "processor.max_cstate=1"  
     # For Intel or older AMD: remove amd_pstate or use "intel_pstate=active"
     "usbcore.autosuspend=-1"   # Prevent USB audio interface sleep
   ];
   ];


   powerManagement.cpuFreqGovernor = "performance";
   powerManagement.cpuFreqGovernor = "performance";
 
  # GameMode can elevate priorities for real-time audio applications
  programs.gamemode.enable = true;
  # 4. NVIDIA Workaround (If applicable)
  # For RTX 40/50 series: disable GSP firmware to prevent DPC latency spikes
  # hardware.nvidia.powerManagement.enable = false;
  # hardware.nvidia.modesetting.enable = true;
  # boot.extraModprobeConfig = "options nvidia NVreg_EnableGpuFirmware=0";
  # 5. Plugin Search Paths (Crucial for NixOS DAWs)
  # Use sessionVariables for GUI apps launched from DE menu
  environment.sessionVariables = let
    makePluginPath = format = (pkgs.lib.makeSearchPath format [
      "/run/current-system/sw/lib"
      "${config.users.users.yourname.home}/.nix-profile/lib"  # Adjust if using home-manager
    ]) + ":$HOME/.${format}";
  in {
    LV2_PATH = makePluginPath "lv2";
    VST3_PATH = makePluginPath "vst3";
    CLAP_PATH = makePluginPath "clap";  # Modern plugin format, supported by LSP/Chow
  };


   # 4. Essential Packages
   # 6. Essential Packages
   nixpkgs.config.allowUnfree = true;  
   nixpkgs.config.allowUnfree = true; # Required for REAPER, Tonelib, etc.
   environment.systemPackages = with pkgs; [
   environment.systemPackages = with pkgs; [
     qpwgraph
    # --- Utilities & Routing ---
     pavucontrol
     qpwgraph           # Visual patchbay for PipeWire
     pavucontrol         # Profile selection (Pro Audio mode)
    pw-top              # Real-time CPU usage per audio node
    pw-cli              # Modern alternative to pw-metadata
    cpupower            # CPU frequency scaling controls
    alsa-scarlett-gui  # Hardware mixer for Focusrite Scarlett (may require firmware)
 
    # --- DAWs ---
     ardour
     ardour
     reaper
     reaper
     carla
 
    # --- Plugin Hosts ---
     carla               # Modular plugin host / pedalboard, supports Windows VST via yabridge
 
    # --- Standalone Guitar Processors ---
     guitarix
     guitarix
     gxplugins-lv2
     # tonelib-gfx      # NOTE: Currently marked as broken in nixpkgs; install from vendor if needed
     lsp-plugins
 
    # --- Plugins (LV2/CLAP) ---
    neural-amp-modeler-lv2 # NAM: loads .nam files from https://tonehunt.org
     lsp-plugins             # Includes latency meter, compressors, IR loader
     calf
     calf
     dragonfly-reverb
     dragonfly-reverb
     neural-amp-modeler-lv2
     gxplugins-lv2
    proteus
    kapitonov-plugins-pack  # Profile-based amp models (KPP)
     kapitonov-plugins-pack
    chow-centaur            # Klon Centaur emulation
    chow-phaser
    # airwindows-lv2       # NOTE: Large package (~400 plugins); consider selective install
 
     # --- Practice & Learning ---
     tuxguitar
     tuxguitar
     hydrogen
     hydrogen
     cpupower
 
     # --- Windows VST Compatibility ---
    yabridge
    yabridgectl
    wineWowPackages.stable  # Use stable, not staging, for VST compatibility
   ];
   ];
}
}
</syntaxhighlight>
</syntaxhighlight>
'''Note on <code>musnix</code>''': For advanced users, the [https://github.com/musnix/musnix musnix] flake automates many low-level audio optimizations (such as <code>PREEMPT_RT</code> kernel patching, <code>rtirq</code> tuning, and <code>das_watchdog</code>). If you experience persistent Xruns with the standard Zen kernel, replacing manual tweaks with <code>musnix.enable = true;</code> is highly recommended. '''Warning''': musnix may require replacing your kernel and can affect compatibility with Steam/Wine applications.


=== Applying Changes ===
=== Applying Changes ===
Line 82: Line 160:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
sudo nixos-rebuild switch
sudo nixos-rebuild switch
# Apply PipeWire configuration changes (required after rebuild):
systemctl --user restart pipewire pipewire-pulse wireplumber
</syntaxhighlight>
</syntaxhighlight>


== Hardware & Connection ==
== Hardware & Connection ==


=== Audio Interface ===
Standard PC line-ins are unsuitable for guitar. Use a dedicated interface with a '''Hi-Z (Instrument)''' input.


Standard PC line-ins are unsuitable for guitar. Use a dedicated interface with a '''Hi-Z (Instrument)''' input.
=== Verified compatible devices (2026) ===
 
{| class="wikitable"
! Device !! Notes
|-
| '''Focusrite Scarlett Solo (4th Gen)''' || Plug-and-play. Use <code>alsa-scarlett-gui</code> for hardware monitoring. May require firmware update.
|-
| '''MOTU M2 / M4''' || Native ALSA kernel support for direct hardware mixer control via <code>alsamixer</code>. Exceptionally stable USB-C latency.
|-
| '''Universal Audio Volt 276''' || Reliable USB-C class-compliant interface.
|-
| '''Arturia MiniFuse 1''' || Stable performance under PipeWire.
|}
 
=== Hardware Rules ===


'''Verified compatible devices (2026):'''
# Connect the interface '''directly to the motherboard''' (rear panel USB 3.0/3.2). Avoid USB hubs — they add latency and can cause Xruns.
* '''Focusrite Scarlett Solo (4th Gen):''' Plug-and-play, excellent Linux support.
# Use a high-quality, shielded USB cable. Audio dropouts are frequently caused by cheap cables acting as antennas for electrical interference.
* '''Arturia MiniFuse 1:''' Stable performance under PipeWire.
# '''Disable Bluetooth''' during live playing: <code>rfkill block bluetooth</code>. BT audio stack can generate interrupt storms causing Xruns.


=== Verification ===
=== Verification ===


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
lsusb     # Confirm hardware connection
lsusb                   # Confirm hardware connection
aplay -l   # Confirm ALSA sees the interface
arecord -l              # Verify ALSA sees the capture input
aplay -l                 # Verify ALSA sees the playback output
# For detailed interface capabilities:
arecord --dump-hw-params -D hw:<card>,<device>
</syntaxhighlight>
</syntaxhighlight>


Line 106: Line 204:


To achieve minimal latency, you must bypass standard software mixing:
To achieve minimal latency, you must bypass standard software mixing:
# Open <nowiki>pavucontrol</nowiki>.
 
# Go to '''Configuration'''.
# Open <code>pavucontrol</code>.
# Go to '''Configuration''' tab.
# Set your interface profile to '''Pro Audio'''.
# Set your interface profile to '''Pro Audio'''.
'''Note''': If "Pro Audio" profile is missing, ensure <code>pipewire-alsa</code> is installed and restart PipeWire. This profile disables software mixing and enables hardware-exclusive mode, critical for achieving lowest latency.


=== Dynamic Buffer Control ===
=== Dynamic Buffer Control ===


You can change latency without rebuilding the system:
You can change latency without rebuilding the system. Note: these settings affect PipeWire clients only; ALSA-direct applications (like Ardour with ALSA backend) use their own buffer settings.


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
# Force a specific buffer size (quantum)
# Modern syntax (PipeWire 0.3.65+):
pw-metadata -n settings 0 clock.force-quantum 64
pw-cli set-param 0 clock.force-quantum 64/48000


# Verify current status
# Verify current settings:
pw-metadata -n settings 0
pw-cli dump settings | grep -E "quantum|rate"
 
# Alternative: use wpctl (WirePlumber CLI)
wpctl set-default-rate 48000
</syntaxhighlight>
</syntaxhighlight>


== Software Hosts ==
Use <code>pw-top</code> in a separate terminal to monitor which applications are consuming the most DSP processing time. Look for the <code>ERR</code> column — values >0 indicate Xruns.
 
== Software Guide: Choosing Your Rig ==
 
This section explains the available software for guitar processing on NixOS, organized by purpose.
 
=== Digital Audio Workstations (DAWs) ===
 
{| class="wikitable"
! Software !! Purpose !! Notes
|-
| '''Ardour''' || Professional recording, mixing, editing || For absolute minimum RTL, use '''ALSA backend''' (bypasses PipeWire). Warning: ALSA locks device exclusively — no other app can produce sound.
|-
| '''REAPER''' || Commercial DAW, lightweight, scriptable || Uses PipeWire-JACK natively. Excellent Linux support. Unlimited trial.
|}
 
=== Amp Simulators & Neural Modelers ===


{| class="wikitable"
{| class="wikitable"
! Type !! Examples !! Best Use Case
! Software !! Purpose !! Notes
|-
|-
| '''Standalone''' || Guitarix || Quick practice, simple pedalboard
| '''Neural Amp Modeler (NAM)''' (<code>neural-amp-modeler-lv2</code>) || Loads <code>.nam</code> files — AI captures of real tube amps || '''No built-in GUI in LV2 version'''. In Carla/Ardour: look for <code>atom:Path</code> parameter and point to your <code>.nam</code> file. Models: [https://tonehunt.org tonehunt.org]
|-
|-
| '''Modular''' || Carla || Flexible routing, loading Windows VSTs
| '''Kapitonov Plugins Pack (KPP)''' || Profile-based traditional amp modeling || Excellent for classic rock/metal. Lower CPU than neural nets.
|-
|-
| '''DAW''' || Ardour, Reaper || Professional recording, lowest latency via ALSA
| '''Guitarix''' || All-in-one virtual amp + pedals || Standalone or LV2. Good for quick practice.
|}
|}


== Plugin Ecosystem (March 2026 Status) ==
'''⚠️ Critical''': Neural amps (NAM, KPP) only model preamp/poweramp. '''You must load a Cabinet IR''' (via LSP IR Loader or similar) to get a usable guitar tone. Without IR, it sounds like a swarm of bees.


=== Available in Nixpkgs ===
=== Effects Plugins ===


* '''Neural Amp Modeler (NAM):''' <nowiki>neural-amp-modeler-lv2</nowiki>. Current standard for high-fidelity amp captures.
{| class="wikitable"
* '''LSP Plugins:''' Includes <nowiki>LSP Latency Meter</nowiki>.
! Plugin Pack !! Key Features
* '''Proteus:''' Excellent for RNN-based captures.
|-
| '''LSP Plugins''' || Professional EQ, compression, gating. '''Includes LSP Latency Meter''' and '''LSP Impulse Response Loader''' (required for cabinet sims).
|-
| '''Dragonfly Reverb''' || High-quality algorithmic reverb (Hall, Room, Plate).
|-
| '''Chow Plugins''' (<code>chow-centaur</code>, <code>chow-phaser</code>) || High-fidelity emulations of classic pedals using RNN/WDF.
|-
| '''Calf Studio Gear''' || Vintage-style effects with "warm" analog character.
|-
| '''GxPlugins.lv2''' || Guitarix project pedals (distortion, overdrive, fuzz) as standalone LV2.
|}


=== Unavailable / Alternatives ===
=== Modular Hosts ===
 
{| class="wikitable"
! Software !! Purpose
|-
| '''Carla''' || Modular plugin host. Chain plugins visually: Input → Tuner → NAM → IR Loader → Reverb → Output. Hosts Windows VSTs via yabridge.
|-
| '''qpwgraph''' || Visual patchbay for PipeWire/JACK. Manually connect hardware inputs to software hosts (PipeWire does not auto-connect).
|}


* '''Ratatouille / AIDA-X:''' Currently not in nixpkgs. Use '''NAM''' or '''Proteus'''.
=== Windows VST Compatibility ===
* '''MOD Desktop:''' Use '''Carla''' for similar modular functionality.
 
{| class="wikitable"
! Tool !! Purpose
|-
| '''yabridge + yabridgectl''' || Bridge for running Windows VST2/VST3 plugins on Linux via Wine. Essential for commercial plugins (Neural DSP, STL Tones, Amplitube).
|}
 
<syntaxhighlight lang="bash">
# After installing Windows plugins via Wine:
yabridgectl sync  # Required to register plugins with Linux hosts
</syntaxhighlight>
 
'''Note''': Ensure glibc versions match between Wine and system. Check with <code>ldd /path/to/plugin.dll</code>.
 
== Rocksmith 2014 Remastered (Optional) ==
 
Rocksmith 2014 runs on NixOS via Proton and PipeWire.
 
=== Connection Options ===
 
{| class="wikitable"
! Method !! Pros !! Cons
|-
| '''Real Tone Cable''' || Official, plug-and-play || Proprietary, limited to 48kHz
|-
| '''Your Audio Interface + RS_ASIO''' || Use professional interface, any sample rate || Requires modding game files
|}
 
=== Setup Steps ===
 
# '''Install dependencies''':
<syntaxhighlight lang="nix">
# In configuration.nix:
programs.steam.enable = true;
programs.gamemode.enable = true;  # For launch option below
</syntaxhighlight>
 
# '''Steam Launch Options''' (force low latency + real-time priority):
<pre>
PIPEWIRE_LATENCY=128/48000 gamemoderun %command%
</pre>
Start with <code>128/48000</code> (~5ms). If stable, try <code>64/48000</code> (~2.5ms). Values <64 may cause crashes.
 
# '''Sample Rate''': Rocksmith strictly requires '''48000 Hz'''. Do not force 96000 Hz while playing.
 
# '''If using Real Tone Cable and experiencing issues''', try ALSA backend as fallback (warning: exclusive device access):
<syntaxhighlight lang="bash">
# Only use if Pulse backend fails. May silence other apps.
protontricks 221680 sound=alsa
</syntaxhighlight>
 
# '''For interface users (no Real Tone Cable)''': Install [https://github.com/mdias/rs_asio RS_ASIO] mod to enable direct interface support. This bypasses the 48kHz limitation and allows using your professional interface.


== Measuring Latency ==
== Measuring Latency ==


Never trust software reports. Always perform a physical loopback test:
Never trust software reports. Always perform a physical loopback test.
# Connect a cable from your interface '''Output''' back into the '''Input'''.
 
# Open '''LSP Latency Meter'''.
=== Procedure ===
# Measure the '''Round-trip Latency (RTL)'''.
 
'''⚠️ Warning''': Before starting, turn output volume on your audio interface '''all the way down'''. A sudden, loud feedback loop can be generated if the connection is unstable. Increase volume gradually only after the plugin is open.
 
# Connect a cable from your interface '''Output''' back into the '''Input''' (use a TS/TRS patch cable).
# Launch LSP Latency Meter:
<syntaxhighlight lang="bash">
# Option A: Via Carla (recommended for beginners)
carla  # Add plugin "LSP Latency Meter Stereo", connect wires
 
# Option B: Via jalv (terminal)
jalv http://lsp-plug.in/plugins/lv2/latency_meter_stereo
</syntaxhighlight>
# Play a sharp transient (string scratch) and read the '''Round-trip Latency (RTL)''' value.
 
=== Target Values ===


{| class="wikitable"
{| class="wikitable"
! Latency !! Perception
! Latency !! Perception
|-
|-
| < 5 ms || Professional / Imperceptible
| '''< 5 ms''' || Professional / Imperceptible
|-
|-
| 5-10 ms || Acceptable for practice
| '''5–10 ms''' || Acceptable for practice
|-
|-
| > 12 ms || Noticable "lag", difficult to play
| '''> 12 ms''' || Noticeable "lag", difficult to play in time
|}
|}
'''Note''': If measured latency exceeds calculated buffer latency <code>(buffer / sample_rate) * 2 * 1000</code>, check: USB interface hardware buffers, PipeWire extra quantum settings, kernel interrupt latency.


== Troubleshooting ==
== Troubleshooting ==


* '''Xruns (Audio Glitches):''' Ensure <nowiki>powerManagement.cpuFreqGovernor = "performance"</nowiki> is active.
{| class="wikitable"
* '''No Sound:''' Check <nowiki>qpwgraph</nowiki>. PipeWire does not always auto-connect.
! Symptom !! Cause & Solution
* '''NVIDIA Latency:''' Add <nowiki>nvidia.NVreg_EnablePowerManagement=0</nowiki> to <nowiki>boot.kernelParams</nowiki>.
|-
| '''Xruns (audio glitches)''' || • Ensure <code>powerManagement.cpuFreqGovernor = "performance"</code> is active (<code>cpupower frequency-info</code>).<br>• Check <code>pw-top</code> for high-CPU nodes.<br>• Close browsers/heavy apps during playing.<br>• Disable Wi-Fi: <code>sudo modprobe -r iwlwifi</code>.<br>• As last resort: add <code>processor.max_cstate=1</code> to <code>boot.kernelParams</code> (disables CPU sleep — high power draw).
|-
| '''No sound''' || • Check <code>qpwgraph</code> PipeWire does not auto-connect hardware.<br>• Verify Pro Audio profile in <code>pavucontrol</code>.<br>• Run <code>sudo lsof /dev/snd/*</code> to find conflicting processes.
|-
| '''DAW cannot find plugins''' || • Ensure <code>environment.sessionVariables</code> block is applied. Log out/in after rebuild.<br>• Verify paths: <code>echo $LV2_PATH</code>.<br>• Check plugin installation: <code>ls ~/.lv2</code>, <code>ls /run/current-system/sw/lib/lv2</code>.
|-
| '''NVIDIA audio glitches''' || • Disable GPU power management: <code>hardware.nvidia.powerManagement.enable = false;</code><br>• For RTX 40/50 series: add <code>boot.extraModprobeConfig = "options nvidia NVreg_EnableGpuFirmware=0";</code><br>• Prefer X11 over Wayland for lowest latency.
|-
| '''Bluetooth causing Xruns''' || • Disable Bluetooth stack: <code>rfkill block bluetooth</code> during live sessions.
|-
| '''PipeWire config not applying''' || • Restart user services after rebuild: <code>systemctl --user restart pipewire wireplumber</code>.<br>• Check for WirePlumber overrides: <code>wpctl status</code>.
|}
 
== Quick Start Checklist ==
 
Before playing, verify:
 
<syntaxhighlight lang="bash">
# 1. CPU governor is performance
cpupower frequency-info | grep "current policy"  # Should show "performance"
 
# 2. PipeWire buffer is set
pw-cli dump settings | grep quantum  # Should show 64 or 128
 
# 3. No Xruns reported
pw-top | grep -E "ERR|XRUN"  # Should show 0 or empty
 
# 4. Pro Audio profile active
pavucontrol  # Configuration tab → your interface → Pro Audio
 
# 5. Plugin paths are set (for GUI apps)
echo $LV2_PATH  # Should include /run/current-system/sw/lib/lv2
</syntaxhighlight>


== See Also ==
== See Also ==
* [[PipeWire]]
 
* [https://github.com/musnix/musnix musnix] - Deep NixOS audio optimizations.
* [[PipeWire]] — Official NixOS PipeWire documentation
* [https://github.com/musnix/musnix musnix] Deep NixOS audio optimizations module
* [https://linuxmusicians.com/ LinuxMusicians Forum] — Community support
* [https://tonehunt.org ToneHunt] — Free NAM model library
* [https://github.com/mdias/rs_asio RS_ASIO] — Rocksmith interface mod


[[Category:Guides]]
[[Category:Guides]]
[[Category:Hardware]]
[[Category:Hardware]]
[[Category:Sound]]
[[Category:Sound]]