Namespaces

Variants
Actions

MSP Dynamics Tutorial 3: Distortion

From Cycling '74 Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "Click here to open the tutorial patch: 03nDistortion.maxpat In this tutorial, we'll look at the use of ''waveshaping'' to modulate an input signal, simulating the disto...")
 
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
Click here to open the tutorial patch: [[03nDistortion.maxpat]]
+
Click here to open the tutorial patch: [[Media:03nDistortion.maxpat]]
  
In this tutorial, we'll look at the use of ''waveshaping'' to
+
In this tutorial, we'll look at the use of ''waveshaping'' to modulate an input signal, simulating the distortion present in overdriven amplifiers. In the realm of analogue audio, all amplifiers introduce some form of distortion into the signal. The ability to creatively harness this by deliberately overdriving distortion circuits is difficult to simulate in a digital audio environment, as the natural artifacts and nonlinearities that render tube and transistor amplifier distortion so interesting are absent in the digital signal path. One way to overcome this is to simulate the distortion caused by amplifiers by using lookup tables to modulate the dynamic response of an input signal. Unlike the previous tutorials, which look at dynamics from a macro- (or envelope) perspective, this tutorial looks at sound amplitudes on a sample-by-sample basis.
modulate an input signal, simulating the distortion present in overdriven
+
amplifiers. In the realm of analogue audio, all amplifiers introduce
+
some form of distortion into the signal. The ability to creatively
+
harness this by deliberately overdriving distortion circuits is
+
difficult to simulate in a digital audio environment, as the
+
natural artifacts and nonlinearities that render tube and transistor
+
amplifier distortion so interesting are absent in the digital signal
+
path. One way to overcome this is to simulate the distortion caused
+
by amplifiers by using lookup tables to modulate the dynamic response
+
of an input signal. Unlike the previous tutorials, which look at
+
dynamics from a macro- (or envelope) perspective, this tutorial looks
+
at sound amplitudes on a sample-by-sample basis.
+
  
A review of the tutorial that covers
+
A review of the tutorial that covers <link type="tutorial" module="msp" name="samplingchapter05">waveshaping synthesis</link> may be useful to understand how the {{maxword|name=lookup~}} object works in MSP.
<link type="tutorial" module="msp" name="samplingchapter05">waveshaping synthesis</link>
+
may be useful to understand how the {{maxword|name=lookup~}} object works in MSP.
+
  
 
===Splitting bands===
 
===Splitting bands===
  
One of the attributes of cool-sounding distortion circuits is that they
+
One of the attributes of cool-sounding distortion circuits is that they are ''frequency-dependent'' as well as ''amplitude-dependent'' in their behavior; that is to say, the way in which they shape an input signal depends not only on how loud the sound comes in, but also the frequency components in that sound. Some distortion circuits process high frequencies far more harshly than bass frequencies; some distort a narrow range of frequencies in the mid-range and leave high sounds relatively pure. In order to simulate this, we create an MSP signal chain that splits our input signal into three bands for low, medium, and high frequencies.
are ''frequency-dependent'' as well as ''amplitude-dependent'' in
+
their behavior; that is to say, the way in which they shape an input
+
signal depends not only on how loud the sound comes in, but also the
+
frequency components in that sound. Some distortion circuits process high
+
frequencies far more harshly than bass frequencies; some distort a narrow
+
range of frequencies in the mid-range and leave high sounds relatively pure.
+
In order to simulate this, we create an MSP signal chain that splits our
+
input signal into three bands for low, medium, and high frequencies.
+
  
* Take a look at the tutorial patcher. Start the audio by clicking
+
* Take a look at the tutorial patcher. Start the audio by clicking the {{maxword|name=ezdac~}} and turn on the {{maxword|name=metro}} object labeled '1)' by clicking the {{maxword|name=toggle}} object. There are three {{maxword|name=gain~}} sliders at the bottom of the patch. Raise these each in turn, and you should hear a random sequence of vibraphone notes, with the first {{maxword|name=gain~}} slider controlling the bass, the second controlling the mid-range, and the third controlling the high frequencies.
the {{maxword|name=ezdac~}} and turn on the {{maxword|name=metro}} object labeled '1)' by
+
clicking the {{maxword|name=toggle}} object. There are three {{maxword|name=gain~}} sliders
+
at the bottom of the patch. Raise these each in turn, and you should hear
+
a random sequence of vibraphone notes, with the first {{maxword|name=gain~}} slider
+
controlling the bass, the second controlling the mid-range, and the third
+
controlling the high frequencies.
+
  
The state-variable ({{maxword|name=svf~}} --- colored red) object in our patcher
+
The state-variable ({{maxword|name=svf~}} --- colored red) object in our patcher takes the output of our sample playback logic and applies four filters to the signal simultaneously: a lowpass filter (output from the left outlet), a highpass filter (output from the second outlet), a bandpass filter (output from the third outlet), and a bandreject or notch filter (output form the last outlet). We're only interested in the first three, which roughly correspond to the bass, middle, and treble of our input signal.
takes the output of our sample playback logic and applies four filters to
+
the signal simultaneously: a lowpass filter (output from the left outlet),
+
a highpass filter (output from the second outlet), a bandpass filter (output
+
from the third outlet), and a bandreject or notch filter (output form the last
+
outlet). We're only interested in the first three, which roughly correspond
+
to the bass, middle, and treble of our input signal.
+
  
 
===Applying distortion===
 
===Applying distortion===
  
* Turn down all but the {{maxword|name=gain~}} slider controlling the low frequencies.
+
* Turn down all but the {{maxword|name=gain~}} slider controlling the low frequencies. On the right of the tutorial patcher, draw in the {{maxword|name=waveform~}} object labeled 'Low'. Start by manually retracing the shape that's already in there (a diagonal line running from bottom to top). Notice that even the slightest derivation changes the sound and adds noise. Try drawing a zig-zag shape across the waveform:
On the right of the tutorial patcher, draw in the {{maxword|name=waveform~}} object
+
 
labeled 'Low'. Start by manually retracing the shape that's already in there
+
(a diagonal line running from bottom to top). Notice that even the slightest
+
derivation changes the sound and adds noise. Try drawing a zig-zag shape across
+
the waveform:
+
 
[[Image:Dynamicschapter03a.png|border]]
 
[[Image:Dynamicschapter03a.png|border]]
 +
 
''A freehand waveshape''
 
''A freehand waveshape''
  
A transfer function with multiple zero-crossing points will have the result of
+
A transfer function with multiple zero-crossing points will have the result of adding additional harmonics to any relatively periodic waveform. In amplifier distortion, this is an important component of the 'warm' effect of tube amplification.
adding additional harmonics to any relatively periodic waveform. In amplifier
+
 
distortion, this is an important component of the 'warm' effect of tube amplification.
+
* Click the {{maxword|name=button}} object labeled 'Reset' under the 'Low' {{maxword|name=waveform~}}. The sound (and the shape) should return to normal. Turn up the {{maxword|name=gain~}} slider representing the mid-range frequencies. In the {{maxword|name=waveform~}} object labeled 'Mid', draw a diagonal slash across the middle of the waveform:
  
* Click the {{maxword|name=button}} object labeled 'Reset' under the 'Low' {{maxword|name=waveform~}}.
 
The sound (and the shape) should return to normal. Turn up the {{maxword|name=gain~}} slider
 
representing the mid-range frequencies. In the {{maxword|name=waveform~}} object labeled 'Mid',
 
draw a diagonal slash across the middle of the waveform:
 
 
[[Image:Dynamicschapter03b.png|border]]
 
[[Image:Dynamicschapter03b.png|border]]
 +
 
''Distortion around zero-crossings''
 
''Distortion around zero-crossings''
  
Notice how the mid-range now has a harsh overdriven sound to it.
+
Notice how the mid-range now has a harsh overdriven sound to it. What we've done in drawing that shape is introduce a set of additional zero-crossings around the normal zero point in the waveform. The result of this will be nonlinearities in the mid-range signal whenever its sample amplitude comes close to zero. This simulates the properties of many solid state transistor distortion circuits (such as guitar pedals), which 'kink' the signal at specific intervals to generate high harmonics from the signal.
What we've done in drawing that shape is introduce a set of additional
+
zero-crossings around the normal zero point in the waveform. The result
+
of this will be nonlinearities in the mid-range signal whenever its
+
sample amplitude comes close to zero. This simulates the properties of
+
many solid state transistor distortion circuits (such as guitar pedals),
+
which 'kink' the signal at specific intervals to generate high harmonics
+
from the signal.
+
  
* 'Reset' the 'Mid' waveshape by clicking the {{maxword|name=button}}, and turn
+
* 'Reset' the 'Mid' waveshape by clicking the {{maxword|name=button}}, and turn up the {{maxword|name=gain~}} slider representing the high frequencies. Draw a series of sharp peaks along the waveform opposite from the normal curve: [[Image:Dynamicschapter03c.png|border]] ''Introducing random non-linearities''
up the {{maxword|name=gain~}} slider representing the high frequencies. Draw
+
a series of sharp peaks along the waveform opposite from the normal curve:
+
[[Image:Dynamicschapter03c.png|border]]
+
''Introducing random non-linearities''
+
  
This type of waveshape creates a harsh distortion similar to the
+
This type of waveshape creates a harsh distortion similar to the way digital distortion effects work. By introducing noise (random activity) into the waveshape, we create the potential for completely arbitrary distortion effects that resemble less an amplifier circuit than a 'digital' effects process.
way digital distortion effects work. By introducing noise (random
+
activity) into the waveshape, we create the potential for completely
+
arbitrary distortion effects that resemble less an amplifier circuit
+
than a 'digital' effects process.
+
  
 
===Resetting and smoothing===
 
===Resetting and smoothing===
  
* Double-click any one of the {{maxword|name=patcher}} objects that are triggered
+
* Double-click any one of the {{maxword|name=patcher}} objects that are triggered by the 'Reset' {{maxword|name=button}} objects (<code>resetlow, resetmid, resethi</code>). Look at the contents of the subpatch.
by the 'Reset' {{maxword|name=button}} objects (<code>resetlow, resetmid, resethi</code>).
+
Look at the contents of the subpatch.
+
  
The MSP {{maxword|name=peek~}} object, you may recall, allows us to programmatically
+
The MSP {{maxword|name=peek~}} object, you may recall, allows us to programmatically fill {{maxword|name=buffer~}} objects with samples according to patcher logic in Max. The {{maxword|name=uzi}} object, when it receives a <code>bang</code>, sets up a chain of <code>8192</code> events that fill the appropriate {{maxword|name=buffer~}} object with an ascending ramp of values from <code>-1</code> to <code>1</code>. When the {{maxword|name=lookup~}} object uses this curve, the incoming signal gets passed unchanged.
fill {{maxword|name=buffer~}} objects with samples according to patcher logic in Max.
+
The {{maxword|name=uzi}} object, when it receives a <code>bang</code>, sets up a chain
+
of <code>8192</code> events that fill the appropriate {{maxword|name=buffer~}} object with
+
an ascending ramp of values from <code>-1</code> to <code>1</code>. When the {{maxword|name=lookup~}} object
+
uses this curve, the incoming signal gets passed unchanged.
+
  
* Close this patcher and open any of the {{maxword|name=patcher}} objects that are
+
* Close this patcher and open any of the {{maxword|name=patcher}} objects that are triggered by the 'Smooth' {{maxword|name=button}} objects (<code>smoothlow, smoothmid, smoothhi</code>)
triggered by the 'Smooth' {{maxword|name=button}} objects (<code>smoothlow, smoothmid, smoothhi</code>)
+
  
The smoothing subpatches, which are triggered whenever you release
+
The smoothing subpatches, which are triggered whenever you release the mouse from drawing in the {{maxword|name=waveform~}} object, triggers an {{maxword|name=uzi}} object that takes each sample currently in the {{maxword|name=buffer~}} and averages it with its previous sample, creating a smoother curve than would be possible by freehand drawing.
the mouse from drawing in the {{maxword|name=waveform~}} object, triggers
+
an {{maxword|name=uzi}} object that takes each sample currently in the {{maxword|name=buffer~}} and
+
averages it with its previous sample, creating a smoother curve than would be
+
possible by freehand drawing.
+
  
* Close the subpatch, and unlock the main tutorial patcher. Disconnect
+
* Close the subpatch, and unlock the main tutorial patcher. Disconnect the {{maxword|name=waveform~}} objects from the {{maxword|name=zl}} objects below them. Lock the patcher and draw some curves. You'll find that the distortion effects you create are much much more pronounced. If you want to, click the {{maxword|name=button}} objects that smooth the shapes manually. The more you click them, the more averaged out our waveshapes become.
the {{maxword|name=waveform~}} objects from the {{maxword|name=zl}} objects below them.
+
Lock the patcher and draw some curves. You'll find that the distortion
+
effects you create are much much more pronounced. If you want to,
+
click the {{maxword|name=button}} objects that smooth the shapes manually. The
+
more you click them, the more averaged out our waveshapes become.
+
  
* In the middle of the tutorial patcher, click the {{maxword|name=message}} box
+
* In the middle of the tutorial patcher, click the {{maxword|name=message}} box that reads <code>replace bass.aiff</code>. Now the sound generated by our sampler will be that of an electric bass guitar. Play with the different waveshaping techniques we looked at earlier. If you like, modify the <code>Cutoff frequency</code> of the {{maxword|name=svf~}} object with the {{maxword|name=number}} box in the middle of the patcher. This will let you choose where the midrange distortion effect is most prominent.
that reads <code>replace bass.aiff</code>. Now the sound generated by our
+
sampler will be that of an electric bass guitar. Play with the different
+
waveshaping techniques we looked at earlier. If you like, modify
+
the <code>Cutoff frequency</code> of the {{maxword|name=svf~}} object with the {{maxword|name=number}} box
+
in the middle of the patcher. This will let you choose where the midrange
+
distortion effect is most prominent.
+
  
 
===Summary===
 
===Summary===
  
Waveshaping is an exciting synthesis technique that allows you to
+
Waveshaping is an exciting synthesis technique that allows you to create complex timbres by running an oscillator through a lookup table; when used as a signal-processing technique with complex audio input, it can be used to simulate all manner of distortion effects. Because real-life amplifier distortion changes depending on the frequency content of the input signal, one way to simulate this distortion is to split an audio signal into several frequency bands and waveshape each one independently. While it's possible to scientifically measure and model the responses of different distortion circuits, freehand drawing in the {{maxword|name=waveform~}} object allows us to experiment with different curves and hear them directly.
create complex timbres by running an oscillator through a lookup table;
+
when used as a signal-processing technique with complex audio input,
+
it can be used to simulate all manner of distortion effects. Because
+
real-life amplifier distortion changes depending on the frequency
+
content of the input signal, one way to simulate this distortion is
+
to split an audio signal into several frequency bands and waveshape
+
each one independently. While it's possible to scientifically measure
+
and model the responses of different distortion circuits, freehand
+
drawing in the {{maxword|name=waveform~}} object allows us to experiment with
+
different curves and hear them directly.
+
  
 
[[Category:Teaching Material]]
 
[[Category:Teaching Material]]

Latest revision as of 15:30, 28 June 2012

Click here to open the tutorial patch: Media:03nDistortion.maxpat

In this tutorial, we'll look at the use of waveshaping to modulate an input signal, simulating the distortion present in overdriven amplifiers. In the realm of analogue audio, all amplifiers introduce some form of distortion into the signal. The ability to creatively harness this by deliberately overdriving distortion circuits is difficult to simulate in a digital audio environment, as the natural artifacts and nonlinearities that render tube and transistor amplifier distortion so interesting are absent in the digital signal path. One way to overcome this is to simulate the distortion caused by amplifiers by using lookup tables to modulate the dynamic response of an input signal. Unlike the previous tutorials, which look at dynamics from a macro- (or envelope) perspective, this tutorial looks at sound amplitudes on a sample-by-sample basis.

A review of the tutorial that covers <link type="tutorial" module="msp" name="samplingchapter05">waveshaping synthesis</link> may be useful to understand how the lookup~ object works in MSP.

Contents

[edit] Splitting bands

One of the attributes of cool-sounding distortion circuits is that they are frequency-dependent as well as amplitude-dependent in their behavior; that is to say, the way in which they shape an input signal depends not only on how loud the sound comes in, but also the frequency components in that sound. Some distortion circuits process high frequencies far more harshly than bass frequencies; some distort a narrow range of frequencies in the mid-range and leave high sounds relatively pure. In order to simulate this, we create an MSP signal chain that splits our input signal into three bands for low, medium, and high frequencies.

  • Take a look at the tutorial patcher. Start the audio by clicking the ezdac~ and turn on the metro object labeled '1)' by clicking the toggle object. There are three gain~ sliders at the bottom of the patch. Raise these each in turn, and you should hear a random sequence of vibraphone notes, with the first gain~ slider controlling the bass, the second controlling the mid-range, and the third controlling the high frequencies.

The state-variable (svf~ --- colored red) object in our patcher takes the output of our sample playback logic and applies four filters to the signal simultaneously: a lowpass filter (output from the left outlet), a highpass filter (output from the second outlet), a bandpass filter (output from the third outlet), and a bandreject or notch filter (output form the last outlet). We're only interested in the first three, which roughly correspond to the bass, middle, and treble of our input signal.

[edit] Applying distortion

  • Turn down all but the gain~ slider controlling the low frequencies. On the right of the tutorial patcher, draw in the waveform~ object labeled 'Low'. Start by manually retracing the shape that's already in there (a diagonal line running from bottom to top). Notice that even the slightest derivation changes the sound and adds noise. Try drawing a zig-zag shape across the waveform:

Dynamicschapter03a.png

A freehand waveshape

A transfer function with multiple zero-crossing points will have the result of adding additional harmonics to any relatively periodic waveform. In amplifier distortion, this is an important component of the 'warm' effect of tube amplification.

  • Click the button object labeled 'Reset' under the 'Low' waveform~. The sound (and the shape) should return to normal. Turn up the gain~ slider representing the mid-range frequencies. In the waveform~ object labeled 'Mid', draw a diagonal slash across the middle of the waveform:

Dynamicschapter03b.png

Distortion around zero-crossings

Notice how the mid-range now has a harsh overdriven sound to it. What we've done in drawing that shape is introduce a set of additional zero-crossings around the normal zero point in the waveform. The result of this will be nonlinearities in the mid-range signal whenever its sample amplitude comes close to zero. This simulates the properties of many solid state transistor distortion circuits (such as guitar pedals), which 'kink' the signal at specific intervals to generate high harmonics from the signal.

  • 'Reset' the 'Mid' waveshape by clicking the button, and turn up the gain~ slider representing the high frequencies. Draw a series of sharp peaks along the waveform opposite from the normal curve: Dynamicschapter03c.png Introducing random non-linearities

This type of waveshape creates a harsh distortion similar to the way digital distortion effects work. By introducing noise (random activity) into the waveshape, we create the potential for completely arbitrary distortion effects that resemble less an amplifier circuit than a 'digital' effects process.

[edit] Resetting and smoothing

  • Double-click any one of the patcher objects that are triggered by the 'Reset' button objects (resetlow, resetmid, resethi). Look at the contents of the subpatch.

The MSP peek~ object, you may recall, allows us to programmatically fill buffer~ objects with samples according to patcher logic in Max. The uzi object, when it receives a bang, sets up a chain of 8192 events that fill the appropriate buffer~ object with an ascending ramp of values from -1 to 1. When the lookup~ object uses this curve, the incoming signal gets passed unchanged.

  • Close this patcher and open any of the patcher objects that are triggered by the 'Smooth' button objects (smoothlow, smoothmid, smoothhi)

The smoothing subpatches, which are triggered whenever you release the mouse from drawing in the waveform~ object, triggers an uzi object that takes each sample currently in the buffer~ and averages it with its previous sample, creating a smoother curve than would be possible by freehand drawing.

  • Close the subpatch, and unlock the main tutorial patcher. Disconnect the waveform~ objects from the zl objects below them. Lock the patcher and draw some curves. You'll find that the distortion effects you create are much much more pronounced. If you want to, click the button objects that smooth the shapes manually. The more you click them, the more averaged out our waveshapes become.
  • In the middle of the tutorial patcher, click the message box that reads replace bass.aiff. Now the sound generated by our sampler will be that of an electric bass guitar. Play with the different waveshaping techniques we looked at earlier. If you like, modify the Cutoff frequency of the svf~ object with the number box in the middle of the patcher. This will let you choose where the midrange distortion effect is most prominent.

[edit] Summary

Waveshaping is an exciting synthesis technique that allows you to create complex timbres by running an oscillator through a lookup table; when used as a signal-processing technique with complex audio input, it can be used to simulate all manner of distortion effects. Because real-life amplifier distortion changes depending on the frequency content of the input signal, one way to simulate this distortion is to split an audio signal into several frequency bands and waveshape each one independently. While it's possible to scientifically measure and model the responses of different distortion circuits, freehand drawing in the waveform~ object allows us to experiment with different curves and hear them directly.