Monday, 20 July 2009

Measuring Audio Quality with Audacity

On some netbooks or laptops you may think the audio quality is good enough for your everyday sound experience; however some audiophiles can pick up audio problems that are sometimes deemed very subjective. For example, the younger people can pick up sounds upto ~20-21Khz and this can drop to ~15Khz or lower as one gets older. Also, we can get tuned to listening to music that has been psycho-acoustically modified, such as when using MP3 compression, which again can reduce and remove subtle harmonics and overtones that most people will just not notice.

But what about the actual hardware on a laptop or netbook? Surely this cannot mess with sound that much. Well, you may be surprised. To remove the subjectivity from my experimentations, I set up some test cases that could be scrutinised by more than the human ear.

Test 1: 440Hz Tone.

I used audacity to generate a 440Hz pure sine wave tone; 440Hz is A above middle C (C4) on an equally tempered musical scale. Then I played this tone at varying volume settings (adjusting them using alsamixer) out through the headphone socket down a low impedance cable into a 44KHz 16 bit sampler. I then took the digitised signal and again used audacity to plot the spectrum (select Analyze->Plot Spectrum).

At low volume settings, I was able to see just the 440Hz peak, but as I increased the volume settings, I was able to see lots of additional harmonics appear. This explained the distortion I was hearing when the volume was cranked up fairly high.

Below are two plots, the first with a low gain, the second with gain fully maxed out:

Test 2, Wider Spectrum Tests

Well, Test 1 is fine for a 440Hz tone, but we do actually use a wider spread of frequencies when listening to music! My second set of test was a repeat of Test 1, but I used two different sound samples, the first was a pure white noise sample and the second was a sine wave sweep from 10Hz upto 20Khz for 30 seconds. I then re-sampled and analysed the spectrum using audacity. On a perfect system one would expect to see an even spread across the spectrum, but again, I was able to see some drop off from 15Hkz upwards. This was another reason for the weird artifacts I was hearing.

Below the white noise test:

Test 3, checking output gain.

This was a bit more hacky. For this tests I played the original 440Hz tone for varying volume settings and sampled this and measured the observable sample amplitude using audacity. I was expecting to see some kind of linearity, but I soon discovered I was only getting linearity from middle to the top volume settings. This seems to imply that the amplifier on my hardware was not biased correctly. Any hardware experts like to comment? :-)

Anyhow, what I learn was that one can check out the audio characteristics of one's hardware using some very simple kit: a good quality audio connection from the headphone socket to a fairly inexpensive digitiser and audacity. I admit that this is fairly hacky as I've not taken into consideration distortion on the cable and the digitizer, but it does allow me to see that my irritation caused by the distortion is legitimate and not to be blamed on old age :-)


  1. I suspect what you're seeing is a consequence clipping.

    Audibly, it's that cracking sound you get when you wind up the playback volume to compensate for insenstive speakers.

    It isn't always a harmonic distortion - if you clip a high frequency, the harmonics are above half the sampling rate, so they alias down into the audible range in a most un-musical way.

    I try to keep my PC audio playback levels at about 70% on the mixer.

  2. Geeko, yep, that sounds plausible for some hardware I've got. Unfortunately for this bit of hardware test 3 showed that the the low playback levels were next to useless, and the only way of getting something audible was to crank up the mixer volume level.

    As for test 2, I was seeing all sorts of harmonics even at 60% on the mixer, which was a little disturbing to see. As I was sampling a 440Hz tone at 44KHz I am not convinced I'm seeing distortion caused by high frequency clipping with too low a sample rate.

  3. Those are weird symptoms.

    One thing to try is to scroll way to one side on alsamixer and see if you've got "External Amplifier" enabled or disabled. I can imagine a cheap and cheerful headphone amplifier will distort like crazy, but OTOH it might be what you need to drive speakers. Pot luck, just try it.

    Another, if you have a surround sound capable mobo on a desktop, is to set the alsamixer switch that duplicates the main output on one of the surround outputs. This might eliminate something in the main output path that's blown up.

  4. When I've got time I would like to repeat this for all the H/W I've got to sanity check things a little deeper. It is kinda weird.