duncanthrax / scream

Virtual network sound card for Microsoft Windows
Microsoft Public License
1.69k stars 142 forks source link

Scream - Virtual network sound card for Microsoft Windows

Scream is a virtual device driver for Windows that provides a discrete sound device. Audio played through this device is published on your local network as a PCM multicast stream.

Receivers on the network can pick up the stream and play it through their own audio outputs. Receivers are available for Unix/Linux (interfacing with PulseAudio or ALSA) and for Windows.

For the special scenario of a Windows guest on a QEMU host, @martinellimarco has contributed support for transferring audio via the IVSHMEM driver mechanism, similar to the GPU pass-through software "Looking Glass". See the section on IVSHMEM below.

Scream is based on Microsoft's MSVAD audio driver sample code. The original code is licensed under MS-PL, as are my changes and additions. See LICENSE for the actual license text.

Download and install

A ZIP file containing signed builds for Windows 10 on x64, x86 and arm64 is available on the GitHub releases page. The "installer" is a batch file that needs to be run with administrator rights.

Installation on Windows 10 version 1607 and newer

Microsoft has recently tightened the rules for signing kernel drivers. These new rules apply to newer Windows 10 installations which were not upgraded from an earlier version. If your installation is subject to these rules, the driver will not install.

However, cross-signed kernel drivers are still accepted by Windows 10 version 1607 (and greater) if any of the following exceptions apply:

Workaround #1: Disable secure boot in BIOS. For more information, see this issue.

Workaround #2: Add this special registry value:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CI\Policy]
"UpgradedSystem"=dword:00000001

Please review the following resources for more information.

Receivers

Receivers can usually be run as unprivileged users. Receiver systems that have an input firewall need to open UDP port 4010, or whatever custom port you use.

Functional description

All audio played through the Scream device will be put onto the local LAN as a multicast stream (using unicast is optional - see below). Delay is minimal, since all processing is done on kernel level. There is no userspace portion.

The multicast target address and port is "239.255.77.77:4010". The audio is a raw PCM stream. The default sampling rate and size can be set as the "Default format" in the driver "Advanced" property page. The default speaker/channel configuration can be set on the "Configure" dialog of the Scream sound device.

Data is transferred in UDP frames with a payload size of max. 1157 bytes, consisting of 5 bytes header and 1152 bytes PCM data. The latter number is divisible by 4, 6 and 8, so a full number of samples for all channels will always fit into a packet. The first header byte denotes the sampling rate. Bit 7 specifies the base rate: 0 for 48kHz, 1 for 44,1kHz. Other bits specify the multiplier for the base rate. The second header byte denotes the sampling width, in bits. The third header byte denotes the number of channels being transferred. The fourth and fifth header bytes make up the DWORD dwChannelMask from Microsofts WAVEFORMATEXTENSIBLE structure, describing the mapping of channels to speaker positions.

Receivers simply need to read the stream off the network and stuff it into a local audio sink. The receiver system's kernel should automatically do the necessary IGMP signalling, so it's usually sufficient to just open a multicast listen socket and start reading from it. Minimal buffering (~ 4 times the UDP payload size) should be done to account for jitter.

Setting the sampling rate (optional)

To satisfy your audiophile feelings, or to reduce unnecessary resampling, you might want to set a higher sampling rate and/or sampling width. You can do that on the driver "Advanced" property page, as shown below. Warning: using high sampling freqs with 24/32 bits width in combination with multichannel can lead to high bit rates on the network. We recommend to stick to 48kHz/16 bits for 5.1 or higher channel modes, or 44.1kHz/16 if you are going to listen to music from CDs.

Bring up the Speakers Properties window and go to the Advanced tab to set the sample rate. width="700"/>

Setting up default speaker configuration (optional)

Thanks to the great work of @martinellimarco, if your target system has a multichannel speaker setup, you can extend that to Windows as well. Use the "Configure" wizard of the sound device driver dialog, as shown below. Please note that this is just a system default, and that application software (like games) may require their own settings to be made.

The “Configure” button starts a wizard where you can step by step select speaker setups and test them.

Using unicast instead of multicast (optional)

This is only recommended if multicast gives you problems. Tweak the registry in the manner depicted in this screenshot (you will have to create the "Options" key), then reboot:

The registry keys are under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Scream\Options and they're called UnicastIPv4 for the IP in REG_SZ format and UnicastPort for the port, in REG_DWORD format.

Using silence suppression (optional)

Silence suppression will avoid sending data over the network if there is silence. Once a set number of consecutive silent samples are processed, Scream will stop sending data. Add the following registry key - the suggested value is 10000 samples (~1/4 second at 44100Hz).

Tweak the registry in the manner depicted in this screenshot (you will have to create the "Options" key), then reboot:

The registry key location is the same as above, Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Scream\Options and the setting is SilenceThreshold which is a REG_DWORD that holds a sample number, like 10000 for example.

Using IVSHMEM between Windows guest and Linux host

:warning: Note: While this setup is possible, it is generally only advised if you can't use network transfer via a standard virtio-net device. Scream on QEMU does not benefit from using IVSHMEM. It increases CPU load and latency due to the polling nature of the implementation.

This can be used as an alternative to the default networked transfer when using QEMU/KVM.

Building

Visual Studio and a recent WDK are required. Good luck!