[ADC17] Fifty Shades of Distortion (extra files + homework part 1)

Hello everybody !

As I promised during my talk, that you can see on Youtube again (or for the first time), I’m going to share some extra contents in the JUCE forum here ! So, you can download all the code samples, and a fully working JUCE plug-in doing static waveshaping + filtering here : http://www.dropbox.com/s/cjq4t08u6pqkaas/ADC17FiftyShadesDistortion.zip?dl=0

The plug-in is here to allow you to experiment with the idea of several blocks containing a waveshaper and two filters before and after, so don’t hesitate to cascade several of them within a DAW environment, to see what happens. And you’ll be able to tweak it as you wish to include other kinds of distortion algorithms inspired by the other code samples and all the stuff I talked about during my talk.

I recommend that you do all your prototyping and experimentation using the DAW Cockos Reaper, which is my opinion the best one for audio developers since it is one the most stable and probably the fastest to load when you click on the executable ! Moreover, you should create a “plug-in test” project inside, with different audio files being loaded there such as dry guitar recordings, drum loops, bass guitar sounds, some singing voice samples, and maybe a MIDI clip playing a few notes to be trigged by any optional virtual instrument. And in Reaper, you can send all the outputs of these tracks to a new one, which will be the only one where you should put the plug-ins that are in test, with the “master send” of all these tracks being disabled. This way you can have the window where you need to put your plug-in opened at project start-up, and you can choose the audio source for the testing by soloing it or muting the other ones.

By the way, I didn’t have the time to say my conclusion during the talk :slight_smile: I just wanted to say that it’s quite interesting to compare all the distortion audio effects methods, and to display how they work with processing block schemes. This way, it will be possible to improve algorithms designed from the digital world, by adding them extra “warmth”, and to make algorithms designed from the analog world more interesting and less the “copy and paste” of an analog electronic circuit into code without caring about what makes it great and how it could be even better.

Now, I did say that I had two DSP exercises to give you after you have seen the talk, so you can better understand all the basics of the talk and experiment on everything on your own. I will provide some information about them, and the solutions later, with the PDF file I used to compile all the information for my talk preparation. I recommend also that you have a look for the talk about nonlinear oscillators from the day before since it gives some useful definitions, and that you do the same with the links in the bibliography :

I’ll start with exercise 1, and you give the second one later.

Exercise 1 : create a static waveshaper with a customizable shape.

I want you to create a static waveshaper, basically a function which could take as arguments some extra information related with its shape, in order to be able to automate it in a given distortion audio effect algorithm. To do so, here is a list of guidelines :

  • You’ll probably want a sigmoid like shape knowing the application of this, so you might want your function to return zero if the input is zero, and you might want it to be continuous
  • It can be bounded whatever the input or not
  • The extra controls might help you control the slope of the function when the output is very high or close to zero (in this case it is easy to do so with just the drive control)
  • It might be branch-less or not
  • It can be a single function with a few arguments, or functions of functions, or anything related with the branches
  • It can be made using polynomials, with one polynomial for each part of the branch algorithm, or fractions of polynomials
  • You can use Bezier curves to set the different sections of the waveshaper shape
  • You can use a look-up table, and play with its content. For example, you could put a hard clipper inside, and filter the shape with a simple low-pass IIR filter to smoothen the shape of the filter
  • And you should definitely use MATLAB / Octave or the website MadTeaLab to experiment with different curves and see what happens (see this link for example).
  • See what happens with the parametric waveshapers on music-dsp with MadTeaLab as well

So tell me your remarks, your questions about that research. You should really try to create your own, don’t simply copy and paste the code from someone else ! And then, you will be able to play with the modulation idea, do what I suggested in the dynamics processors part of my talk with your new waveshaper !

The exercise 2 got its own topic :

16 Likes

Thank you for the great talk Ivan! :+1: It was one of my favourites.

3 Likes

Hi Ivan, the talk was super interesting!
What is the license of the code samples you provide for download ?

1 Like

Well, you can use them for whatever you want if you don’t say you did them, and if you let all the comments inside so we can see who is the author :wink:

1 Like

Ivan thank you for all your disclosure. I respect you and I am learning from you. There is one thing that is not clear to me about audio plugins and especially about distortion algorithms: should the numerical value of the sample output from the plugin always be between -1 and 1? I read this information about will pirkle’s book but I don’t understand if it’s always like that. So each algorithm (distortion in particular) must not give output values outside this range?

1 Like

Hello! Well I would say there is no final rule like that, and a lot of plug-ins can actually send signals with amplitude outside [-1 1]. However, the volume going to the end of your DAW signal path is supposed to stay in that range, since going outside will lead to distortion in the digital to analog converters. That’s the reason people use limiters in the master bus too, to prevent the final signal to be too high in amplitude.

However, one more reason I add sometimes hard clippers in my plug-in, preventing the signal to be higher than +2 for example, is to prevent your bugs or bad user interactions to hurt your or their ears :slight_smile:

1 Like

Soundcard drivers usually clip values outside -1…1 before they reach the DAC, but that will cause distortion with aliasing. On OSX there is a limiter that kicks in and might not do what you expect. If you produce a really large value, it’ll take seconds to recover.

If your plugin produces values outside -1…1 then the behaviour down the chain is undefined. The next plugin probably expects -1…1 and if it gets something else it might just clip it or do something terrible.

The sensible thing is to expect the input to be inside -1…1 and make the output also stay between -1…1.

1 Like

Thank you very much, so to be on the safe side better check to be within range -1 1 in case of particular elaborations like boosts, distortions etc… I wonder if I want to create a plugin that models the ideal non-inverting op amp (Vout=(1+R2/R1)*Vin) with gain, for example 5, and I assume Vin as the input data to the plugin how do I do it? Simply check if I pass +1 or -1? How can I simulate analog processing always within the range +1 -1?

How do I map analogue values always in the range -1 +1?