JohnConover_medium.jpg 
john@email.johncon.com
http://www.johncon.com/john/

Linux Sound System Calibration


Home | John | Connie | Publications | Software | Correspondence | NtropiX | NdustriX | NformatiX | NdeX | Thanks



home.jpg
john.jpg
connie.jpg
publications.jpg
software.jpg
correspondence.jpg
ntropix.jpg
ndustrix.jpg
nformatix.jpg
ndex.jpg
thanks.jpg

Linux sound mixer controls interact and must be calibrated for maximum dynamic range-the difference between maximum undistorted output and the quantization noise of the digital signal.

Since the only mixer input that has a unique, single, level control is the CD, it will be used as a reference, and all other inputs balanced against the maximum CD level-the CD level will be adjusted such that at maximum input from the CD device, the output level from the mixer is just below clipping. Clipping will be measured graphically, (i.e., like using an oscilloscope,) using the tsriff program suite, from the Spatial Distortion Reduction Headphone Amplifier page and sox.

  • First, make a 5 minute WAV/RIFF file, 440.wav, of a maximum amplitude, (i.e., 32767 to -32768, maximum peak-to-peak,) 440 Hz. sine wave:

    
    
                  sox -w -s -t .nul /dev/zero 440.wav synth 300 sine create 440
    
                
  • Next, make a CD of the file, 440.wav, (using whatever your device is):

    
    
                  cdrecord -v -dev=0,1,0 -audio -pad 440.wav
    
                
  • Then, make an MP3 of the file, 440.wav, for convenience:

    
    
                  lame -V 0 -B -h 440.wav 440.mp3
    
                

To calibrate the sound system, (I will use aumix, since it is a "standard" in most Linux distributions,) with all levels set at zero, recording from the CD, and adjusting IGain, place the CD with the 440.wav in the CD-ROM, and play it with something like, (using the cdrom device for your system):



          cdplay -d /dev/cdrom start

        

and:



          sox -w -s -r 44100 -t ossdsp /dev/dsp -w -s -r 44100 -t wav outfile.wav

        

to record the 440 Hz. waveform on the CD. After about 10 seconds, kill the sox recording program, and:



          tsriff outfile.wav | cut -f1 | head -1000 > plot

        

to make a plot file of the recorded output, which can be viewed with gnuplot:


plot1.jpg

Figure I

Figure I is a plot of the 440 Hz., maximum output level, WAV/RIFF file recording. Note that the output level is the maximum supported by the sound card, with no visible clipping.


plot2.jpg

Figure II

Figure II is a plot of the 440 Hz., maximum output level, WAV/RIFF file recording. Note the pronounced clipping, meaning that the IGain level was set too high-another try will have to be made, lowering the IGain level.

The sine waveform of the 440.wav file has values that are a maximum of 32767, and a minimum of -32768, (2^16, or 65536 peak-to-peak levels, including zero, which is the WAV/RIFF CD standard,) and the maximum non-clipped value is the maximum that the sound card will handle. On most cards, it is the full 2^16 levels, but on many inexpensive cards, clipping occurs at about +/- 23000. Nevertheless, the maximum non-distorted CD output is the calibration reference for the sound card, and the IGain level should be recorded, (or better, loaded into a mixer initialization file.) The IGain level is now calibrated against the CD device output level.

Leaving the IGain value at its calibrated level, record from IGain, and adjust the CD level, (as opposed to adjusting the IGain level above,) again using sox and tsriff to find the maximum, non-clipped level the sound card will handle. The IGain and CD levels are now calibrated, leaving only the PCM level to be adjusted-eject the CD with the 440.wav file.

Leaving the IGain and CD values at their calibrated levels, play the original 440.wav file, (using the dsp device on your system):



          sox -w -s -r 44100 -t wav 440.wav -w -s -r 44100 -t ossdsp /dev/dsp

        

and record a few seconds of the output, as before:



          sox -w -s -r 44100 -t ossdsp /dev/dsp -w -s -r 44100 -t wav outfile.wav

        

iteratively adjusting the PCM level for maximum non-clipped output.

All three levels, IGain, CD, and PCM, are now calibrated to utilize the sound card's maximum available dynamic range. In better sound cards, they will all have a maximum PCM output value of 32767 to -32768, and the 440.mp3 file can be used to calibrate the Linux media players using the same procedure.

Calibration of the Line/Mic input on the sound card is more difficult. However, using the -p option to tsriff after recording about 10 minutes of content, can be of help-it tells the tsriff program to print the maximum, minimum, and root-mean-square of the PCM values of the content; there should be very few of the maximum values, (i.e., less than 1% should be over 32000, or less than -32000,) and the RMS value should be about 10-20 dB, (about a factor of 3 to 10,) lower than the peaks, (i.e., an RMS value of about 5000.)


Note that for generality, tsriff and gnuplot were used to display the waveforms in the calibration procedure. Another handy program is xoscope, and is a highly recommended tool for the Linux audio enthusiast.


Quite frequently, the line input of the sound card will be required to mix two, (or more,) line outputs of external devices; for example, individual FM/TV/DVD component/devices, all of which have different output levels. A simple "T" resistive network mixer will often suffice to combine the different signal levels-in my case, it was an FM tuner, and television. Making measurements, as above, on each, indicated that the television had to have its signal level reduced by a factor of 1.5, and the tuner had to have its level reduced by a factor of 4:

mixer.jpg
Figure III

Figure III is the schematic of the simple "T" resistive network mixer. Then, by inspection:



             R2||R3        1
          ------------- = ---
          (R2||R3) + R1   1.5

        

and:



             R1||R3        1
          ------------- = ---
          (R1||R3) + R2   4.0

        

Which means solving two simultaneous equations. However, by inspection, the first equation means something, (R2||R3,) divided by the something plus something else, (R1,) must be 2 / 3, or:



                R2||R3
          R1 =  ------
                  2

        

and:



          1         1
          -- =  ----------
          R2    3 (R1||R3)

        

or:



                       1
               1    -------
          R1 = - *  1    1
               2    -- + --
                    R2   R3

        

and:



           1      1    1
          ---- =  -- + --
          2 R1    R2   R3

        

substituting:



           1     1    1        1        1  1    1      1      1
          ---- - -- = -- = ---------- = - (-- + --) = ---- + ----
          2 R1   R3   R2   3 (R1||R3)   3  R1   R3    3 R1   3 R3

        

which means:



           1      1      1     1
          ---- - ---- = ---- + --
          2 R1   3 R1   3 R3   R3

        

and combining:



           1      4
          ---- = ----
          6 R1   3 R3

        

which means no matter what values we chose:



          R3 = 8 R1

        

and:



               8
          R2 = - R1
               3

        

Since the output impedance of many devices can be about 2K, and R2||R3 = 2 R1, 3 R1 should be about 10 times 2K, or about 20K, or R1 = 6.8K, and R2 = 18K, with R3 = 56K, which could be eliminated since the line input of most cards is 47K.


License

A license is hereby granted to reproduce this software for personal, non-commercial use.

THIS PROGRAM IS PROVIDED "AS IS". THE AUTHOR PROVIDES NO WARRANTIES WHATSOEVER, EXPRESSED OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY, TITLE, OR FITNESS FOR ANY PARTICULAR PURPOSE. THE AUTHOR DOES NOT WARRANT THAT USE OF THIS PROGRAM DOES NOT INFRINGE THE INTELLECTUAL PROPERTY RIGHTS OF ANY THIRD PARTY IN ANY COUNTRY.

So there.

Copyright © 1992-2008, John Conover, All Rights Reserved.

Comments and/or problem reports should be addressed to:

john@email.johncon.com

http://www.johncon.com/john/
http://www.johncon.com/ntropix/
http://www.johncon.com/ndustrix/
http://www.johncon.com/nformatix/
http://www.johncon.com/ndex/



Home | John | Connie | Publications | Software | Correspondence | NtropiX | NdustriX | NformatiX | NdeX | Thanks


Copyright © 1992-2008 John Conover, john@email.johncon.com. All Rights Reserved.
Last modified: Fri May 16 11:55:30 PDT 2008 $Id: index.html,v 1.0 2008/05/16 18:55:49 conover Exp $
Valid HTML 4.0!