Cornus Ammonis's Avatar

Cornus Ammonis

@cornusammonis

Just a feedback loop

495
Followers
499
Following
133
Posts
13.11.2024
Joined
Posts Following

Latest posts by Cornus Ammonis @cornusammonis

The main difference is they support fast lower-precision math, have much more VRAM, much fewer ROPs, and don't have video output ports. It's a specialized GPU.

07.01.2025 02:56 ๐Ÿ‘ 3 ๐Ÿ” 0 ๐Ÿ’ฌ 0 ๐Ÿ“Œ 1

I'm aware, but this is written with an audience in mind that is more familiar with trig than convolution.

06.01.2025 20:59 ๐Ÿ‘ 3 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

Thanks to @tildesounds.bsky.social for prompting this.

06.01.2025 19:13 ๐Ÿ‘ 6 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Equations demonstrating that distortion applied to two tones with a perfect 5th interval between them results in an intermodulation distortion component that is an octave below the fundamental. This technique is often used by guitar players to get a full sound.

Equations demonstrating that distortion applied to two tones with a perfect 5th interval between them results in an intermodulation distortion component that is an octave below the fundamental. This technique is often used by guitar players to get a full sound.

That idea is a direct consequence of interpreting HD as AM. AM doesn't always produce tones that are harmonic relatives of the inputs, namely when the inputs aren't harmonic relatives of each other. The same is true of HD, and when this happens it's called intermodulation distortion.

06.01.2025 18:52 ๐Ÿ‘ 5 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

I also haven't addressed intermodulation distortion (ID). ID is often treated as something categorically different from HD, but I would argue that it is the same thing as HD, but in the context of complex signals, i.e. signals that contain tones that are not harmonics of one another.

06.01.2025 18:50 ๐Ÿ‘ 5 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

I've somewhat conflated "harmonic distortion," as in the harmonics created by distortion, and "a harmonic distortion," as in a memoryless nonlinearity that creates harmonics. If that bothers you, feel free to mentally substitute one or the other definition as appropriate.

06.01.2025 18:49 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

Some glossed-over details: I've assumed here that the sidechain signal is the same as the input signal. It doesn't have to be, and when it isn't we can't call a compressor a harmonic distortion. This reasoning only applies when the input and sidechain signals are harmonically related to each other.

06.01.2025 18:49 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

Interestingly, I've never seen a compressor design that attempts to account for and cancel out a compressor's effect on phase. Many people use compressors in a way that's closer to being a pure distortion (like OTT), which puts the most dramatic phase distortion in the range where you can notice it.

06.01.2025 18:49 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

So, is a compressor always a harmonic distortion? In one sense yes, in that it limits a signal by creating harmonics. In another sense no, in that the harmonics don't have the same phase relationship as they do in a harmonic distortion.

06.01.2025 18:48 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Example showing that amplitude modulation of a wave with a phase-shifted version of the same wave doesn't change the amplitude of the created harmonic.

Example showing that amplitude modulation of a wave with a phase-shifted version of the same wave doesn't change the amplitude of the created harmonic.

On the other hand, the phase delay doesn't cause the magnitude of the harmonic spectrum to change due to interference, and the effect would mostly be heard as a change in spatialization (for a stereo signal) or a change in transients.

06.01.2025 18:48 ๐Ÿ‘ 5 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

Arguably yes, because of the influence of the lowpass filter on phase. A more strict definition of a (memoryless) distortion requires that the phase of the created harmonics can only change by a multiple of ฯ€/2, and the phase delay of the lowpass filter causes that to no longer be the case.

06.01.2025 18:45 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

This makes a compressor look more like a harmonic distortion, with a harmonic profile that's controlled by its lowpass filter characteristics. So, does using a lowpass filter make this not technically a harmonic distortion for some reason?

06.01.2025 18:45 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

Contrary to conventional wisdom, aliasing primarily happens inside the envelope follower/gain reduction stages, and the sidechain signal is typically audible, because the envelope follower filter is not steep enough to cut out everything above 20Hz, even with a slow attack/decay time.

06.01.2025 18:45 ๐Ÿ‘ 5 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

Put another way, so long as our envelope follower and gain reduction can be expressed as a (memoryless) distortion applied to the input signal, the whole system can be expressed as a single distortion function.

06.01.2025 18:45 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

From all this we can draw a few conclusions. Ignoring the lowpass filter (which corresponds to a very low attack/release time), a compressor is ultimately a saturating distortion like any other.

06.01.2025 18:44 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Post image

In fact, if we ignore the lowpass filter in our compressor signal chain, we can combine the rectifier and gain reduction functions and compare that against tanh(x)/x, and see that they look almost identical if we choose appropriate threshold, ratio, and knee settings for gain reduction.

06.01.2025 18:44 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Equations showing tanh(x) in "gain reduction form" is an even distortion.

Equations showing tanh(x) in "gain reduction form" is an even distortion.

Looking at tanh(x) again, we could instead frame the function in a "gain reduction form," meaning that we find the function that we would multiply by x to get tanh(x). This is simply tanh(x)/x, which is an even distortion.

06.01.2025 18:42 ๐Ÿ‘ 3 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Example showing that multiplying odd and even harmonics together produces odd harmonics.

Example showing that multiplying odd and even harmonics together produces odd harmonics.

This means we have a signal chain that generates even harmonics, which is then multiplied by our fundamental. The fundamental is the first harmonic, which is odd. When we multiply even and odd harmonics together, the result is all odd harmonics, just like in the tanh(x) function from earlier.

06.01.2025 18:37 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Post image

This combined gain reduction function is also an even distortion, so our signal chain so far is: even distortion -> lowpass filter -> even distortion. The final step in the chain is multiplying the result of the GR function with our original input signal.

06.01.2025 18:35 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Example of a simplified gain reduction function. There are several ways to design one of these functions, especially when taking CPU performance in mind, although the overall effect is basically the same.

Example of a simplified gain reduction function. There are several ways to design one of these functions, especially when taking CPU performance in mind, although the overall effect is basically the same.

Without going too deep into the details, in practice, the gain reduction stages can typically be combined together as shown here, where x is the amplitude of the signal, k is the knee sharpness, T is the threshold in dB, and R is the compression ratio.

06.01.2025 18:34 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Graph of a softplus function showing different knee parameters.

Graph of a softplus function showing different knee parameters.

The next stage of a compressor is gain reduction. This is typically done by taking our estimated signal level from the envelope follower, converting it to dB, thresholding it, and then converting it back from dB. A "soft knee" function is used for the threshold, like this "softplus" function:

06.01.2025 18:31 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

The slew limiter then filters out higher-frequency harmonics. Slew limiters are equivalent to a 1-pole lowpass when they 1) are exponential rather than linear and 2) have equal attack/decay times. They otherwise act like a lowpass + even distortion, which doesn't change the overall analysis much.

06.01.2025 18:30 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

A full-wave rectifier is equivalent (ideally) to the absolute value function, and a slew limiter is a kind of specialized 1-pole lowpass filter. A full-wave rectifier is an even distortion. It produces infinite harmonics, all of which are even multiples of the input frequency.

06.01.2025 18:29 ๐Ÿ‘ 5 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Post image

A common envelope follower design works by passing a signal through a full-wave rectifier, which is then sent to a slew limiter to smooth the signal out with a specified attack/decay time. These steps are not spectrally neutral, and if not oversampled, the rectifier can cause aliasing.

06.01.2025 18:28 ๐Ÿ‘ 6 ๐Ÿ” 1 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Diagram of a compressor I found online, which incorrectly says the sidechain signal is not audible.

Diagram of a compressor I found online, which incorrectly says the sidechain signal is not audible.

Back to compressors: a typical compressor design uses an envelope follower to estimate the level of a signal, and a threshold function to apply gain reduction to the input signal when it gets too loud. (This is a screenshot from a guide for producers, note the "Not Audible" claim--this is not true!)

06.01.2025 18:27 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Post image

This way, we can directly frame distortion in terms of amplitude modulation, and estimate the harmonics of our distortion function, without using Fourier analysis. Comparing a direct FFT of tanh(sin(t)) to our calculated harmonics, we get very close agreement. Note that there are only odd harmonics.

06.01.2025 18:26 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Series expansion of tanh(x) when sin(x) is substituted, showing that the result gives us a harmonic series.

Series expansion of tanh(x) when sin(x) is substituted, showing that the result gives us a harmonic series.

We can use those power-of-sine equations in order to directly convert the tanh power series into a harmonic series by substituting sin(x) for x. Here we only calculate a few terms because it gets tedious fast, but we can do this for a large number of terms with Python or Mathematica.

06.01.2025 18:25 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 2 ๐Ÿ“Œ 0

Amplitude modulation on its own does not cause a lot of aliasing, because the maximum frequency in the output is equal to the sum of the maximum frequencies in the inputs. However, if we do amplitude modulation repeatedly (as in the tanh power series), there's no upper frequency limit.

06.01.2025 18:23 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0

This means we can express this distortion function in terms of amplitude modulation of a signal with itself. There are a few caveats here: not every function readily converts to a power series, and the bound where the series converges is generally limited.

06.01.2025 18:23 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0
Power series of the tanh function.

Power series of the tanh function.

So, how does this relate to distortion? For many functions, we can get a representation of the function in terms of powers of the input, namely a power series. Here's the power series for the tanh(x) function, which is one of the most commonly used distortion functions for softclipping in audio.

06.01.2025 18:22 ๐Ÿ‘ 4 ๐Ÿ” 0 ๐Ÿ’ฌ 1 ๐Ÿ“Œ 0