Changes

Jump to navigation Jump to search

Using JACK and PipeWire

3,357 bytes added, 10:42, 1 September 2021
no edit summary
== 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.
 
First, we must prepare the <code>/srv/win10</code> directory. Run the following commands:
 
<syntaxhighlight lang="console">
$ sudo mkdir /srv/win10
$ sudo chown example: /srv/win10
$ chmod 700 /srv/win10
$ setfacl -m u:libvirt-qemu:rx /srv/win10
</syntaxhighlight>
 
We then need to allow the socket to be bind mounted to the new location. To do this, edit <code>/etc/fstab</code>, and add:
 
/run/user/1000/pipewire-0 /srv/win10/pipewire-0 none bind,rw,user,noauto 0 0
 
Then, we configure this socket to be mounted and unmounted when systemd starts <code>pipewire.socket</code>. To do this, run <code>systemctl --user edit pipewire.socket</code> and put in:
 
<syntaxhighlight lang="ini">
[Socket]
ExecStartPost=/bin/mount /srv/win10/pipewire-0
ExecStopPre=/bin/umount /srv/win10/pipewire-0
</syntaxhighlight>
 
Then, run <code>systemctl --user restart pipewire.socket</code>, and the socket should be mirrored. Now we can tell libvirt to use this socket.
 
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>
</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. You can get the names by looking at your patchbay, or run <code>jack_lsp</code>.
# 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>:
#: <syntaxhighlight lang="xml">
<qemu:commandline>
<qemu:env name="PIPEWIRE_RUNTIME_DIR" value="/srv/win10"/>
<qemu:env name="PIPEWIRE_LATENCY" value="512/48000"/>
</qemu:commandline>
</syntaxhighlight>
#: If you already have a <code><qemu:commandline></code> section, merge this block with it. Remember to change <code>1000</code> to your actual user ID. You can tune the latency and sampling rate as you like.
 
If you are using a distro with <code>apparmor</code>, you will need to configure new rules. To do this, append the following lines to your <code>/etc/apparmor.d/local/abstractions/libvirt-qemu</code> (if this file doesn't exist, create it):
<source>
# PipeWire/JACK
/etc/pipewire/* r,
/usr/share/pipewire/* r,
/srv/win10/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.
21

edits

Navigation menu