Virtual balanced in/out from regular soundcard in linux - results

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Regular soundcards have only single-ended inputs/outputs. For longer runs/measurements/avoiding ground loops a balanced connection is needed.

This is what happens if stereo single-ended inputs/outputs of a regular internal soundcard are converted into dual-mono balanced ones by simple alsa configuration in .asoundrc.

Code:
pcm.balanced_in {
         type route
         slave {
                 pcm "hw:0"
                 channels 2
         }

	 ttable {
		 0.0= 0.485571
		 0.1= -0.49
		 1.0= 0.485571
		 1.1= -0.49
	 }
}

pcm.balanced_out {
         type route
         slave {
                 pcm "hw:0"
                 channels 2
         }
	 ttable {
		 0.0= 1
		 0.1= -1
	 }
}
pcm.balanced
{
    type asym
    playback.pcm
    {
        type plug
        slave.pcm "balanced_out"
    }
    capture.pcm 
    {
        type plug
        slave.pcm "balanced_in"
    }
}

Device balanced_out - right channel of the virtual device is inverted to the soundcard left output channel

Device balanced_in - input channels of the soundcard are subtracted into identical right/left channels of the virtual device. To avoid clipping with full-scale signal, each input channel contributes < 50% to the result.

To optimize common-mode rejection I measured transfer of each in/out chain:

1) recording stereo signal (hw:0 -> hw:0) and

2) measuring RMS in each channel by sox

Code:
sox out.wav -n remix 1 stat
sox out.wav -n remix 2 stat

The ratio of listed RMS amplitudes gives the channel difference and corresponding coffecient of one channel in balanced_in definition must be multiplied with. In my case the default 0.49 coefficient was calibrated to 0.485571 for the other channel.

Measured results:

Line-in jack on PC front panel was hooked with line-out jack on back panel with a regular thin long curly stereo jack cable. Older power-consuming workstation producing lots of EMI/RFI (Dell Precision, 2 x dual Xeon, 72GB RAM), internal Intel HDA with 24bit codec AD1984A.

Measured in arta under wine (wine must be configured to offer alsa software devices)

Code:
winetricks sound=alsa

Sound - WineHQ Wiki

Useful Registry Keys - WineHQ Wiki


Measured results show that even a simple integrated soundcard in the extremely noisy environment of a loaded PC offers very good CMRR (70dB).

With a stereo soundcard such setup can enable measuring bridged amps and/or significantly reducing ground loop effects in measuring.

A multichannel soundcard can be configured to provide stereo balanced output for longer runs and/or reducing the ground-loop issues.
 

Attachments

  • single-ended-1200Hz.png
    single-ended-1200Hz.png
    118.5 KB · Views: 529
  • virtual-balanced-1200Hz.png
    virtual-balanced-1200Hz.png
    108.3 KB · Views: 514
  • single-ended-13+14kHz.png
    single-ended-13+14kHz.png
    116.1 KB · Views: 514
  • virtual-balanced-13+14kHz.png
    virtual-balanced-13+14kHz.png
    112.2 KB · Views: 504
  • calibrated-cmmr.png
    calibrated-cmmr.png
    109 KB · Views: 494
  • calibrated-cmrr-13+14kHz.png
    calibrated-cmrr-13+14kHz.png
    108.3 KB · Views: 155
Last edited:
I'd like to show measurements of two amplifiers giving 1Vrms into a real loudspeaker using this method.

Measurement equipment:
- virtual balanced input on line-in of internal soundcard [Realtek ALC892, ADC with 90dB(A) SNR] in a PC with ATX supply
- Linux+Wine and ARTA measurement software

Both measurements are direct input from loudspeaker terminal into L+R wires of line-in input - no divider (ground wire was not connected). Voltage on a speaker terminal 1Vrms.

Notice: without virtual balanced input measurements would show much more power line frequencies and their intermodulations with a signal.


Amplifier #1: NAD D3020, USB input [Class-D]
NAD_D3020_1Vrms_USBin.png



Amplifier #2: DPA222mk2 fast SSE [Class-AB, designed by Pavel Dudek (Upupa Epops), built by me from DIY kit]

In this case I used internal sound card as a signal source. It has a higher noise floor at least by 3dB than it would have with a better signal source.
DPA-222mk2_fast_SSE_1Vrms.png
 
Comparision of virtual vs. native balanced input of ESI Juli@ in my measurement station Headless Amplifier Measurement Workstation

The poor CMRR (-50dB) of native balanced inputs suggests Juli uses a fake balanced input similar to one described in Audio Note

An externally hosted image should be here but it was not working when we last tested it.


When shorting the corresponding SE (cinch) input, the cold balanced input sensitivity drops down to -50dB.

IMO the performance of calibrated virtual input is clearly better than that of native fake balanced inputs of Juli.

Of course a proper balanced input with good differential amp does offer a significantly better CMMR (e.g. -100dB for Lynx22 with standard INAxxx).
 

Attachments

  • fr-virtual-balanced-192kHz.png
    fr-virtual-balanced-192kHz.png
    37.9 KB · Views: 108
  • cmrr-native-192kHz.png
    cmrr-native-192kHz.png
    38.7 KB · Views: 118
  • cmrr-virtual-balanced-192kHz.png
    cmrr-virtual-balanced-192kHz.png
    41.3 KB · Views: 112
  • no-signal-native-balanced.png
    no-signal-native-balanced.png
    42 KB · Views: 117
  • no-signal-virtual-balanced.png
    no-signal-virtual-balanced.png
    41.8 KB · Views: 128
  • fr-native-balanced-192.png
    fr-native-balanced-192.png
    35.4 KB · Views: 88
I like this old trick, too. It's something I would have liked to see integrated into software like REW, but being able to use the device system-wide (with channel gain delta compensation no less) is even better. Good for you Linux guys.

One thing:
To optimize common-mode rejection I measured transfer of each in/out chain:

1) recording stereo signal (hw:0 -> hw:0) and

2) measuring RMS in each channel by sox

Code:
sox out.wav -n remix 1 stat
sox out.wav -n remix 2 stat
This will work fine if you just do a loopback measurement, however in a real-life application you'll have to determine channel gain delta for input and output separately. No way around making cables or plugging up adapters so you can split one output channel across both L and R inputs or alternate between the output channels on either input.

Once you've matched your input channel gains well, there is no reason why CMRR couldn't be pretty high - in the "directly connected amplifier" scenario, for example, source impedance is <<1 ohm on both channels, and input impedance a few kOhms at least, possibly several 10 kOhms. If I'm not mistaken, CMRR equals about 2 R_in / ΔR_out, so we're looking at maybe 90 to 110 dB in that case (assuming 2k2..22k in and a damping factor of 60 / 8R, midband). When using a balanced attenuator of 10k/470R each (26 dB and change, the common-mode-reducing variant with midpoint at ground), it's still 54 to 74 dB with 1% parts assuming worst-case tolerances, meaning any sane person with a multimeter and a handful of each resistor value would probably do 20 dB better or more.

What's more, the cost of a stereo opamp buffer should get you a boost of another 14-20 dB if we assume an input impedance of 100-220k, and another 6 dB if instead of simply 2 resistors to ground, we are going with a T-type input bias (e.g. 10k + 10k with a 100k branching off to ground gives more than twice the common-mode input impedance as 2x 100k to ground). Realistically this is one to iron out bigger amounts of mismatch, but still. T topology also is a good idea if you need some Cs in the input for RF suppression.

Comparision of virtual vs. native balanced input of ESI Juli@ in my measurement station Headless Amplifier Measurement Workstation

The poor CMRR (-50dB) of native balanced inputs suggests Juli uses a fake balanced input similar to one described in Audio Note

fig_03.gif
While this sounds plausible, there is absolutely nothing "fake" about this circuit as long as R1/R3 and R2/R4 are matched. It is a functional balanced line receiver and used like this in loads of lower-cost (home) studio or PA equipment - power amps, monitor speakers, digital crossovers, you name it. It merely involves some nasty tradeoffs between (common-mode) input impedance, gain and noise performance, so it's not really good for anything more than a basic line-level receiver, where levels are high enough and thus lowest noise and highest CMRR aren't of utmost importance. Some particularly cheap manufacturers have also used it for a balanced mic preamp of particularly meh performance - not recommended.

If you take that same circuit and add a buffer in front as outlined above, performance can be improved dramatically. Likewise, a discrete variable-gain balanced frontend turns it into a pretty decent mic preamp (ESP P66, Behringer mixers). And of course, the two amps of the buffer can also be used to form an instrumentation amp.

So lower performance - yes, but fake - decidedly not.
 
Last edited:
This will work fine if you just do a loopback measurement, however in a real-life application you'll have to determine channel gain delta for input and output separately. No way around making cables or plugging up adapters so you can split one output channel across both L and R inputs or alternate between the output channels on either input.

Very true. That is what my automated calibration tool with preamp was planned to provide measurement-station/preamp-schematics.png at master * pavhofman/measurement-station * GitHub But since then I have moved a bit further and the planned calibration tool will have to change https://www.diyaudio.com/forums/equ...ensation-measurement-setup-2.html#post5584029

Once you've matched your input channel gains well, there is no reason why CMRR couldn't be pretty high

Well, it is not only about gain, each channel has a tiny bit different transfer function which again lowers the CMRR. This is not the case of a good differential amplifier feeding just single channel.

On the other hand the DA conversion involves errors which cancel-out in virtual balanced setup - like the small fs/4 peak in native balanced spectrum of ESI Juli (the second screenshot above ) - gone in the virtual balanced mode (the first screenshot).

So lower performance - yes, but fake - decidedly not.

Thanks a lot for the explanation. A Lynx card with proper INAxxx differential amp measures CMRR -100dB, while my Juli does only -50dB and virtual balanced inputs perform far better. That is why I called it fake :)
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.