Advanced cable usage

Virtual Audio Cable

Advanced cable usage

This section describes advanced usage methods. You need to understand VAC principles and simple usage rules before attempting to use advanced features.

Choosing most appropriate interface

As a WDM/KS Audio filter, VAC driver presents a pair of render and capture pins for each cable. Using these pins, Windows audio subsystem builds higher-level audio layers (see Audio layering issues). So, each Virtual Cable presents at least three audio interfaces: WDM/KS, DirectSound and MME (Wave), with a pair of recording/playback ports in each layer. In Windows 6.x, there will be a fourth interface, WASAPI.

The following list shows audio interfaces in the order of increasing efficiency:

To get higher performance and less latency, use a lowest-level possible interface type. To get higher compatibility and less problems, use a highest-level possible interface type.

Using WDM/KS or WASAPI in the exclusive mode, keep in mind that they does not support pin instance sharing. More than one connection to a specific pin is available only if a driver supports multiple pin instances. VAC supports them but not all other audio drivers do.

Using WDM/KS interface, please note that it contains a huge set of features (properties) but some audio drivers, especially third-party ones, are tested only with a limited set of them. Some properties are not documented well so driver developers may not be able to meet all the requirements. Incorrect driver behavior may cause application malfunction or even system crash. Trying a new application, new audio device or new driver version, first test them a lot in a minimal environment, prior to performing an important work.

Adjusting DirectSound hardware acceleration level

In Windows 5.x, VAC can be used via the DirectSound interface much more effectively if its hardware acceleration feature is utilized. To enable Windows to utilize it, you must adjust the hardware acceleration level for the VAC device.

In Windows 6.x, DirectSound hardware acceleration is not supported.

Stream and cable format limiting

Due to audio layering specifics, audio applications have no full control over audio formats actually used by devices for playback or recording, except of exclusive mode access. In Windows 5.x, recording operation always requests a specified format from the driver, but playback operations in Windows 5.x try to request a most wide format supported by the device for System Audio Engine.

For example, if a DirectSound application requests playback at 48000/24/2, DirectSound subsystem first requests 44100/16/2 from System Audio Engine. If a Virtual Cable is free and this format is within the cable format range, 44100/16/2 will be chosen for the cable format. A second render stream will be created with 48000/24/2 but the cable format cannot be changed when a cable is used. Therefore, VAC will perform a format conversion from 48000/24/2 to 44100/16/2 and signal quality will degrade. To minimize format conversion, you could limit a cable format, or a stream format, or both of them.

Cable format limiting is useful to specify most convenient format range for both cable sides. For example, if you want to use 48000/16/2 at one side and 44100/24/2 at another side, you could set cable format range to 44100-48000/16-24/2-2. It prevents the cable format from locking at low sampling rate and/or bitness due to implicit pin instance allocation for System Audio Engine.

By default, cable format range is restricted to very common range for better compatibility. If you want to use wider range, you can extend the format range using the VAC Control Panel.

DirectSound and MME subsystems often can try some consecutive formats if the driver does not allow them to use their preferred format parameters. A driver cannot suggest to higher-level layers to use a particular parameters but it can reject some formats and allow some others. So you could use various stream format limiting modes:

  • None - there is no stream format limiting over the common driver features. So a new stream can be created using any format supported by the driver. A format conversion will be performed in most cases.

  • Cable range (default) - a new stream can be created only if its format is inside the cable format range. A format conversion is performed in some cases.

  • Cable format - a new stream can be created only if its format exactly matches the current cable format. If a cable is free, the "cable range" mode is used for a first stream (see format selection rules for details). Therefore, no format conversions are performed because all cable streams have the same format. This mode is similar to previous (2.x, 3.x, 4.00 betas) versions behavior.

As an extreme case, you can set the same lower and upper ranges for each cable format parameter and specify stream format limiting mode to the "cable format". Therefore, only a particular format (for example, 96000/24/2) will be allowed for client streams. If both side clients are able to choose such format, no conversion will be performed. All audio data will be transferred through the cable unchanged, with no quality loss.

But don't forget that layered scheme prevents applications from having full control over their audio activity. Some implicit format conversion may occur in System Audio Engine and there is no way to easily check it.

Format conversion issues

VAC 4 supports a format conversion. But due to mixing purposes, VAC cannot directly convert from a playback client's format to a recording client's format. Instead, VAC first converts data from various playback client formats to the cable format then mixes client data using the cable format. Finally, VAC converts mixed data from the cable format to various recording client formats.

The cable format parameters are selected when a first playback or recording client connects to a given Virtual Cable. Sampling rate, bits per sample and number of channels are chosen from the cable format range to be possibly close to a client's format parameters.

For example, if a client requests 44100/16/2 and the cable format range is 22050-48000/8-32/1-8, the cable format is set to 44100/16/2 (equal to client's format). If the cable format range limits sampling rate to 22050-32000, cable sampling rate will be set to 32000. If it is limited to 48000-96000, resulting value will be 48000.

If you don't know which format is used by a particular application for playback or recording , run the VAC Control Panel. It shows a current cable format for each cable.

For multichannel (4.1, 5.1, 7.1 etc.) formats, don't forget to adjust the Virtual Cable's default format for shared-mode access (Windows 6.x) or speaker configuration (Windows 5.x).

If cable channel mixing is enabled and cable and client formats have different number of channels, only typical channel conversion schemes for 1, 2, 4, 6 and 8 channels are implemented. In other combinations, all source channels are mixed together and then distributed to all destination channels.

To extract particular channels from a stream or add them, use channel scatter/gather feature.

Try to minimize format conversion chances. A conversion is performed by the main CPU and takes significant CPU resources and it may noticeably slow your applications. When used by many clients at a same time, it may even hang your computer because the conversion is performed in kernel-mode which has higher priority than every application in the system.

Volume control issues

VAC supports volume control. For each playback and recording stream, volume and pan can be controlled via appropriate interface methods. For the entire cable, a main volume, pan and mute can be controlled, either via an audio mixer interface or the Windows Audio Mixer Control application.

To use cable volume control features, you must enable Volume Control in the cable configuration parameters.

Volume control limits are -40..+12 dB.

To control cable volume parameters, use Windows Volume/Mixer Control tool:

  • In Windows 6.x, right-click speaker icon in the system tray, select Open Volume Mixer then click the arrow under device name/icon and select a desired device. Clicking on device icon opens device properties applet; advanced controls can be found on the Levels tab. Another way is to customize a fast volume control window by selecting Volume Control Options from the speaker icon context menu and then use a single click to open the fast control window.
  • For Windows 5.x: click Start - Programs - Accessories - Entertainment - Volume control. Another way is right-clicking the speaker icon and choosing Open Volume Control. In Windows Audio Mixer Control window, open Options menu and select Properties. In Mixer Device item, select a proper Virtual Cable device and click OK. The Mixer will switch to show Virtual Cable N volume controls. The first group, "Volume Control" represents the main cable controls. "Wave" group adjusts waveform stream volume and "SW Synth" group adjusts a system-created software MIDI synthesizer channel volume. Other controls are shown for compatibility purposes and don't affect cable operations.

VAC supports only playback (output) volume controls because recording (input) cable side is connected immediately to output side and there is no difference where to change volume level. So recording volume controls for Virtual Cable devices have no effect.

Like format conversion, volume control takes some CPU resources and affects sound quality. Use it only when really needed.

Clock correction feature

When a Virtual Cable is used in a path containing another audio device (a hardware device, a software device other than Virtual Cable and even another Virtual Cable device), clock difference effect occurs. To minimize it, change cable clock correction multiplier until cable internal clock speed becomes closest to another device clock.

Mixing, format conversion and sound quality

Mixing of output streams is implemented with a saturation (clipping). If the amplitude value exceeds a maximal range defined by the sample bitness, it is clipped to the maximal value.

VAC uses relatively simple linear resampling algorithm and does not use dithering or other advanced smoothing features. Therefore, conversion results may sound worse than an original signal. To prevent quality degradation, you need to pay attention to a format matching. In an ideal case, all three formats (the playback client's format, the cable format and the recording client's format) are the same.

If all formats are equal and cable volume control is disabled, VAC performs no conversion, all samples are copied directly, and only mixing is performed if there are more than one playback clients. In such case, no quality degradation occurs (a bitperfect transfer is performed). If you play a WAV file to the playback side and simultaneously record data from the recording side, recorded data will be equal to played data, except of possible leading and/or trailing silence.

But such perfect results can be achieved only if all used formats are the same, volume control is disabled and audio data path is clearly understandable. In Windows 6.x, it is hard to clearly understand audio data path unless WDM/KS interface is used.

Start recording first

Due to layering issues, Windows 5.x audio subsystem in shared mode propagates only recording audio format on a first device connection, when a common pin instance is created for System Audio Engine. If a first connection issued to a Virtual Cable device is a playback request, shared format selection will be more complex and less predictable. So in Windows 5.x, it is better to start a recording operation with Virtual Cable before you start a playback operation on the same cable. It will fix the cable format and further playback operations will not change it.

An "operation" stands for an actual recording/playback process, not running an application. Some applications have a special button and/or menu command to start an operation. But some other applications can start an operation when they want. For example, Skype starts them when a peer connection is established.

In Windows 6.x, you can explicitly choose a default format for shared mode operations.

To watch the cable format evolutions, use the VAC Control Panel.

Speaker/channel configuration for multichannel formats

To properly transfer multichannel audio data under Windows 5.x, you must configure the Speaker Configuration for a particular Virtual Cable first. Virtual Cable's Speaker Configuration must match the channel distribution of the audio format. Adjusting the Speaker Configuration is similar to adjusting the DirectSound Hardware Acceleration Level:

  • Under Administrator account, open Audio Properties applet.
  • Open the Audio tab, select an appropriate Virtual Cable device in Sound Playback listbox and click Advanced button.
  • On the Advanced Audio Properties page, open Speakers tab, select a configuration and then click OK.
  • On the Sounds and Audio Properties page, click Cancel (if you will click OK here, your default device will be changed).

In Windows 6.x, the Configure button is not available for cables with disabled speaker-type pins (default setting). Instead, select a default format at the Advanced tab in the device properties dialog. You can enable speaker pin type for some cables but all these cables will have the same "Speakers" playback endpoint name so it would be hard to distinguish between them.

Scattering/gathering channels in multichannel streams

Mixing cable client streams to cable sound and distributing cable sound among client streams, VAC processes audio channels by three possible ways:

  • Convert a source channel set to a destination channel set using common summation/distribution schemes. For example, to convert two stereo channels to a single mono channel, left and right channels are summed together. This mode is used if the Channel Mixing is enabled for the cable.
  • Scatter a set of less number of channels to a set of more channels. Channels packed adjacently in the source stream frame are distributed (scattered) as suggested by source channel distribution mask.
  • Gather a set of less number of channels from a set of more channels. Channels placed in source stream frame as specified by destination channel distribution mask are compacted (gathered) to be adjacently packed in the destination stream frame.

Scatter/gather modes are used if the Channel Mixing is disabled for the cable. Internal cable mixing buffer in the cable format always has all channels placed sequentially. So scattering can be performed either from a playback stream having less channels than in cable format, or to a recording stream having more channels than in cable format. Vice versa, gathering can be performed either from a playback stream having more channels than in cable format, or to a recording stream having less channels than in cable format.

For example, the stream has stereo format (two channels) and mask 0x410 (BL+SR) while cable format has 7.1 format (eight channels). If the stream is a playback one, two stream channels will be scattered to eight cable channels: left stream channel will be mixed to BL cable channel, and right stream channel will be mixed to SR cable channel. If the stream is a recording one, two stream channels will be gathered from eight cable channels: left stream channel will be taken from BL cable channel, and right stream channel will be taken from SR cable channel.

In other words, there can be two data transfer paths: from audio application (source) to Virtual Cable (destination), or from Virtual Cable (source) to audio application (destination). If source stream has less channels than destination stream, scattering occurs. If source stream has more channels than destination stream, gathering occurs.

Please note that channel reordering is not supported. Scattered/gathered channels are always packed in the same order as source channels.

Scattering/gathering is performed only if cable and stream channel masks are overlapped (bitwise AND is non-zero). Otherwise, direct transfer is performed (first source channel copied to first destination channel and so on).

Most applications don't allow to explicitly specify channel distribution masks; instead, they assign a standard mask based on the number of channels. To use scatter/gather feature, you need to use KS version of Audio Repeater or develop your own application accessing Virtual Cable pins via WDM/KS interface.

See the example demonstrating scatter/gather feature usage.

Using stream buffer watermark technique

Watermark control technique is intended to partially compensate application buffering problems and, in some cases, clock difference problems.

By default, VAC driver processes stream audio data continuously at a constant speed, transferring a fixed amount of data on each timer event. If a client fails to provide data/room at a good time, an overflow/underflow occurs. If the client discovers this situation and quickly restores data flow, providing amount of data/room with a reserve, data processing continues normally. But if the client continues being late with providing data/room for the stream, overflows/underflows occur repeatedly and the only way to restore a stable flow is to stop and restart client application activity.

If watermark control is enabled, VAC does not perform audio data transfer from/to client buffer until the client provides an amount of data (for rendering streams) or empty space (for capture streams) equal to or more than the high watermark value specified (a reserve of data/space is created). Then VAC starts data transfer that consumes this reserve. If the client  provides additional data/space in time, the stream goes smoothly. If amount of data/space available drops down to the low watermark value specified, VAC suspends data transfer until the high watermark is reached again.

Both low and high watermark values are specified in milliseconds so the "amount of data/room" means an amount of audio data that is played/recorded within the specified time. There is no need to calculate number of bytes, samples or frames.

The "Max wait" parameter prevents VAC from waiting for data/room very long. If data processing is suspended, VAC waits for data/room no more than specified by this parameter (also in milliseconds) then resumes data processing regardless of actual amount of data/room.

Using stream data buffer

For each stream, VAC driver creates an internal data buffer used for some technical purposes. In some cases, this buffer can be used to compensate bad data buffering algorithm used by client application or System Audio Engine, holding some audio data while a client fails to provide data buffers in time. Please note that this buffer cannot compensate clock difference.

You can control buffer length by Control Panel application, separately for each cable.

By default, length of this buffer is set to several dozens of milliseconds that is enough for most cases. To get a smallest possible latency and overhead, you can set it to Auto; VAC driver will use a smallest possible size and bypass this buffer when possible. But please note that this buffer is not directly linked to latency time, there is only a small correlation. Latency time is much more sensitive to event period time.

In very rare cases, you may get a profit from increasing buffer length up to hundreds of milliseconds.

Please note that this buffer can compensate delays and buffering failures only for immediate driver clients, not via intermediate layers. For example, an application using KS is always an immediate client while applications using MME, DS or WASAPI are clients of System Audio Engine, not of VAC driver. But in some cases, System Audio Engine itself uses small buffer sizes and/of amount of buffers so its stability can be improved too.

Using PortCls data processing engine

For performance and stability reasons, VAC uses its own stream data processing engine, partially bypassing the code provided by the standard Windows PortCls driver. But VAC internal data processing engine is not exhaustive tested yet so there may be some problems with it. In case of such problems, you can disable internal VAC engine and use PortCls' one. In such case, you may need to restrict system threads affinity to partially avoid known PortCls problems.

Get more than 16 Virtual Cables

By Windows design, number and names of available audio devices must be specified at device installation stage. The driver cannot create more devices than were described during the installation. In VAC installation, number of described devices is limited to 16 by default for two reasons:

  • Installation of more possible devices takes more time but most users don't need many cables.
  • Creation of many (more than 10-15) audio subdevices in the driver causes very high system load and the system may almost hang for several minutes.

If you need more than 16 cables, replace the device/driver description file (vrtaucbl.inf) and catalog file (vrtaucbl.cat) with files contained in "256cables" package subfolder before the installation. If VAC is already installed, uninstall it, unpack the distribution package, replace the files and install VAC again.

Increasing number of cables, be aware of system limitation and overhead issues.