Sunday, June 27, 2010

A Close Look at Thor's Shaper


Quick Links

Thor's Shaper is a modest device - it sits nonchalantly between Filter 1 and the Amplifier module and to me it was shrouded in a certain mystery. The Reason Operation Manual doesn't give much away, mentioning it briefly on page 215:


"Waveshaping is a synthesis method for transforming sounds by altering the waveform shape, thereby introducing various types of distortion. The Shaper can radically transform the sound or just add a little warmth, depending on the mode and other settings.

There's a brief mention of how to use it, and the names of the nine modes it supports, but that's about it.

I thought it might be useful to take a closer look at the Shaper and see if I can determine what it actually does.

First, a few things you need to know about the Shaper.
  • the Shaper has to be enabled to do anything interesting, obviously.
  • only Filter 1 output can go into the Shaper - the manual says:
"You can also route other sources directly to the Shaper in the Modulation section."
    but this is not correct. The Thor modulator destinations only include "Shaper Drive", and not the Shaper audio input. If you want to direct anything into the Shaper, you need to direct it into the Filter 1 audio input, and then typically select Filter 1 Bypass to disable any filter that is there.
  • the Shaper will not do anything until you trigger a "voice" in the synth. This means hitting a note on your keyboard when Thor has controller focus, using the sequencer to play notes through Thor, or using the Step Sequencer to allocate a continuous voice by latching the Step Sequencer trigger and setting the gate length to 100%.
  • the "Drive" control can be used to change the effect that the Shaper has on the sound. It can be set to a specific value or modulated by the Mod Matrix. A signal can also be routed directly into "Shaper Drive".
  • typically you'll use it to shape audio, but you can also use it to shape CV signals as well.
  • Thor has a bug.
So what does the Shaper actually do? Simply, it shapes or distorts the incoming signal according to the mode selected and the Drive setting. In most cases, the distortion is non-linear.

It is important to understand what non-linear distortion means. To do that, let's talk about linear systems first.

Linear & Non-linear Systems

A linear system is essentially (yes, I'm going to keep it simple) one in which the output scales proportionally with regards to the input. This means that if you have one input signal and you double its amplitude, you will see the output signal double too. If you have two input signals and you add them together before putting them into the system, then the output you see will be the same as if you put each signal into the system independently and then added the outputs. This is called the principle of superposition.

Linear distortion, where a signal is altered by a linear system, is pretty common. Essentially, you multiply the signal by a number so it's either larger (amplified) or smaller (attenuated). Static filters such as low-pass filters with an unchanging cut-off are examples of such distortion. Certain frequencies are cut out or boosted by amplifying or attenuating those frequencies. I'm deliberately ignoring phase effects mmmkay? :)

This leads to an important aspect of linear systems - you can only get out an amplitude- (and phase-) modified version of the frequencies you put in. If you put in a sine-wave at 100 Hz, you can only get a sine-wave at 100 Hz out, although it might be louder or quieter than the input.

A non-linear system on the other hand is an entirely different beast. The easiest way to define such systems is to simply consider them as systems that are not linear! In all cases, the output is disproportional to the input or inputs. This means you might put in 100 Hz and get out 372 Hz, or put in 100 Hz at one amplitude level and get an output that modulates amplitude over time.

Most systems in real life are non-linear but engineers prefer to think in terms of linear systems because they are a gazillion times easier to analyse. In many situations a complicated non-linear system can be broken down into a number of simpler, linear systems and analysed to a certain level of accuracy.

Thor's shaper is a non-linear system, but it's a relatively simple one. It contains no dynamic internal state so there's no time-based distortion effects. The shaping is simply done by a non-linear function selected by the Shaper Mode. Unfortunately it's not easy at all to reduce this to a simpler set of linear systems, but we can still learn a lot by looking at its behaviour.

Linear & Non-linear Functions

Consider the function f(x) = x/2, or y = x/2, which looks something like this:

(thanks Wolfram Alpha)

Consider an input signal of some value "x" - look along the horizontal x-axis for the value x, move straight up until you hit the diagonal line, then move directly across to read the corresponding output on the vertical y-axis. It's fairly straightforward to see that this function divides all incoming signal values by 2 - it always halves the amplitude of the input signal, regardless of what the actual input is. This is linear distortion.

What about this function, y = x2?


This is a parabolic function - the output is not proportional to the input signal, but to the input signal squared. Look at x = 0.5, the output is 0.25. The signal is attenuated by a factor of 2. When x = 1.0, the output is unchanged at 1.0. So the amount of this attenuation depends on the input value. Therefore the output is disproportional to the input signal - this is non-linear distortion.

If the function goes through the origin (where the axes meet), then that means that an input value of zero produces an output of zero. This has implications for zero-frequency (DC) offset that I might talk about later.

Thor's Shaper implements nine different functions in this manner, but also provides a "Drive" parameter. This parameter simply affects the shape of each function in a particular way - for one mode it might change only part of the function slightly, in another mode it might result in a completely different function altogether. Since there are 128 possible drive settings, you could consider there to be 128 different functions for each Shaper mode.

With this in mind, now I'm going to introduce and explain each mode and how the Drive parameter affects it.

Shaper Modes

In the following sections, for each mode, you will see two plots. These are screen shots from Audacity of signals generated in Reason and distorted by Thor's Shaper. Each plot has nine waveforms - these are measurements of the Shaper at various Drive levels from 0 to 127 - 0, 16, 32, 48, 64, 80, 96, 112 and 127.

Each waveform is independent of the others - it's just easier for me to present them on a single axis. Zero on the horizontal axis is in the centre of each waveform (where the diagonal line crosses the axis in this case). Zero on the vertical axis is where the horizontal axis lies.

The first plot will be a representation of the Shaper function, obtained by passing a rising full-scale linear signal (sawtooth) through the Shaper and recording the output. This is essentially just reading out the values in the function look-up table (if Thor uses such a thing). In this example, the Shaper is turned off and output is directly proportional to the output - in fact it's the same, or y = x:


If the function is linear, then the output will look exactly like one of the graphs above. In this example only, all nine waveforms are practically identical because the Drive parameter has no effect when the Shaper is disabled.

The second plot is an example of what the Shaper does to a pure sine-wave input for each drive setting:


Because the Shaper is switched off in this example, the function is again y = x and the sine-wave is unmodified regardless of the Drive parameter. For other modes it's interesting to see the effect on the sine-wave but its usefulness is limited - remember that the Shaper is non-linear so you cannot apply the principle of superposition! Adding sine-waves together before the Shaper input does not give you the same result as adding the result of passing through separate sine-waves. A particular function might generate a harmonic for a single sine-wave input, but two sine-waves might do something else entirely - see Intermodulation Distortion below.

In all cases, you can click on an image to view a full-resolution version.

I used these RNS files to generate the signals by "exporting loop as audio":

WARNING
For the CV Scope, the connection from the main mixer to the hardware device is deliberately disconnected. Do not reconnect the audio output unless you have turned off your speaker system first! I am not responsible for any damage that might result if you try to drive CV signals through your expensive amplifier or speakers!!



Soft Clip

function

sine-wave

This is a simple distortion that reduces the range of the incoming signal as the drive increases by clipping the signal. Compared with the hard clip, there is a more gentle, rounded characteristic to the clipping. Note that at zero drive it is not quite linear - there's a small distortion in linearity and a small attenuation of amplitude. At high drive the distortion is very distinct, very similar to the hard clip mode, and will introduce many new frequencies.

sine-wave chord



Hard Clip

function

sine-wave

This is a very simple and nasty type of distortion that simply limits the input signal to a maximum and minimum level according to the drive. It is similar to the soft clip mode except that the function has no gentle rolling off before the clip takes effect. At zero drive, the function is practically linear, and at maximum drive it's pretty much a step function except for a very narrow range near zero, just like the soft clip at this drive. This distortion adds significant new frequencies at higher drives.

sine-wave chord


Saturate

function

sine-wave

It is my understanding that the saturate mode is meant to model the behaviour of a transistor that is fully turned on. There is a linear section near the origin, but as the signal approaches the upper and lower limits, the saturation function pulls it back in. It's essentially a smoother version of the soft clip, which means it puts less energy into the higher harmonics.

sine-wave chord


Sine

function

sine-wave

This is a weird one - the shaper function is actually a sine-wave itself. I'm not sure what the intent of this function is, but it's pretty strange. At low drive, it's a bit like saturate with an attenuation at extreme input values. At higher drives, the frequency of the 'sine-wave' increases rapidly, essentially producing what I'd consider to be a fairly random effect. Consider an input signal value of x, with a drive of 127 - the output value is going to be almost anything, and will change dramatically for very small changes of x. It's pretty unstable.

This mode has some interesting and dramatic results if you automate the drive control, so that it changes as the sound plays through the shaper.


sine-wave chord


Bipulse

function

sine-wave

Another slightly strange distortion mode - I imagine it's called "bipulse" because at higher drives the function looks like two pulses, one inverted. Notice that the output signal for any input is greatly attenuated for any drive setting - even at minimum drive, the signal is no more than 25% of the original amplitude. At lowest drive, it's very similar to the sine or saturate function. As drive increases, the attenuation becomes even more dramatic. It's as if the signal almost disappears. I'm really not sure what I'd use this function for, but if you put in a very quiet signal, you would get an amplified output, whereas louder inputs would tend to disappear to nothing.


sine-wave chord


Unipulse

function

sine-wave

Yep, another unusual function. This is actually an even function, which means that it reflects negative input signals back into the positive half; notice the sine-wave above, it never goes below zero. In many ways, this function is a bit like a soft clip followed by a rectify - at low drive, it rectifies and amplifies then clips the input signal. At higher drives, the clip level decreases and the amplification domain becomes very small. At maximum drive this mode essentially creates a fixed DC signal and not much else.


sine-wave chord


Peak

function

sine-wave

The peak mode has two main effects - first, it cuts out all positive input input, which reduces the energy in the output by half. Second, it clips the negative input. So it's really just a soft clip or saturate with the bottom half cut off.

One unexpected use of this mode is to implement a unipolar step function for CV processing - at maximum drive, the output is zero for negative CV (0-63), and -64 for positive CV (64-127). All you have to do is invert this and you've got a nice step function.

sine-wave chord


Rectify

function

sine-wave

Now we're getting interesting - this function has some interesting properties. At zero drive it's linear, and at low drive the bottom is attenuated. At mid-drive, the lower half of the input signal is zeroed out and energy is lost. At higher drives, things get very interesting - the lower half is mirrored up into the top half, and this has three effects - first, fundamental frequency is doubled; second, the fundamental frequency is eliminated; third, even harmonics are introduced.

You can also use this function with CV processing to zero-out half of the input signal by setting the drive to 63. Unfortunately, the function is not quite zero for negative CV input, so you don't get a pure zero. An inverted peak works better in this case. The advantage is that this function retains linearity for the upper half of the input signal domain.

sine-wave chord


Wrap

function

sine-wave

And now for the strangest function of them all. I'm really not sure how to describe this one. At low drive, it's linear, but as the drive increases the upper half of the input signal is quickly attenuated non-linearly, and then inverted! Yet the maximum positive input is still passed through unmodified. As drive increases further, it just gets weird. Look at the way it distorts a basic sine-wave. Crazy stuff!

sine-wave chord



Frequency Analysis

I set out intending to examine each mode according to its frequency response. But I quickly hit a problem - non-linear systems don't lend themselves to frequency analysis very easily at all. Since the usefulness of this analysis is very limited, I decided to give this a miss.


Audacity does do some very nice spectrum analysis plots though.


Intermodulation Distortion

Intermodulation (wikipedia) is a phenomenon of non-linear systems where two input frequencies combine in a way that does not produce harmonics, but typically sum and difference frequencies. It's essentially an interaction between the input signals - they mix together and produce new frequencies which are typically non-harmonic, or "off-key".

This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 License.

It's intermodulation distortion that makes non-linear systems difficult to analyse, as well as sometimes sound very cool. It also means that the sine-wave plots throughout this article are indicative only - simply add a second sine-wave and you'll get completely different results. Put in more complex signals and who knows what you'll get out...

As I was writing this, something occurred to me. If you take a typical Thor sound patch and play a chord, Thor creates a separate voice for each note. Each voice has its own Shaper, so you're only playing one note through each Shaper - the result is mixed together later. This completely avoids any intermodulation distortion created by different notes. If you want to create this sort of distortion, which sounds completely different, you need to route the mixed audio into another Shaper. Here are some examples of the same chord played through a separate Shaper:

soft clip
hard clip
saturate
sine
bipulse
unipulse
peak
rectify
wrap

Here's the RNS file:

Using the Shaper for CV Processing

Normally the Shaper is used for audio distortion, but with a few considerations it can also be used to process CV signals. This opens up some very interesting possibilities.

Shultz designed a Triple Cross Fader using the Shaper's rectifier mode. This brilliant design uses the drive set to maximum which implements two piece-wise linear functions. You can read all about this here.

During the development of my 8-bit Adder, I encountered an issue where one of my CV signals was growing very, very large. This was causing the Thor scaling to fail. To fix this, I fed the rogue CV signal into a Thor Shaper with the hard-clip mode set to zero drive. This clipped the CV signal at 127 rather than whatever high value it had reached, and this allowed the Thor scaling to work properly again, regardless of what processing happened before.

In order to use the Shaper for CV processing, there's a trick you need to know. Because the Shaper is located in the "per-voice" section of Thor, it is only available when Thor is playing a note. Or at least when Thor thinks it is playing a note.

To do this, route your incoming CV source into Filter 1 Audio Input, then route the Shaper output to wherever you want the output to go. The trick is to use the Step Sequencer on Repeat Mode with a single step of gate length 100%, and to tie the Step Sequencer Trigger to LFO2, set to square wave. Also, set LFO2 to trigger the Amplitude Envelope (with A=99ms, D=max, S=max, R=max). The LFO2 rate and Step Sequencer rate don't seem to matter too much (but see the bug below).


I've created a basic template for this here.

The Bug

I co-discovered an unfortunate bug in Reason 4. Although the above self-triggering of the Step Sequencer works fine after loading a file, sometimes after exporting an audio clip, or even hitting "stop", the Thor Step Sequencer stalls. The 'Run' light remains on and the Step Sequencer is running - you can see the lights flashing above the steps - but there's no output. To reset this condition, simply click the Thor Run off then on. You can set the gate length to 99% to avoid this problem, but this will introduce very obvious glitches between each step. Not good.

This bug is a bit of a shame really, because it's just serious enough to make the Shaper unreliable. To get around this, I am considering making all of my Shaper devices 'resettable' - an external signal will toggle the trigger. Then I just need a way to generate this signal on "stop" - this same behaviour can be exploited to do this, as long as this behaviour remains consistent in future versions of Reason... (*ahem*).

Update: selig has suggested an excellent workaround for this bug here, using the global LFO2 to trigger a voice's Amplitude Envelope. I have created an updated template here and the old one is still available here. This design solves the "stop" bug, but still has an issue after exporting audio. The fast LFO2 rate retriggers as soon as possible. If you don't care about the export issue, you can turn down the LFO2 rate if you like.

Using the Shaper as a Standalone Effects Device

The Shaper is a mono device - it can only process a single audio channel at a time. However you can use it to process any audio, not just Thor's oscillator signals. With this in mind, and using the same principles as the CV Shaper above, you can use the following patch to do this - just wire your incoming audio into Audio In1, and take the result from Audio Out1.
If you want to process a stereo signal, just use two of them.

The Random Element

The Reason manual mentions that the Shaper has a slightly random element:
"... there is a slightly random element to the resulting distortion."
I'm not sure what this refers to. During my analysis the shaper functions were very well defined and always returned the expected values. I did notice a couple of glitches (if you look carefully you may see them in the plots above) but I put these down to Step Sequencer glitches briefly disabling the shaper. Other than that, I didn't see anything random at all. Maybe someone at Propellerhead can enlighten us?

Spiky Glitch

One other observation - sometimes the first value that is fed into the Shaper for each 'scope' sweep outputs an extreme low value. You'll see this as a little downward spike in the function graphs above, on the left, just as each one starts. I wasn't able to determine what causes this - I'm not even sure if it's a consequence of "exporting to audio file" or whether it's either related to the way the Step Sequencer works, or behaviour of the Shaper when it is given a zero input for a period of time. Any ideas?

Conclusion

This might be the longest article I've written for this blog so far - it certainly took the most time. Hopefully, if you've read this far then you now have a better understanding of what Thor's Shaper actually does in each of its modes.

In my opinion, the effect that the Shaper has on many sounds is a bit unpleasant, although with care it can be used to add warmth. It should work differently on chords because of intermodulation, but by default a separate instance is used for each note/voice, so you have to route into a Shaper yourself.

I don't think it's quite as pleasing as the Scream4 but it is a handy device to have around and its use in CV processing is also very powerful.

If you have any comments or questions, please do submit them - it's always great to get feedback.

8 comments:

  1. my compliments for a thorough and complete documentation about the shaper! Awesome stuff

    ReplyDelete
  2. Well done article - I've never really paid much attention to the shaper until this, cheers :)

    ReplyDelete
  3. Thanks a lot. This little and almost unnoticed device was making a powerful lead that I created sound really great and I was trying to reproduce its effect somewhere else but I didn't understand it at all. This was really helpful. Now I don't think I can reproduce its effect in any other device... but this article was trully revealing. Thnx again.

    ReplyDelete
  4. Thanks everyone for your comments - I appreciate the feedback and I'm pleased you found it interesting.

    ReplyDelete
  5. The "Sine" shaper looks just like it's performing FM on the source material.

    ReplyDelete
  6. Replies
    1. Could be - it's been a while so I don't remember the details, but I do recall it was fairly random. I usually disable the mod envelope entirely in these experiments though, so I'm not sure. Thanks for the suggestion though.

      Delete