Soundcard Impulse Response

A project log for Oscilloscope Vector Game Display

Raspberry Pi (or Linux) vector display using audio output

Ted YapoTed Yapo 02/09/2018 at 20:117 Comments

You may have noticed that I like to measure things.  I just added another example program to the GitHub repo, this time for measuring the impulse response of audio adapters.  The results are pretty interesting.  You can clone the repo and test your soundcard, too.

The impulse_response example program generates a single-sample impulse at the specified sampling rate.  In this case, 500 samples of 0, followed by a single sample of 1, then 500 more 0's, and repeats this forever.  The output from the card is then a representation of the system's impulse response.  This first waveform, taken from one of those tiny $8 SYBA USB audio adapters, is funny for several reasons.  This dongle uses a CM119 chip from C-Media, as a brief hammer and chisel session revealed:

The output from this card is slightly bizarre.  From the output shown above, it looks like there's no analog filtering whatsoever on the output - you get discrete steps right from the DAC, but digital filtering has been applied before the DAC.  The card only supports 44.1 or 48kHz, and the output above was set to 48kHz.  However, the output is sampled at 96kHz (see cursor measurement), and has been digitally filtered with an approximation of the sinc function.  This is just plain weird (not the sinc part, which is the correct reconstruction filter for frequency domain accuracy).

It's this upsampling that causes the stray dots in the vector display - in between desired dots and as ringing artifacts.  On the plus side, this card does draw discrete points on the display, even if it adds a few extra.

One of the challenges of this project is that soundcards/audio adapters are designed to sound good by reproducing the signal accurately in the frequency domain.  This is a different goal from reproducing the signal accurately in the time domain.  The sinc function is the ideal reconstruction filter for the frequency domain, but what we'd really like is a Gaussian filter, which shows minimum step times with no overshoot or ringing.


I think I know what's going on here.  I had read about oversampling interpolating DACs before, but didn't recognize this one when I saw it. Analog Devices has a nice whitepaper on the concept here.  The idea is to reduce the requirements on the post-DAC analog anti-aliasing filter, so that a lower-order filter can be used.  In this case, they've taken it to an extreme, and used *no* anti-aliasing filter at all.  I guess the assumption is that your headphones will act as the filter.  I also remembered that I can look at the frequency response implied by the impulse response using the FFT on the scope:

It's tough to read from the image, and the cursor view obscured the trace, but I measured the response as -3dB down at 18.7 kHz.  The deep trough is about 50dB down, and extends from 37 to 61kHz.  If you followed this DAC with an analog filter that dropped substantially before 61KHz, it wouldn't look that bad (as it is, the harmonics extend pretty high). @Thomas mentioned that you might use an adapter like this as a MW transmitter, and now I believe it!

I am tempted to dig out my bag of 5532 amps, whip up a decent lowpass, and see how nice I could make this cheap adapter look.

Motherboard Soundcard

Here's a similar test using the output of the audio adapter built into my desktop motherboard, reported as:

00:14.2 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] SBx00 Azalia (Intel HDA) (rev 40)

 It's an Azalia audio chipset.

This is more like what I expected to see, a nice representation of  a sinc waveform, the ideal reconstruction filter. Again, perfect for audio, but if you try to draw a single dot on the vector display, you get this ringing.

Raspberry Pi 1 Model B

Here's the same thing from the audio output of the RPi.

This thing is a fucking train wreck.

The response jumps between three different shapes, none of which resemble a good sinc.  This isn't too surprising, since the RPi "audio" output is actually just an RC-filtered PWM.  It appears that the response you get depends on how the PWM phase hits, maybe?  You can also see the RC filter at work turning steps into exponentials.  I'll have to think about this one a little more, but it looks like there is some digital filtering, the PWM, then the RC analog filtering going on.

In any case, this output probably isn't the best for vector display output, and should be relegated to sound effects, making coarse bleeps and bloops to accompany your retro vector game creations.


In the middle of writing this log, the UPS person dropped one of these on my doorstep.  The 24-bit isn't really interesting and I haven't had much chance to play with it yet, but here's what I found so far using 96kHz sampling rate.

First, the output is inverted! This is sheer apostacy for audiophiles who insist on absolute phase.  There is also a ridiculous amount of noise.  I've only used this adapter for a few minutes, and haven't even tried music through it, so it's entirely possible I've screwed something up.  I'll play with it a bit more, and report back later.

Anyway, this has been very interesting.  I had no idea soundcards would be so different...


bald engineer wrote 02/11/2018 at 03:56 point

Glad you covered the Pi. I got mine drawing wrencher but not at all crisp. I've got a cheap DAC, a high quality one, and a couple of computers I can try next.

  Are you sure? yes | no

Ted Yapo wrote 02/11/2018 at 13:46 point

So far, the best results are from the cheapest USB adapter.  The lack of analog filtering means you draw dots instead of continuous lines, but if you use enough of them, it looks good.  The random-looking extra dots created by the upsampling aren't great, but still tolerable.

It's now $7 on Amazon, assuming they haven't changed what's inside since I bought the first.  I've ordered one, and will check it out.

Oops, that's a different one.  The one I was testing was this:

It's $6 (but an add-on item, not prime shipping by itself).

I guess I get a new data point now...

  Are you sure? yes | no

bald engineer wrote 02/11/2018 at 17:20 point

I have something like that in my random bits box. I'll check it out later. My "good" DAC is a Focusrite Scarlett. Noise-free output, but I see what you mean about drawing lines instead of dots. I'll give my cheap one a try later. 

Any thoughts on using a I2S based DAC? Might be a way to add a real DAC to a Pi without hanging a dongle off the USB port.

  Are you sure? yes | no

Ted Yapo wrote 02/11/2018 at 17:40 point

@baldengineer My suspicion is that DACs with I2S interfaces will do something audio-like with the signal, like the upsampling interpolating thing the cheap dongle does.  If you want a nice audio output from the Pi, this might be the way to go.

If you want to add hardware for better vector graphics output, a general-purpose DAC would probably be a better bet.  This one is 2-channels, 12-bits, has synchronized outputs, and at 20MHz SPI clock, should handle close to 312ksps on each channel. At $3.18 each in singles, it seems like a bargain.

You know, I started this project with ideas of not building any hardware, but this is pretty tempting.

You could use the output of that DAC as-is for displaying dots, or add some kind of Gaussian filter on the output for more of a line display.  I'll have to figure out how to make a Gaussian-shaped filter with lumped components.  You can approximate one with multiple box filters, but that doesn't directly translate into LCR's:

  Are you sure? yes | no

Ted Yapo wrote 02/11/2018 at 20:13 point

Oh, I forgot to mention the slew-rate control on the display_params struct.  It controls the number of points output per unit length.  You might have better luck turning it up higher.

  Are you sure? yes | no

Thomas wrote 02/09/2018 at 20:27 point

Nice writeup!

It's not surprising that the C-Media output looks weird, these dongles also sound weird if you use a good headset. They are are a good match for the cheapest PC loudspeakers...

  Are you sure? yes | no

Ted Yapo wrote 02/09/2018 at 21:18 point

I have a pair of Sennheiser HD 280 Pro's for daily use.  I'll have to give all these cards a subjective listen ... and haul out my audiophile dictionary to attempt capturing the experience in words :-)

  Are you sure? yes | no