Hacker News new | ask | show | jobs
by TheOtherHobbes 1274 days ago
Oversampling won't help with the brickwall clipping being attempted here.

This circuit is not a diode emulator, it's a comparator. It's the worst-sounding of all distortions. It sounds even worse in digital because of the aliasing.

And it will always alias, no matter how much you oversample it, because a vertical edge - aka "Heaviside Step Function" - has an infinite harmonic series. If you oversample it enough it won't alias much because the series terms become smaller. But they never disappear.

A better way to do this kind of clipping is with a tanh (logistic/s-curve) approximation. That can give you a variety of valve-like [1] smooth clipping curves. Unfortunately tanh is pretty expensive computationally, so a more practical alternative is a piecewise curve, perhaps with some interpolation.

Although if you only have 8-bit or 16-bit resolution you may as well just use a lookup table.

OP might want to consider learning a little more about signal theory and practical DSP before posting more how-tos.

[1] Not really because real valves are more complicated. But it will do for a first approximation.

2 comments

I appreciate your feedback and sharing your knowledge! I'll definitely be digging more into some of the things your mentioned to get a better understanding. The topic is a super deep one–though my goal (at least at this point) is to stay high level enough so that anyone could get started in making their own sounds/effects.

The lower the barrier of entry, the more cool things that people can come up with! I'm hoping that more without a math/EE/audio background like myself can get started and explore some more of these deeper topics :)

It will help, though! Commercial products will use 4-16x oversampling internally. Most useful distortions will have infinite harmonic series, but the hard clipper is certainly one of the worst because of the high amount of total harmonic distortion (THD). There's a lot of energy in those upper harmonics.

The classic soft clipper is something like

    tanh(kx) / tanh(k)
which gives you a normalized output. It's not that expensive in the grand scheme of things, and is certainly cheaper than oversampling.

If you want something even more valve-like, a bit of DC bias to the signal before tanh will give you even order harmonic distortion, which sounds warmer (it beefs up the signal and puts energy into the octave harmonics, where as hard clippers usually only shove energy into the odd harmonics which sound harsher).