Audio: Difference between revisions

imported>Mic92
m Mic92 moved page Audio HOWTO to Audio
imported>Mic92
No edit summary
Line 16: Line 16:


Sometimes the pc-speaker is the default audio card for ALSA. You can make your real sound card default instead.  For example, if your sound card is "hda-intel" then add
Sometimes the pc-speaker is the default audio card for ALSA. You can make your real sound card default instead.  For example, if your sound card is "hda-intel" then add
<pre>
<syntaxHighlight lang="nix">
  boot.extraModprobeConfig = ''
boot.extraModprobeConfig = ''
    options snd slots=snd-hda-intel
  options snd slots=snd-hda-intel
  '';
'';
</pre>
</syntaxHighlight>
to your <code>/etc/nixos/configuration.nix</code>.
to your <code>/etc/nixos/configuration.nix</code>.


Sometimes, we may want to disable one of intel cards. Here is how to disable first card, but enable the second one.
Sometimes, we may want to disable one of intel cards. Here is how to disable first card, but enable the second one.
<pre>
<syntaxHighlight lang="nix">
  boot.extraModprobeConfig = ''
boot.extraModprobeConfig = ''
    options snd_hda_intel enable=0,1
  options snd_hda_intel enable=0,1
  '';
'';
</pre>
</syntaxHighlight>


Alternatively you can ...
Alternatively you can ...
Line 36: Line 36:
edit <code>/etc/nixos/configuration.nix</code> and add "snd_pcsp" to <code>boot.blacklistedKernelModules</code> option:
edit <code>/etc/nixos/configuration.nix</code> and add "snd_pcsp" to <code>boot.blacklistedKernelModules</code> option:


  boot.blacklistedKernelModules = [ "snd_pcsp" ];
<syntaxHighlight lang="nix">
boot.blacklistedKernelModules = [ "snd_pcsp" ];
</syntaxHighlight>


Now reboot and retry from the beginning (i.e. check that your real card is shown by alsamixer without using the 'S' key).
Now reboot and retry from the beginning (i.e. check that your real card is shown by alsamixer without using the 'S' key).
Line 72: Line 74:


Once you have found a setting that works, you can add it to your configuration file:
Once you have found a setting that works, you can add it to your configuration file:
<pre>
<syntaxHighlight lang="nix">
  boot.extraModprobeConfig = ''
boot.extraModprobeConfig = ''
    options snd-hda-intel model=YOUR_MODEL  
  options snd-hda-intel model=YOUR_MODEL  
  '';
'';
</pre>
</syntaxHighlight>


Much of this is taken from https://help.ubuntu.com/community/HdaIntelSoundHowto which also has additional tips.
Much of this is taken from https://help.ubuntu.com/community/HdaIntelSoundHowto which also has additional tips.
Line 83: Line 85:


In your config file:
In your config file:
<pre>hardware.pulseaudio.enable = true</pre>
<syntaxHighlight lang="nix">hardware.pulseaudio.enable = true</syntaxHighlight>


You can check if everything works by using pavucontrol to see the audio streams and to make sure that PulseAudio detects your audio hardware.
You can check if everything works by using pavucontrol to see the audio streams and to make sure that PulseAudio detects your audio hardware.
Line 90: Line 92:


You may need to add your users to the audio group:
You may need to add your users to the audio group:
<pre>
<syntaxHighlight lang="bash">
$usermod -a -G audio myusername
usermod -a -G audio myusername
</pre>
</syntaxHighlight>
If a user is not a member the audio group only a dummy device will appear in pavucontrol.  
If a user is not a member the audio group only a dummy device will appear in pavucontrol.  


The following command should only show that pulseaudio (and nothing else) is using the sound devices, if you see something like "plugin-container" in the COMMAND column then something is definitely not right, perhaps you have a local ~/.asoundrc which overrides the global alsa settings?.
The following command should only show that pulseaudio (and nothing else) is using the sound devices, if you see something like "plugin-container" in the COMMAND column then something is definitely not right, perhaps you have a local ~/.asoundrc which overrides the global alsa settings?.
<pre>
<syntaxHighlight lang="bash">
  $ lsof /dev/snd/*
$ lsof /dev/snd/*
  COMMAND    PID    USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
COMMAND    PID    USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
  pulseaudi 14080 goibhniu  30u  CHR  116,7      0t0 5169 /dev/snd/controlC0
pulseaudi 14080 goibhniu  30u  CHR  116,7      0t0 5169 /dev/snd/controlC0
  pulseaudi 14080 goibhniu  37u  CHR  116,7      0t0 5169 /dev/snd/controlC0
pulseaudi 14080 goibhniu  37u  CHR  116,7      0t0 5169 /dev/snd/controlC0
</pre>
</syntaxHighlight>


=== Using JACK with PulseAudio ===
=== Using JACK with PulseAudio ===
Line 151: Line 153:
https://github.com/musnix/musnix
https://github.com/musnix/musnix


<pre>
<syntaxHighlight lang="nix">
  boot = {
boot = {
    kernelModules = [ "snd-seq" "snd-rawmidi" ];
  kernelModules = [ "snd-seq" "snd-rawmidi" ];
    kernel.sysctl = { "vm.swappiness" = 10; "fs.inotify.max_user_watches" = 524288; };
  kernel.sysctl = { "vm.swappiness" = 10; "fs.inotify.max_user_watches" = 524288; };
    kernelParams = [ "threadirq" ];
  kernelParams = [ "threadirq" ];
    kernelPackages = let
  kernelPackages = let  
     rtKernel = pkgs.linuxPackagesFor (pkgs.linux.override {
     rtKernel = pkgs.linuxPackagesFor (pkgs.linux.override {
       extraConfig = ''
       extraConfig = ''
Line 169: Line 171:
       '';
       '';
     }) pkgs.linuxPackages;
     }) pkgs.linuxPackages;
    in rtKernel;
  in rtKernel;


    postBootCommands = ''
  postBootCommands = ''
      echo 2048 > /sys/class/rtc/rtc0/max_user_freq
    echo 2048 > /sys/class/rtc/rtc0/max_user_freq
      echo 2048 > /proc/sys/dev/hpet/max-user-freq
    echo 2048 > /proc/sys/dev/hpet/max-user-freq
      setpci -v -d *:* latency_timer=b0
    setpci -v -d *:* latency_timer=b0
      setpci -v -s $00:1b.0 latency_timer=ff
    setpci -v -s $00:1b.0 latency_timer=ff
    '';
  '';
    /*The SOUND_CARD_PCI_ID can be obtained like so:*/
  # The SOUND_CARD_PCI_ID can be obtained like so:
    /*$ lspci ¦ grep -i audio*/
  # $ lspci ¦ grep -i audio
  };
};


  powerManagement.cpuFreqGovernor = "performance";
powerManagement.cpuFreqGovernor = "performance";


  fileSystems =
fileSystems."/" = { options = "noatime errors=remount-ro"; };
  {
    "/" = { options = "noatime errors=remount-ro"; };
  };


  security.pam.loginLimits =
security.pam.loginLimits = [
   [
   { domain = "@audio"; item = "memlock"; type = "-"; value = "unlimited"; }
    { domain = "@audio"; item = "memlock"; type = "-"; value = "unlimited"; }
  { domain = "@audio"; item = "rtprio"; type = "-"; value = "99"; }
    { domain = "@audio"; item = "rtprio"; type = "-"; value = "99"; }
  { domain = "@audio"; item = "nofile"; type = "soft"; value = "99999"; }
    { domain = "@audio"; item = "nofile"; type = "soft"; value = "99999"; }
  { domain = "@audio"; item = "nofile"; type = "hard"; value = "99999"; }
    { domain = "@audio"; item = "nofile"; type = "hard"; value = "99999"; }
];
  ];


  services = {
services = {
    udev = {
  udev = {
      packages = [ pkgs.ffado ]; # If you have a FireWire audio interface
    packages = [ pkgs.ffado ]; # If you have a FireWire audio interface
      extraRules = ''
    extraRules = ''
        KERNEL=="rtc0", GROUP="audio"
      KERNEL=="rtc0", GROUP="audio"
        KERNEL=="hpet", GROUP="audio"
      KERNEL=="hpet", GROUP="audio"
      '';
    '';
    };
    cron.enable =false;
   };
   };
  cron.enable =false;
};


  shellInit = ''
shellInit = ''
    export VST_PATH=/nix/var/nix/profiles/default/lib/vst:/var/run/current-system/sw/lib/vst:~/.vst
  export VST_PATH=/nix/var/nix/profiles/default/lib/vst:/var/run/current-system/sw/lib/vst:~/.vst
    export LXVST_PATH=/nix/var/nix/profiles/default/lib/lxvst:/var/run/current-system/sw/lib/lxvst:~/.lxvst
  export LXVST_PATH=/nix/var/nix/profiles/default/lib/lxvst:/var/run/current-system/sw/lib/lxvst:~/.lxvst
    export LADSPA_PATH=/nix/var/nix/profiles/default/lib/ladspa:/var/run/current-system/sw/lib/ladspa:~/.ladspa
  export LADSPA_PATH=/nix/var/nix/profiles/default/lib/ladspa:/var/run/current-system/sw/lib/ladspa:~/.ladspa
    export LV2_PATH=/nix/var/nix/profiles/default/lib/lv2:/var/run/current-system/sw/lib/lv2:~/.lv2
  export LV2_PATH=/nix/var/nix/profiles/default/lib/lv2:/var/run/current-system/sw/lib/lv2:~/.lv2
    export DSSI_PATH=/nix/var/nix/profiles/default/lib/dssi:/var/run/current-system/sw/lib/dssi:~/.dssi
  export DSSI_PATH=/nix/var/nix/profiles/default/lib/dssi:/var/run/current-system/sw/lib/dssi:~/.dssi
  '';
'';


  users = {
users = {
    extraUsers.yourname= {
  extraUsers.yourname= {
      extraGroups = [ "wheel" "audio" ];
  extraGroups = [ "wheel" "audio" ];
    };
   };
   };
 
};
</pre>
</syntaxHighlight>