I wanted to know how much audio distortion I could tolerate in speech or music. To find out, I wrote a Windows program that adds a calibrated amount to any .WAV file.
The program generates THD.WAV with audible pips that mark audio pairs. Distorted sound follows undistorted audio for unblind comparison. For blind comparison, sometimes the second sound is undistorted. The program writes a text file that identifies the second sounds. Take notes while listening and check the file when you're done.
The program uses a polynomial to generate distorted sample y from input sample x:
y = x + a2 * x ^ 2 second-harmonic distortion y = x + a3 * x ^ 3 third-harmonic distortion y = x + a4 * x ^ 4 + b4 * x ^ 2 fourth-harmonic distortionThe polynomial coefficients are
a2 = .02 * pct / peak a3 = .04 * pct / (1 - .03 * pct) / peak ^ 2 a4 = -.08 * pct / peak ^ 3 b4 = .08 * pct / peakwhere pct is percent distortion and peak is the largest amplitude in the input file. Referring distortion to the signal peak instead of full scale makes it independent of recorded level.