Monday 28 March 2016

Raspberry Pi audio vs. Adafruit USB audio

Many people on the internet comment about the poor sound quality of the Raspberry Pi audio output when taken direct from the 3.5mm jack socket.

One alternative is the Adafruit USB audio adaptor, which provides a mic input and headphone output.

Both the Pi jack and Adafruit audio outputs sounded a little harsh to me, so I decided to do a few checks using sine waves and a scope.

As I'm still in the process of building a Pi powered radio for our kitchen, I have been testing the design with just the bare speakers laying on my desk. I can't decide which I prefer; using the Pi audio direct from the jack socket or taking the audio from an Adafruit USB module.

I have 2 of these little Adafruit modules which I bought to use just for the mic inputs. They are great, and really cheap, but how do they perform when used for audio output?

This is what Adafruit say about the Pi and their USB audio adaptor;

The Raspberry Pi has an on-board audio jack, which is super handy for all kinds of sound effects and speech, just plug and go! However, for when you want better audio for music playback, a USB audio card can greatly improve the sound quality and volume. That's because the on-board audio is generated by a PWM output and is minimally filtered. Don't get us wrong, it's a great thing to have audio on board but this USB audio card will make it even better.

Having tried a simple listening test in my last post, I couldn't really decide if it was worth using an Adafruit rather than simply using the Pi audio jack. I found some time over the Easter weekend to do further testing using sine waves and my cheap Hantek scope module.

Initially I used the Linux command: speaker-test

This is a very useful command which can be used in one of three modes:-
  • Pink: this produces noise, what most people call "white noise". But white noise is actually spread over the entire spectrum, whereas pink is just across the audible (to us) spectrum
  • Sine: this can produce a sine wave up to a maximum of 8000Hz
  • Wav: this outputs a lovely ladies voice, one channel at a time

So I started with something like this:-

speaker-test -D hw:ALSA -t sine -c1 -s1 -f440

...and the captured output looked like this:-

left: Pi jack, right: Adafruit

This was a surprise. The Adafruit output floats at about 2Volts d.c. which indicates that it does not have an output coupling capacitor. And as my Hantek scope does not have an a.c. coupled mode, the signal appears clipped when I try to increase the vertical resolution and keep the trace on screen.

The issue here is that my NJM2073D amp is also d.c. coupled, so there is a danger that the output could also become clipped when I turn the volume up!

So I fitted 10uF coupling capacitors and repeated the test, which fixed the problem. In addition to 440Hz, I also tested at 85Hz, 1kHz, 4kHz and 8kHz.

At higher frequencies the outputs started to look really ugly;

Pi jack on the left, Adafruit on the right

In the Adafruit trace we can clearly see the sampling points. The sampling frequency is 48,000Hz so the distance between these points is just over 20uS. There seems to be little or no attempt to filter this waveform. Either way, the end result is not a clean sine wave.

The Pi jack audio trace is also bad, but in a different way. There appears to be some filtering, which is softening the transition between sampling points.

A third comparison

Just to make sure this wasn't some dreadful nightmare, where my results were due to my primitive test methods, I conducted a few tests with an HP laptop.

First of all, I connected my signal generator to the laptops mic input via a 100k resistor and recorded an 8kHz sine wave via Audacity. I set the project sampling rate to 96,000Hz for the best possible results, and the Audacity display showed a pretty good sine wave.

I then used the saved 8kHz WAV file as my signal source and repeated the tests.

The results were a bit different...

Pi left/Adafruit right

...but still not good. The sampling points of the original file seem to be further distorting the output signal.

As a final test I connected my scope to the laptop audio output. Using either the speaker-test method or the 8kHz wav file gave this kind of result...

HP Laptop output from 8kHz WAV file that's what I call a sine wave!

What to do?

I guess what is required is a good low-pass filter to restore the sine wav from either the Pi or Adafruit outputs. When I say "good" I mean as a minimum an active 2nd order filter.

I doubt this will happen for my KitchenPi radio, but I do need to order a couple of 1nF capacitors and see what happens when I solder these across the 10k volume control. I'm hoping this may remove some of the sound harshness without loosing too much of the high frequency response.

Closely related posts:-

No comments:

Post a Comment