by diydsp · 3y ago · 0 comments
https://jatinchowdhury18.medium.com/practical-considerations...
Admittedly, I'm early into moving from analog circuits to digital signal processing, so I could be off the mark on my answer. :) Hope it helps, though.
When you clip in discrete time, the spectra is finite (more technically, it's periodic with a period of the sample rate frequency). That means the energy that would go into harmonics past nyquist gets "wrapped" around.
This is the big difference between analog and digital distortion. In analog, it's really quite difficult to create energy at non-harmonic frequencies of the signal. In digital clippers like you have here, it's trivial, and the design problem is figuring out how to deal with it. Most products will use some kind of anti-aliasing strategy (usually oversampling before clipping) to handle it.
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.
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 :)
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).
One trick for doing nonlinear waveshaping without introducing too much aliasing is to perform the wave shaping at a higher sample rate than the rest of your system and then downsampling with a low pass filter. Thankfully, the high frequency components introduced by nonlinearity tend to decrease in magnitude reasonably quickly.
In the digital (or again more correctly discrete-time, you have a sample rate) realm it totally makes a difference, because many of the harmonics you generate will extend above the Nyquist frequency, half the sample rate, and "reflect" back down.
In general, the more pointy edges you introduce to a waveform, the more high frequency artifacts you get.
This aspect of pontryagin duality (narrow in one domain means wide in the other) is also what underlies the heisenberg uncertainty principle. If you "hard clip" a photon's position (with a slit) you get a lot of frequency domain (momentum) noise, leading to a spread-out beam.
I don't see you doing anything in particular to bandlimit your waveshaping, but I might well have missed it.
Nobody using clipping as an effect in their music cares if a fuzz/distortion/overdrive effect is less than pristine from an audiophile standpoint.
Audiophiles would throw up if they realized exactly what's going on in a guitar rig.
Audiophiles also drop a lot of money on gear that intentionally distorts the signal. Aliasing is one reason why they buy tube amplifiers instead of tube modelers in their receivers, although I don't doubt the latter exists.
I'd bet I could ask 10 other people who play guitar and none of them even know what aliasing is.
And none would be able to talk intelligently about what it means and what sounds good when thinking about a transistor distorting, an op-amp distorting, diode or LED clipping, a tube causing clipping/distortion, or a digital algorithm clipping. Most just try something and fiddle with the knobs, decide whether it sounds good or not, and move on with trying to figure out what music to create.
I actually find the stuff that gives more options around clipping tends to just be annoying. I prefer the designer to just pick the best sounding one and just go with that. Pretty much every time I've had an effect that offered a clipping switch or rotary dial one sounds the best, it takes a couple minutes to decide, after that I just wish the designer had left only that best one in the product without a switch.
I'd kind of argue intentional aliasing as a purposeful strategy to get a unique sound is probably something that has been overlooked. I guess "bit crushing" counts and that is somewhat common though.
Audiophiles are a whole different thing. I love tubes for playing guitar where everything is very non-audiophile but it's still really hard to wrap my head around it for audio reproduction.
I have been doing tons of anti-aliasing and saturation DSP lately and agree you mostly should be picking a vibe and sticking to it as a DSP sound designer. However the hell that comes together in the math is irrelevant, as long as the minimal set of controls you provide to the musician are fun to tweak and you’re not delivering an airplane cockpit.
There is a lot of marketing blather about analog this legendary that but at the end of the day, a unique sound that is fun for musicians to “play” or intuitively useful for the tradespeople (mixers, mastering engineers, trackers) to use is all that matters!
For example, if you were comparing AxeFX, Kemper, or Line6 Pod none of this would be on the labeling, but it's deeply tied to how they were designed.