====== Audio setup ====== For audio production and processing, your system needs to be optimized for low latency operation using the [[https://jackaudio.org|Jack Audio Connection Kit (JACK)]] audio server with [[https://alsa-project.org/wiki/Matrix:Main|Advanced Linux Sound Architecture (ALSA) compatible]] audio interface hardware. Today class-compliant USB audio interfaces are supported out of the box as well as IEEE 1394 aka [[wp>FireWire|Firewire]] devices since the introduction of [[https://ieee1394.wiki.kernel.org/index.php/Juju_Migration|Juju]]. Audio applications use JACK for low-latency operation and signal routing. [[https://wiki.linuxaudio.org/wiki/system_configuration|Extensive documentation]] may help to understand some principles and general guidelines when trying to setup a professional audio environment. ===== Real-time Kernel ===== The Linux kernel is compiled with ''[[https://rt.wiki.kernel.org/index.php/CONFIG_PREEMPT_RT_Patch|CONFIG_PREEMPT=y]]'' by default in most distributions and worst case [[wp>Latency_(audio)#Computer_audio|latency]] is normally up to 10 ms. So for starting you might want to [[https://jackaudio.org/faq/realtime_vs_realtime_kernel.html|stay with the stock kernel]], but depending on hardware and requirements you may need a real-time (RT) kernel. Use your package manager to install ''linux-rt'' or similar. In Arch Linux there are no official builds, so you would need to [[wp>Software_build|build]] the RT kernel by yourself, if you don't trust the [[https://wiki.archlinux.org/title/Arch_User_Repository|Arch User Repositories (AUR)]] by Arch Linux developer [[https://wiki.archlinux.org/title/Unofficial_user_repositories#realtime|dvzrv]]. After installation reboot into that kernel and optionally check its configuration on terminal with: gzip -cd /proc/config.gz | grep PREEMPT Some distributions store that file in ''/boot'' directory and if ''CONFIG_IKCONFIG'', but not ''CONFIG_IKCONFIG_PROC'' is present, you can extract it out of the kernel image with [[https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/extract-ikconfig|extract-ikconfig]]. Other [[https://wiki.archlinux.org/title/Professional_audio#Realtime_kernel|real-time configuration]] options to consider when building the kernel by yourself is setting timer frequency to 1000 Hz and disabling [[wp>Advanced_Power_Management|APM]]: * ''CONFIG_HZ_1000=y'' * ''CONFIG_APM=n'' ===== System settings ===== As low-latency is important for an audio setup there are some settings to be tweaked for using full system resources and improving performance for access on hardware. Most of those optimizations are based on the [[https://wiki.archlinux.org/title/Professional_audio#System_configuration|ArchWiki]] as well as recommendations from [[https://linuxmusicians.com|linuxmusicians.com]] and can be checked by a perl script. Get and execute that script like this: git clone https://github.com/raboof/realtimeconfigquickscan cd realtimeconfigquickscan perl ./realTimeConfigQuickScan.pl Then follow instructions for all check results classified //not good//. Some of the commands for optimization need to be run with [[wp>Superuser#Unix_and_Unix-like|sudo or as superuser]]. So be careful when executing them! ==== Disable CPU power-saving ==== Changing CPU frequency can cause [[wp>Buffer_overflow|xruns]] and lead to audible artefacts like dropouts or distortions. So it's better to set your [[https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html#generic-scaling-governors|CPU scaling governor]] to performance mode. You can do this on terminal: echo performance > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor I'm using [[https://www.archlinux.org/packages/community/x86_64/cpupower|cpupower]] along with following [[https://wiki.archlinux.org/title/Sudo#Example_entries|sudo configuration]] to allow it without root password prompt: %wheel ALL= NOPASSWD: /usr/bin/cpupower frequency-set -g performance ==== Lower swappiness and increase fs.inotify ==== High [[wp>Paging#Swappiness|swappiness]] values causes the system to swap running applications to hard disk even if there's still memory resources available. Lower swappiness by adding ''vm.swappiness=10'' to /etc/sysctl.conf file. The maximum number of files your system can monitor with inotify is specified in /etc/sysctl.conf file, too. Increase the //max_user_watches// parameter by appending ''fs.inotify.max_user_watches = 600000'' to it. Both settings are provided by an AUR package called ''[[https://github.com/redtide/archlinux-realtime-generic-setup|realtime-generic-setup]]'' in Arch Linux. Activate new configuration by reloading sysctl with ''sysctl -f''. ==== Grant special device access ==== For access to the high precision event timer and real-time clock is necessary. Normally those are owned by the audio group, so you must be part of that group: gpasswd -a audio ==== Set audio group limits ==== RT priorities and memlock setting needs to be specified in /etc/security/limits.conf file to allow applications to use most of the system resources: @audio - rtprio 90 @audio - memlock unlimited In Arch Linux the package [[https://www.archlinux.org/packages/community/any/realtime-privileges|realtime-privileges]] provides that configuration and you need to be part of the ''realtime'' group instead. > **Note:** Changes concerning group membership are applied on next login. ==== Manual IRQ handling ==== Another crucial task, especially for external audio interfaces using USB, Firewire etc. connection, is [[wp>Interrupt_request_(PC_architecture)|IRQ]] handling. Although this is done automatically, I found that manually prioritizing IRQs reduces latency. The process is to identify IRQs with ''rtapp'' and set priorities with ''rtirq'' as described for [[https://www.audio-linux.com/html/realtime.html|Audio Linux project]]. For Arch Linux the packages [[https://www.archlinux.org/packages/community/any/rtirq|rtirq]] and [[https://aur.archlinux.org/packages/rtapp|rtapp]] are provided for installation with package manager. Append ''threadirqs'' to [[https://wiki.archlinux.org/title/Kernel_parameters|kernel parameters]] in boot configuration and reboot to apply changes. Connect your audio interface and identify current IRQ handling with ''rtstatus'' on terminal. If the output is similar to this: RTPRIO COMMAND 50 irq/16-ehci_hcd 50 irq/30-xhci_hcd ... run ''rtcards'' to examine IRQ and interface of [[wp>Digital-to-analog_converter|DAC]] to specify it for ''RTIRQ_NAME_LIST'' in /etc/rtirq.conf file. I'm using an USB 2.0 audio interface requiring ''ehci_hcd'' (default is ''xhci_hcd'') value, for example. There's no further editing needed as default ''RTIRQ_PRIO_HIGH=90'' is fine. Changes are applied when rtirq service is restarted: systemctl restart rtirq Enable the service with ''systemctl enable rtirq'' to change IRQs automatically at boot. ===== Audio server ===== In the center of audio applications the JACK audio server guarentees low-latency operation, signal routing and connection management. There are [[https://github.com/jackaudio/jackaudio.github.com/wiki/Differences-between-jack1-and-jack2|two versions]] available. To maintain multimedia capabilities (e.g. audio in web browsers) provided by [[https://www.freedesktop.org/wiki/Software/PulseAudio|PulseAudio (PA)]] and use multi-core CPUs efficiently, ''[[https://www.archlinux.org/packages/extra/x86_64/pulseaudio-jack|pulseaudio-jack]]'' module needs to be installed along ''[[https://www.archlinux.org/packages/community/x86_64/jack2|jack2]]'' with SMP and D-Bus support. The hardest part is to evaluate best JACK parameters depending on your hardware. To ease this procedure and control JACK graphically ''[[https://www.archlinux.org/packages/community/x86_64/qjackctl|qjackctl]]'' can be used. Besides [[https://wiki.archlinux.org/title/JACK_Audio_Connection_Kit#A_GUI-based_example_setup|general settings]] for starting ''jackdbus'' instead of ''jackd'' service, main parameters regarding to latency (frames, periods, sample rate) are described by this function: //L = n * p / f// //L//: Latency in miliseconds (ms), //n//: Frames or buffer (multiples of 2, starting at 16), //p//: Periods, //f//: Sample rate in Hertz (Hz). Capabilities of the audio interface define working combinations. You have to trial and error to find a setup. Sure, it's a trade-off between xrun prevention and latency, but recent audio interfaces can be used at high sample rates (up to 192 kHz) to deal with that requirement. Start your evaluation by choosing a period of 2 or 3 (for external audio interfaces) and try frames values ranging from 16 to 256. Some combinations have been documented in the [[https://wiki.linuxaudio.org/wiki/list_of_jack_frame_period_settings_ideal_for_usb_interface|Linux Audio Wiki]]. If you do [[wp>Audio_mixing_(recorded_music)|mixing]] only and don't plan to use live processing and recording with software monitoring in your [[https://en.wikipedia.org/wiki/Digital_audio_workstation|Digital Audio Workstation (DAW)]], the frames value can be much higher as there might be more processing power needed over real-time performance capabilties. For instance, I'm using //n=3//, //p=128// and //f=48000// resulting in a latency of //L=8 ms// for recording with a USB audio interface and software monitoring. Mixing only setup uses a higher frames value of //p=1024// with my built-in audio interface. ===== Applications ===== There are many applications for different tasks and workflows. In the audio context it's important that they are //JACKyfied//, which means supporting JACK for audio in-/output. Be inspired by the following list of applications I'm using: ^ Application name ^ Description and highlight features ^ | [[https://www.archlinux.org/packages/community/x86_64/ardour|ardour]] | [[wp>Cross-platform_software|Cross-platform]] DAW: unlimited tracks and buses, automation, MIDI support | | [[https://www.archlinux.org/packages/community/x86_64/audacity|Audacity]] | Extensible audio editor with encoding and plugin support, cross-platform | | [[https://www.archlinux.org/packages/extra/x86_64/cdrdao|cdrdao]] | Audio and data recording of CD-Rs in [[wp>Optical_disc_recording_modes#CD_Disc-At-Once|Disc-At-Once (DAO)]] mode | | [[https://www.archlinux.org/packages/extra/x86_64/fluidsynth|FluidSynth]] | [[wp>Software_synthesizer|Software synthesizer]] using [[wp>SoundFont|SoundFont]] format for voicings | | [[https://aur.archlinux.org/packages/ddptools/|ddptools]] | [[wp>Disc_Description_Protocol|Disc Description Protocol (DDP)]] mastering for CD Red Book format | | [[https://www.archlinux.org/packages/community/x86_64/hydrogen|Hydrogen]] | [[wp>Drum_machine|Drum machine]] featuring custom drumkits and separated JACK outputs for each instrument | | [[https://aur.archlinux.org/packages/jamulus|Jamulus]] | A tool for online [[wp>Jam_session|jam sessions]] in real-time | | [[https://www.archlinux.org/groups/x86_64/ladspa-plugins/|ladspa-plugins]] | Package group for a collection of [[https://www.ladspa.org|LADSPA]] plugins | | [[https://www.archlinux.org/groups/x86_64/lv2-plugins|lv2-plugins]] | Package group for a collection of [[https://lv2plug.in|LV2]] plugins | | [[https://www.archlinux.org/packages/community/x86_64/patchage/|Patchage]] | JACK connection management (software [[wp>Patch_panel|patch panel]]) for audio and MIDI | | [[https://www.archlinux.org/packages/community/x86_64/qsynth|qsynth]] | Graphical control of FluidSynth written in [[https://www.qt.io|Qt]] | | TuxGuitar | [[wp>Tabulature|Tabulature]] editor with [[wp>Guitar_Pro|GuitarPro]] and [[wp>Power_Tab_Editor|PowerTab]] format support | While ''tuxguitar'' package is not provided in official repositories, you can get it from [[https://wiki.archlinux.org/title/unofficial_user_repositories#coderkun-aur|coderkun-aur]] or start binaries directly after [[http://www.tuxguitar.com.ar/download.html|download]] of compressed archives. Regarding to [[https://linuxmusicians.com/viewtopic.php?f=19&t=2290|ardour and tempo/measure changes]] there's a [[https://www.python.org|Python]] script to apply tempo map information intended for [[https://aur.archlinux.org/packages/klick-git|klick]] metronome software to an ardour session automatically: [[https://github.com/dsacre/klick2ardour|klick2ardour]]. ===== Overtone ===== There are more details for special hardware devices in the [[https://wiki.archlinux.org/title/Professional_audio#Hardware|ArchWiki hardware]] section and you may want to read about general [[https://wiki.archlinux.org/title/Professional_audio#Tips_and_tricks|tips and tricks]], too. {{tag>audio composition editing production recording}} Category: [[./|FLOSS media studio]]