__FORCETOC__
----
'''NOTE: Since the release of Looking Glass B6 which has native audio support built in, this is no longer the preferred method unless you require audio from the VM while the LG client application is not running'''
----
QEMU's JACK backend provides the best audio quality out of all the available options (Scream, PulseAudio, etc.). One of the easiest ways to leverage the JACK support is by using PipeWire, which emulates JACK.
Normally, you can run applications with PipeWire's JACK support by running it with <code>pw-jack</code>, but this is not possible when using libvirt. Instead, you need PipeWire to provide drop-in JACK support. To do this:
* on Debian: run <code>sudo cp /usr/share/doc/pipewire/examples/ld.so.conf.d/pipewire-jack-*.conf /etc/ld.so.conf.d/; sudo ldconfig</code>
* on Arch: install the [https://aur.archlinux.org/packages/pipewire<code>qemu-audio-jack-dropin</ code> package, which contains the jack driver for qemu, and the <code>pipewire-jack-dropin] AUR </code> package.
Once this is done, you have two options. You could run your virtual machines under your user, or you could set it up so that the QEMU user has access to your PipeWire socket. The former is easier, while the latter is more secure.
Then, you can run <code>virsh edit win10</code>, and perform the following changes:
# If the <code><domain></code> line doesn't already contain <code>xmlns:qemu</code>, add <code><nowiki>xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'</nowiki></code>. The line should look like:#: <syntaxhighlight lang="xml"><domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'></syntaxhighlight># Add the following block to the <code><devices></code> section:#: <syntaxhighlight lang="xml"> <audio id="1" type="jack"> <input clientName="win10" connectPorts="input-name"/> <output clientName="win10" connectPorts="output-name"/> </audio> <sound model="ich9"> <alias name="sound0"/> </sound></syntaxhighlight>#: <code>input-name</code> and <code>output-name</code> should be replaced with a regular expression that matches the name of the JACK input and output ports. Essentially, these are the names of microphone and speaker devices that the VM would connect to. You can get the names by looking at your patchbay, or run <code>jack_lsp</code>add it.
#: If there is an existing <code><sound></code> block, it should be removed.
# Finally, we need to set PipeWire's runtime directory and latency. These are configured by environment variables. To do this, the following block right before <code></domain></code>:
/run/user/1000/pipewire-0 rw,
</source>
Once you shutdown your VM and restart it, you should see an emulated HD audio device, and any sound should go into PipeWire. If you don't hear anything, check your patchbay connections.
== Allow QEMU user access to your PipeWire socket ==
We will assuming your username is <code>example</code>, your user ID is 1000, and your virtual machine is called <code>win10</code>. We will also assume the QEMU user is <code>libvirt-qemu</code>, but this varies based on distro. We will be duplicating the socket as <code>/srv/win10/pipewire-0</code>, but the directory can be changed.
/srv/win10/pipewire-0 rw,
</source>
If you are using NixOS, you'll also need to add <code><qemu:env name="LD_LIBRARY_PATH" value="$LD_LIBRARY_PATH:/run/current-system/sw/lib/pipewire"/></code> to your <code><qemu:commandline></code> section.
Once you shutdown your VM and restart it, you should see an emulated HD audio device, and any sound should go into PipeWire. If you don't hear anything, check your patchbay connections.