Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SlewDistortion effect and oversampling support #7641

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

LostRobotMusic
Copy link
Contributor

@LostRobotMusic LostRobotMusic commented Jan 2, 2025

image

LMMS didn't have any particularly impressive distortion plugins, so I decided to make one for everybody.

The GUI was designed by thismoon.


Slew Distortion is a 2-band slew rate limiter and distortion plugin. Almost the entirety of its audio processing code is written in pure SSE2 instructions, meaning it can process all four channels (two stereo channels x two bands) simultaneously in a single thread, resulting in extremely low CPU usage for what it provides.

Unlike most distortion plugins, this one has an optional dynamics-restoring feature which can restore all of the dynamic range that distortion usually removes from your signal, meaning you can push it as hard as you want to change your sound's timbre without worrying about things sounding too squashed.

The slew rate limit can be set for both upward and downward movement independently, and can be modulated internally using an envelope follower so it morphs in time with the volume.

Most distortion plugins, especially the ones in LMMS currently, majorly struggle with aliasing, which introduces ugly and harsh high frequencies that are inharmonic and can even completely destroy the cleanliness of your song. This plugin supports up to 32x oversampling, meaning up to an extra ten whole octaves of overhead before aliased frequencies become audible, far more than you'd ever realistically need.

Ten waveshaping types are featured. Let me know if there's another one you'd like for me to add and I'd be happy to add it in!
image
(And yes, as mentioned, every single one of these distortion types are fully implemented as pure SSE2 instructions. I have not been getting eight hours of sleep.)

My personal favorites are Tanh and Sinusoidal, since they are mathematically smooth and infinitely differentiable. In less stupid terms, they can generally be pushed far more aggressively before they start to create any harsh upper frequencies.

But only having a few waveshaping presets to choose from is no fun, so I've added a couple handy knobs to help you sculpt your own with almost no performance detriment. Warp and Crush are algorithms of my own invention which allow you to pass lower-amplitude sample values through without distortion, and concentrate the waveshaping up at the higher peaks.
(They can also be used to create waveshapes essentially identical to those used in the relatively famous Camelcrusher plugin, which is fun.)

Slew Distortion comes with a handy visualizer on the right side to show you exactly what you're doing to the waveshaping curve, no guesswork needed.

image


I recommend trying the plugin out for yourself, but here are some old videos I recorded during the development process.
Singleband demo: https://youtu.be/nqabNFl46Vo
Multiband demo: https://youtu.be/jqdMEhJw_8I

These demos kinda suck, but it should hopefully give a general idea of a few things it can do. Obviously its more creative features would be far more useful on individual songs than full mixes.


KNOWN BUGS (do not merge until these are resolved):

  • The oversampling class spits out a NaN like once per hour or so, regardless of the input or situation. Even if you feed it nothing but pure silence, it'll be totally fine for an hour or more and then spit out a NaN for no reason. I've spent far too many hours trying to get this one figured out, but as you can probably imagine, it's impossibly difficult to debug an issue that almost never happens. I haven't figured out whether the bug is with my class, my usage of the class, or perhaps with HIIR itself (surely not?). If anybody spots the issue, I'd be enormously grateful.
  • The graph axes are off-center, I somehow didn't notice until just now. It's an easy fix. FIXED

Donations for developing free audio software is literally my only source of income, and I can't quite afford enough food to keep myself fully healthy, so if you're willing and able, any contributions would be deeply appreciated: https://www.patreon.com/c/lostrobot

@Rossmaxx
Copy link
Contributor

Rossmaxx commented Jan 2, 2025

Great to have another plugin added to LMMS.

The oversampling class spits out a NaN like once per hour or so, regardless of the input or situation. Even if you feed it nothing but pure silence, it'll be totally fine for an hour or more and then spit out a NaN for no reason. I've spent far too many hours trying to get this one figured out, but as you can probably imagine, it's impossibly difficult to debug an issue that almost never happens. I haven't figured out whether the bug is with my class, my usage of the class, or perhaps with HIIR itself (surely not?).

Have you checked all the division and modulo operators? If not, i would recommend manually adding a ternary to find and fix the nans.

I don't have much else to say

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants