GUIDE TO REACHING LOW AUDIO LATENCY WHEN RUNNING AN APPLICATION VIA WINEHQ
This guide was written with the intention of creating a universal system for musicians with minimal Ubuntu OS changes. The guide was tested on Ubuntu 24.04.1 LTS with wine v9.17 installed and the following system configuration:
- MSI® motherboard Z170A
- Intel® Core™ i5-6600 Processor
- GeForce GTX 1650 AERO ITX 4G OC
- Inateck RedComets U21 USB 3.2 Gen 2 PCIe Card
- Steinberg UR22C Portable USB 3 Audio Interface.
Note: Using a discrete graphics card will likely help eliminate crackling at low latencies. Additionally, using a USB PCIe x4 Gen 3.0 card with exclusive USB port throughput will likely help eliminate crackling at low latencies when using a USB audio interface.
Please read the text carefully before you start system changes.
Disclaimer: This guide was written for research purposes. The author have no responsibility for any consequences, including potential device brick, violating manufacturer licenses, lose device warranty etc.
PREPARATION
STEP 1. Install Wine
Enable 32 bit architecture
$ sudo dpkg --add-architecture i386
$ sudo apt update
Find out Ubuntu's VERSION_CODENAME
$ cat /etc/os-release
Create a “keyrings” directory if it does not exist
$ sudo mkdir -pm755 /etc/apt/keyrings
Download the WineHQ repository key
$ sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
Add the WineHQ repository key from the keyrings directory
$ software-properties-gtk --open-tab=3
Add the WineHQ repository
$ sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/noble/winehq-noble.sources
See: Debian/Ubuntu · Wiki · wine / wine · GitLab
Update the list of available packages
$ sudo apt update
Install
$ sudo apt install --install-recommends winehq-devel
STEP 2. Install complete lowlatency Linux kernel then reboot your system
$ sudo apt install --install-recommends linux-lowlatency
STEP 3. Set the default boot kernel
Edit the grub file then save the changes
$ sudo nano /etc/default/grub
Add the following two lines
GRUB_SAVEDEFAULT=true
GRUB_DEFAULT=saved
Replace the following line
GRUB_TIMEOUT=0
with
GRUB_TIMEOUT=3
STEP 4. Update GRUB then reboot your system
$ sudo update-grub
In the GRUB menu, go to Advanced options and select lowlatency kernel. Your choice will be saved as default.
Note: For updates and standard tasks, use generic kernel.
STEP 5. Install winetricks and run. Use winetricks to set Windows version to Windows 10
$ sudo apt install winetricks
$ winetricks
Follow the sequence of selecting options: Select the default wineprefix > Change settings > win10
Note: The “Windows Audio” audio device type is available in Windows 10.
EXAMPLES OF USE
E1 STEP 1. Make sure that a lowlatency kernel is used (necessary to eliminate crackles at low latencies)
$ uname -r
E1 STEP 2. Set CPU governor on Ubuntu operating system to "Performance" (necessary to eliminate crackles at low latencies)
E1 STEP 3. Install the application
$ wine '/home/username/Downloads/setup.exe'
Note: You can practice with Surge XT tool
E1 STEP 4. Launch the application via the Dash menu
Note: If the application does not appear in the Dash menu, reboot the system
E1 STEP 5. Use the app's Audio Settings menu to make the following changes:
- Audio driver type: Windows Audio
- Output: PulseAudio Output, Sound card or Audio interface
- Sample rate: <samplerate>
- Audio buffer size: <buffersize>
Formula for approximate calculation of total latency: total latency=(((alsa.output.quantum + application.quantum + audio.driver.quantum)÷rate)×1000).
Examples using “Windows Audio” Audio Driver: (((128+240+128)÷48000)×1000)=10,333333333ms, (((192+480+128)÷96000)×1000)=8,333333333ms, (((256+960+128)÷192000)×1000)=7ms.
Example using “DirectSound” Audio Driver: (((128+240+256)÷48000)×1000)=13ms
Note: The examples were tested on a Realtek® ALC892 Codec and a Steinberg UR22C Portable USB 3 Audio Interface.
E1 STEP 6. Set a force sample rate and buffer size or rules for automation
$ pw-metadata -n settings 0 clock.force-rate <samplerate>
$ pw-metadata -n settings 0 clock.force-quantum <buffersize>
Note: This should be done every time the operating system is started or restarted.
Note: Ideally, the app's sample rate and the forced sample rate must be the same (for resampling latency bypass).
Note: Additionally, you can make changes to the following files $ sudo nano '/usr/share/pipewire/minimal.conf', $ sudo nano '/usr/share/pipewire/pipewire.conf'.
E1 STEP 7. Confirm that the changes have been set
$ pw-metadata -n settings
To cancel the force-rate and force-quantum changes, do the following:
$ pw-metadata -n settings 0 clock.force-rate 0
$ pw-metadata -n settings 0 clock.force-quantum 0
E1 STEP 8. Find out about quantums (buffer sizes), rates (sample rates), if Xruns or Errors have occurred
$ pw-top
SEE ALSO
GPU PASSTHROUGH GUIDE FOR UBUNTU WITH NOUVEAU DRIVER INSTALLED
GPU PASSTHROUGH GUIDE FOR UBUNTU WITH NVIDIA PROPRIETARY DRIVER INSTALLED
NVIDIA HARDWARE-ACCELERATED TRANSCODING USING FFMPEG
PipeWire Guide
WineASIO
TROUBLESHOOTING
Problem: I hear a choppy sound with crackles.
Action:
- Set the correct rate (sample rate) and quantum (buffer size)
Problem: I hear a sound with crackles.
Action:
- Increase the quantum (buffer size)
Problem: The options with small values of Sample rate has disappeared from the Audio Settings menu of the installed on wine application.
Action:
REFERENCES
PipeWire
PipeWire
Advanced Linux Sound Architecture
Config PipeWire
Set the default kernel in GRUB