First let’s address the crackling, etc… The technical term for this is a “buffer underrun” btw. I have found that the PA code in Qemu is whats lacking a this time and in my personal opinion a better workaround is to tell Qemu to use ALSA instead. It will still be using PA as there is a ALSA to PA shim, but using this method in my experience it completely resolves all guest audio issues without any custom software on the guest.
See if you can get aplay
working as the user you’re running Qemu as.
aplay -L
should list all the devices, one of which should be pulse
.
If you can get this working you should be able to do what I suggested earlier and tell Qemu to use ALSA by setting the QEMU_AUDIO_DRV
environment variable to alsa
.
Here are the exact environment variables I am using with great success:
# tell qemu to use ALSA
QEMU_AUDIO_DRV=alsa
# tell ALSA to use the output device called "pulse"
QEMU_ALSA_DAC_DEV=pulse
# tell ALSA to use the input device called "pulse"
QEMU_ALSA_ADC_DEV=pulse
# total size of the audio buffer to setup for DMA to the hardware
# this varies depending on your hardware, some can handle low values which = lower latency
QEMU_ALSA_DAC_BUFFER_SIZE=512
# how big each period inside the buffer is (512 / 128 = 4 periods)
# this affects how often the kernel will wake up your application for more data.
QEMU_ALSA_DAC_PERIOD_SIZE=128
Note though that the buffer and period sizes will likely need to be tweaked as these values are specific to your hardware. In simple terms these dictate how much audio data is to be buffered between each audio thread wake up. I have a professional audio card which can handle extremely low values so what you see here may already be too low (although they are conservative as I don’t need extremely low latency for my guest VM). Note that these values must be powers of 2.
For completeness the total latency is calculated using the following formula
latency = sample rate / buffer size
For example, at 48000Hz (48KHz), the latency would be 48000 / 512 = 93ms
For more detail on this specific subject see: https://www.alsa-project.org/main/index.php/FramesPeriods
Removing PA will break tons of stuff, most packages that have any kind of audio support now depend on PA and removing it will break audio for other applications. It also does increase latency and reduces quality (forced 48KHz re-sample by default) but not enough that you would care unless you were dealing with studio quality audio, and if you were you would already be using “JackAudio” instead.
Yeah, tonight actually I plan to have a go at the Division 2 now it’s out. I have been away on a camping trip and only just got back.