CompAudio [options] AFileA [AFileB]
Compare audio files, printing statistics
This program gathers and prints statistics for one or two input audio files. With one input file, this program prints the statistics for that file. With two input files, the signal-to-noise ratio (SNR) of the second file relative to the first file is also printed. For this calculation, the first audio file is used as the reference signal. The "noise" is the difference between sample values in the files.
For SNR comparisons between multi-channel audio files, the data are treated as as a single channel. For stereo files, the SNR calculated is the same as if the two channels contain the real and imaginary components of complex samples.
For each file, the following statistical quantities are calculated and printed for each channel.
Xm = SUM x(i) / N
sd = sqrt[ (SUM x(i)^2 - Xm^2) / (N-1) ]
Xmax = max(x(i))
Xmin = min(x(i))
The above values are reported as a percent of full scale. For instance for a file with 16-bit integer data, full scale is 32768.
An optional delay range can be specified when comparing files. The samples in file B are delayed or advanced relative to those in file A by each of the delay values in the delay range. For each delay, the SNR with optimized gain factor (see below) is calculated. For the delay corresponding to the largest SNR (with optimized gain), the full regalia of file comparison values is reported.
In calculating the SNR for stereo files, the channels are considered to represent the real and imaginary parts of a complex signal. For multi-channel files, the comparisons are carried out on samples in each channel, unless the number of channels is large. In that case, the samples in the files are considered to be a single channel.
SUM |xa(i)|^2 SNR = --------------------- . SUM |xa(i) - xb(i)|^2
SNR = 1 / (1 - r^2) ,
SUM xa(i)*xb'(i) r = ------------------------------------- . sqrt[ SUM |xa(i)|^2 * SUM |xb(i)|^2 ]
SUM xa(i)*xb'(i) Sf = ---------------- . SUM |xb(i)|^2
SUM xa(i)^2 SS(k) = 1 + ------------------------- . eps + SUM [xa(i)-xb(i)]^2
SSNR = 10 * log10( 10^[SUM log10(SS(k)) / N] - 1 ) dB.
If any of these SNR values is infinite, only the optimal gain factor is printed as part of the message (Sf is the optimized gain factor),
"File A = Sf * File B".
The comparison between the files also include maximum absolute difference between samples of the files and the number of samples that differ as a percentage of the number of samples in all channels.
An example of the output for stereo files with integer 16-bit data over a range of delays is shown below.
Delay: 20, SNR = 5.25 dB (File B Gain = 0.558) Delay: 21, SNR = 65.4 dB (File B Gain = 0.667) Delay: 22, SNR = 5.25 dB (File B Gain = 0.558)
File A: Channel 1: Number of Samples: 23829 Std Dev = 855.02 (2.609%), Mean = -9.9431 (-0.03034%) Maximum = 4774 (14.57%), Minimum = -6156 (-18.79%) Active Level: 946.7 (2.889%), Activity Factor: 81.6% Channel 2: Number of Samples: 23829 Std Dev = 427.5 (1.305%), Mean = -4.9737 (-0.01518%) Maximum = 2387 (7.285%), Minimum = -3078 (-9.393%) Active Level: 473.34 (1.445%), Activity Factor: 81.6% File B: Channel 1: Number of Samples: 23829 Std Dev = 1282.4 (3.914%), Mean = -14.886 (-0.04543%) Maximum = 7160 (21.85%), Minimum = -9233 (-28.18%) Active Level: 1418.6 (4.329%), Activity Factor: 81.7% Channel 2: Number of Samples: 23829 Std Dev = 641.2 (1.957%), Mean = -7.4417 (-0.02271%) Maximum = 3580 (10.93%), Minimum = -4617 (-14.09%) Active Level: 709.29 (2.165%), Activity Factor: 81.7% Best match at delay = 21 SNR = 6.023 dB SNR = 65.39 dB (File B Gain = 0.667) Seg. SNR = 6.02 dB (256 sample segments) Max Diff = 3077 (9.39%), No. Diff = 46127 (573 runs)
See routine CopyAudio for a description of other options.
P. Kabal / v10r3 2020-11-30