Discussion:
[music-dsp] A good guitar distortion algorithm?
Christoph Jung
2003-12-01 10:36:00 UTC
Permalink
Hello everybody,

I'm working on a distortion algorithm for guitar with the aim of a future
DSP-implementation. My question is: What would be the right approach to
achieve aliasing-free and flexible guitar overdrive with efficient use
of the
processing power?

So far, I've experimented with several non-linear functions like tanh,
arctan, 1/x, etc.
but immediately encounter the problem of audible aliasing for higher gain
settings - no matter which function is in use. Pre- and post
equalization and
separation into frequency bands (distortion decreases with increasing
frequency) can be of help but don't give me full control of the harmonic
content of the output signal.

A second approach of mine was the implementation of chebyshev polynomial
waveshaping which has been occasionally mentioned in this mailing list.
On my opinion,
this method is fine for full control of harmonic additives but only
works with not too
complex input signals. Given a single note or a sine as input, my
version of polynomial
WS produces smooth overdrive with absolutely no aliasing. But as soon
as polyphonic
input signals occur, this method produces new tones ("intermodulation
partials") which
sound totally unmusical. This gets worse with increasing complexity of
the input signal.
If a full guitar chord is given as input signal, the harmonic output
consists of roughly nothing
else than noise - due to the huge amount of unwanted intermodulation
partials. Knowing that
polynomial WS works fine with sine-like signals, I could improve my
algorithm by dividing
the input signal into different frequency bands and applying waveshaping
individually. But
what if the input signal consists of two tones that lie very close to
each other? Do i need to
separate these tones with two different filters? Doesn't the complexity
of such an algorithm
exceed the computational capacity of a standard low-cost DSP?

In general, my question is: What would be the right way to achieve a
good sounding guitar
distortion algorithm? Should I continue with the polynomial WS? Or
should I concentrate on
the usage of non-linear functions (and maybe apply some oversampling for
filtering of
unwanted partials)? Or are there other ways? How does digital
"modelling" of guitar amplifiers
or stomp boxes work? Is there any expert in guitar effects processing
around here to give me a hint?

Thanks
Christoph
Paul Chana
2003-12-01 11:35:01 UTC
Permalink
we upsample to fs * 2 then distort, then down sample to fs. Works nicely
without (well i can't hear it) aliasing.

Paul
Subject: [music-dsp] A good guitar distortion algorithm?
Date: Mon, 01 Dec 2003 13:29:29 +0100
Hello everybody,
I'm working on a distortion algorithm for guitar with the aim of a future
DSP-implementation. My question is: What would be the right approach to
achieve aliasing-free and flexible guitar overdrive with efficient use of
the
processing power?
So far, I've experimented with several non-linear functions like tanh,
arctan, 1/x, etc.
but immediately encounter the problem of audible aliasing for higher gain
settings - no matter which function is in use. Pre- and post equalization
and
separation into frequency bands (distortion decreases with increasing
frequency) can be of help but don't give me full control of the harmonic
content of the output signal.
A second approach of mine was the implementation of chebyshev polynomial
waveshaping which has been occasionally mentioned in this mailing list. On
my opinion,
this method is fine for full control of harmonic additives but only works
with not too
complex input signals. Given a single note or a sine as input, my version
of polynomial
WS produces smooth overdrive with absolutely no aliasing. But as soon as
polyphonic
input signals occur, this method produces new tones ("intermodulation
partials") which
sound totally unmusical. This gets worse with increasing complexity of the
input signal.
If a full guitar chord is given as input signal, the harmonic output
consists of roughly nothing
else than noise - due to the huge amount of unwanted intermodulation
partials. Knowing that
polynomial WS works fine with sine-like signals, I could improve my
algorithm by dividing
the input signal into different frequency bands and applying waveshaping
individually. But
what if the input signal consists of two tones that lie very close to each
other? Do i need to
separate these tones with two different filters? Doesn't the complexity of
such an algorithm
exceed the computational capacity of a standard low-cost DSP?
In general, my question is: What would be the right way to achieve a good
sounding guitar
distortion algorithm? Should I continue with the polynomial WS? Or should I
concentrate on
the usage of non-linear functions (and maybe apply some oversampling for
filtering of
unwanted partials)? Or are there other ways? How does digital "modelling"
of guitar amplifiers
or stomp boxes work? Is there any expert in guitar effects processing
around here to give me a hint?
Thanks
Christoph
dupswapdrop -- the music-dsp mailing list and website: subscription info,
FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp
_________________________________________________________________
Tired of 56k? Get a FREE BT Broadband connection
http://www.msn.co.uk/specials/btbroadband
y***@arnet.com.ar
2003-12-01 13:22:00 UTC
Permalink
Cristoph:
What you are experiencing \"sounds\" like aliasing, oversimplified:
You bandlimit the signal and enter the DSP, then you distort the signal. This distorted
signal can\'t fit the limited bandwidth, so the spectrum is folded back onto itself, generating \"non musicallly related\" components.
There was a thread on this subjects a couple of years ago, search the archives.
You have to upsample to provide extra \"frequency headroom\" for the new components, and then downsample after processing to keep the same codec rate.
Some people do 4x, others claim 2x is enough.

BTW, many analog distortion boxes have diode clippers, I played for many years with a hi-gain amp that squared the signal. These generate LOTS of harmonics, but the extra ones are usually removed by a low-pass filter, unless you do want a fuzzy sound.
Different shaping functions will get you different harmonic content and different sound. Many guitarists prefer a tube-like non-linear function, others want a powerfull metal-like clipping. Some people prefer cutting basses before distortion (or more gain in treble), others prefer boosting the mids.

In the case of chords, there will always be intermodulation, it exists on analog boxes, depending on the amount of distortion you want. Unless you are playing perfect fifths (power chords), many intervals won\'t sound very pleasing to the standard ear with high distortion levels. You can reduce the harshness by low pass filtering after distortion.

__________________________________
Registrate desde http://servicios.arnet.com.ar/registracion/registracion.asp?origenid=9 y participá de todos los beneficios del Portal Arnet.
Nick
2003-12-01 13:30:01 UTC
Permalink
Hey Christoph,
I have recently done some research into the subject and have a great
article for you. Let me know if it helps (quite frankly it is a little
over my head so if you get it maybe you can share the knowledge). I
guess for that matter if anybody on the list can explain it, I would be
very appreciative.


http://www.tele.ntnu.no/akustikk/meetings/DAFx99/schattschneider.pdf

Good Luck,
Nick
Post by Christoph Jung
Hello everybody,
I'm working on a distortion algorithm for guitar with the aim of a
future
DSP-implementation. My question is: What would be the right approach to
achieve aliasing-free and flexible guitar overdrive with efficient use
of the
processing power?
So far, I've experimented with several non-linear functions like tanh,
arctan, 1/x, etc.
but immediately encounter the problem of audible aliasing for higher
gain
settings - no matter which function is in use. Pre- and post
equalization and
separation into frequency bands (distortion decreases with increasing
frequency) can be of help but don't give me full control of the
harmonic
content of the output signal.
A second approach of mine was the implementation of chebyshev
polynomial
waveshaping which has been occasionally mentioned in this mailing
list. On my opinion,
this method is fine for full control of harmonic additives but only
works with not too
complex input signals. Given a single note or a sine as input, my
version of polynomial
WS produces smooth overdrive with absolutely no aliasing. But as soon
as polyphonic
input signals occur, this method produces new tones ("intermodulation
partials") which
sound totally unmusical. This gets worse with increasing complexity of
the input signal.
If a full guitar chord is given as input signal, the harmonic output
consists of roughly nothing
else than noise - due to the huge amount of unwanted intermodulation
partials. Knowing that
polynomial WS works fine with sine-like signals, I could improve my
algorithm by dividing
the input signal into different frequency bands and applying
waveshaping individually. But
what if the input signal consists of two tones that lie very close to
each other? Do i need to
separate these tones with two different filters? Doesn't the
complexity of such an algorithm
exceed the computational capacity of a standard low-cost DSP?
In general, my question is: What would be the right way to achieve a
good sounding guitar
distortion algorithm? Should I continue with the polynomial WS? Or
should I concentrate on
the usage of non-linear functions (and maybe apply some oversampling
for filtering of
unwanted partials)? Or are there other ways? How does digital
"modelling" of guitar amplifiers
or stomp boxes work? Is there any expert in guitar effects processing
around here to give me a hint?
Thanks
Christoph
dupswapdrop -- the music-dsp mailing list and website: subscription
info, FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp
Nigel Redmon
2003-12-01 22:17:00 UTC
Permalink
Given a single note or a sine as input, my version of polynomial
WS produces smooth overdrive with absolutely no aliasing.
Given a limited-bandwidth input and the degree of your polynomial, yes,
you can ensure no aliasing... ***BUT***... you are probably using a
section of the polynomial, with hard clipping if the input amplitude
exceeds the bounds of that section. In that case, you won't have the
nice bounds on frequencies added by the non-linear processing, so you
will have liasising. To minimize aliasing you need to oversample before
the nonlinear processing--"how much" depends on your tolerance of
aliasing. (For instance, the higher the input gain, the more the
aliasing, with the distortion harmonics masking aliasing to a
degree.... but the aliasing is still very apparent when you bend
notes--especially purer tones like string harmonics--and the aliasing
tones bend in the wrong direction :-P )

Beyond that, people don't play guitar straight through hifi tube amps,
so obviously tube simulation isn't going to be nearly enough. You need
to look at tone filtering before and after the tube distortion section.
The "after" part will give you linear post-tube tone control, so it's
pretty intuitive what to expect there. The "before" part is less
intuitive, but with a little thought you can figure out some
guidelines: If you go for heavy distortion (high gain into the "tube"),
large low-frequency components will give a flatulent quality to the
sound (like over pumping a woofer so that it hits a resistance in your
speaker cabinet)--most people don't like this ;-) So, for high-gain amp
simulation for those screaming leads, you'd want to roll off the bass
before the tube, and bring it back up as needed after the tube.
Similarly, for high gain leads you probably want to accentuate the mids
and have less high-end hash, so you'd probably roll off the highs
too--basically go for a bandpass response pre-tube. Lower-gain
distortion usually requires less drastic filtering.
Jim Wintermyre
2003-12-02 00:44:00 UTC
Permalink
Post by Nigel Redmon
Given a single note or a sine as input, my version of polynomial
WS produces smooth overdrive with absolutely no aliasing.
Given a limited-bandwidth input and the degree of your polynomial,
yes, you can ensure no aliasing... ***BUT***... you are probably
using a section of the polynomial, with hard clipping if the input
amplitude exceeds the bounds of that section. In that case, you
won't have the nice bounds on frequencies added by the non-linear
processing, so you will have liasising.
^^^^^^^^^^

Would that be "email aliasing"?

:-)

Jim
jeffrey traer bernstein
2003-12-02 06:22:00 UTC
Permalink
People ask about this about once a month so it seems perhaps an FAQ is
in order.
Starting from the beginning, where all good stories begin... For you
consideration:

Guitar distortion basically stems form overdriven amplifiers and
nonlinearities present in the components used (maybe tubes or the
transformer or diodes). The signal is clipped and all sorts of stuff not
present in the original signal appears. Though not an accurate
representation of the original signal, this new distorted signal tends
to rock way more.

So how does one make this distortion digitally?

This is normally accomplished through a waveshaping. We take the
original signal between -1 and 1 and map it, using a mathematical
function to a new signal between -1 and 1. This is what is called a
memoryless nonlinearity. Memoryless because the next sample out has
nothing to do with any of the other previous samples, and nonlinear
adding to signals together and obtaining the result is not the same as
obtain the results separately for each signal and then adding them
together. So the higher your amplitude going into the waveshaper the
more clipping and the more distortion.

There is hard clipping and soft clipping. Not easy to explain without
pictures but hard clipping means you chop off everything above 1 and
below -1, soft clipper has a smoother transition between the probably
linear middle region and the clipped parts. for example:

a 3rd order polynomial
f(x) =
-2/3, x < -1
x - x^3/3, -1 <= x <= 1
2/3, x > 1

or maybe arctan, or tanh (but polynomials are faster to calculate).

These functions are odd i.e. they are symmetrically f(-x) = -f(x), they
only generate odd harmonics (take to this to the limit and you get a
square wave which is a fundamental and all the odd harmonics). Breaking
this symmetry in any way will add some even harmonics, tubes will create
some even harmonics and as will things like pickups that aren't placed
symmetrically like in the fender rhodes.

Easy ways to make your function asymmetrical are to add a DC offset into
the signal before the nonlinearity so e.g. the top is clipped more than
the bottom, or you could add an even function like a square to your
function.This will change the duty cycle of your waveform i.e. e.g. the
first peak might take up more of the period than second peak. and means
the higher your input signal the more unequal the duty cycle is, i.e.
duty cycle modulation as a function of amplitude.

Now you probably want to filter the signal before and after the
nonlinearity because you want specific frequencies to be distorted more
than others. Distorted low frequencies can sound "flatulent" and
distorted high frequencies sound really "fuzzy". Most likely what you
want is a band pass or high pass before and lowpass after adjusted to taste.

Problems with this:

Intermodulation,
basically beating of the sum and/or difference between all the
frequencies and harmonics you now have in your signal. Mostly apparent
when you play a chord. This happens in the analog domain too and your
filters will mostly take care of this.

Aliasing,
you may have introduced some frequencies higher than the nyquist. You it
hear mostly when you slide between notes or bend a note (you hear some
frequencies bend or slide in the opposite direction as the frequencies
wrap around). This actually depends on the order of your polynomial. If
your input signal contains no frequencies over fs/2n you can apply an
n-th order polynomial without aliasing.

If your waveshaping function is a polynomial you can bandlimit you
signal in a parallel filter bank with lopass filters with cutoffs at
fs/2n and apply up to an n-th order polynomial to you bandlimited
signals then sum the result and avoid all the aliasing! You can control
the gain of each polynomial term to make any desired polynomial waveshaper.

The problem is that usually you would use a polynomial section and then
clip the after the bounds of the section like in the 3rd order
polynomial example above. This means you no longer have a nice neat
polynomial and will introduce a bunch of aliasing. The solution to this
is to oversample i.e. stick zeros between the samples, bandlimit to
original fs/2, distort, bandlimit to original fs/2, then downsample by
tossing out every other sample. This gives you some space to alias and
then throws out the bad stuff. It won't completely eliminate the
aliasing but will get rid of some of it. How much you oversample is up
to you. People mostly seem to think 2 times oversampling is sufficient
as anything left is obscured by the distortion anyway. Oversampling
tends to be computationally expensive...

to sum up, you probably want:

pre-gain > pre-eq (bandpass) > nonlinear waveshaping function > post-eq
(lowpass) > post-gain
and you may wish to eliminate aliasing using the bandlimited polynomials
or by oversampling.
Nigel Redmon
2003-12-02 06:58:00 UTC
Permalink
Post by jeffrey traer bernstein
pre-gain > pre-eq (bandpass) > nonlinear waveshaping function >
post-eq (lowpass) > post-gain
Normally, pre-gain should come after the pre-eq; that gain could be
something like 100dB for guitar distortion, which would likely make
your pre-eq a clipper instead of the waveshaper :-(
jeffrey traer bernstein
2003-12-02 15:04:01 UTC
Permalink
I meant the pre-eq to be a pre-waveshapping bandpass filter i.e. LTI,
the gain and filter are commutable.
Post by Nigel Redmon
Post by jeffrey traer bernstein
pre-gain > pre-eq (bandpass) > nonlinear waveshaping function >
post-eq (lowpass) > post-gain
Normally, pre-gain should come after the pre-eq; that gain could be
something like 100dB for guitar distortion, which would likely make
your pre-eq a clipper instead of the waveshaper :-(
dupswapdrop -- the music-dsp mailing list and website: subscription
info, FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp
Nigel Redmon
2003-12-02 15:45:01 UTC
Permalink
I edited for brevity and lost the part about fixed point, sorry. That
is, the order doesn't matter for floating point, but you'll get nailed
that way in fixed point, so I was suggesting the edited order for a faq
to handle the general case.
Post by jeffrey traer bernstein
I meant the pre-eq to be a pre-waveshapping bandpass filter i.e. LTI,
the gain and filter are commutable.
Post by Nigel Redmon
Post by jeffrey traer bernstein
pre-gain > pre-eq (bandpass) > nonlinear waveshaping function >
post-eq (lowpass) > post-gain
Normally, pre-gain should come after the pre-eq; that gain could be
something like 100dB for guitar distortion, which would likely make
your pre-eq a clipper instead of the waveshaper :-(
dupswapdrop -- the music-dsp mailing list and website: subscription
info, FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp
dupswapdrop -- the music-dsp mailing list and website: subscription
info, FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp
jeffrey traer bernstein
2003-12-02 18:22:00 UTC
Permalink
New and improved with stage order switched as per nigel's suggestion
since it doesn't mater floating point but does fixed...
Any other suggestion before I fire it off to mr. repetto?


Guitar distortion basically stems form overdriven amplifiers and
nonlinearities present in the components used (maybe tubes or the
transformer or diodes). The signal is clipped and all sorts of stuff not
present in the original signal appears. Though not an accurate
representation of the original signal, this new distorted signal tends
to rock way more.

So how does one make this distortion digitally?

This is normally accomplished through a waveshaping. We take the
original signal between -1 and 1 and map it, using a mathematical
function to a new signal between -1 and 1. This is what is called a
memoryless nonlinearity. Memoryless because the next sample out has
nothing to do with any of the other previous samples, and nonlinear
adding to signals together and obtaining the result is not the same as
obtain the results separately for each signal and then adding them
together. So the higher your amplitude going into the waveshaper the
more clipping and the more distortion.

There is hard clipping and soft clipping. Not easy to explain without
pictures but hard clipping means you chop off everything above 1 and
below -1, soft clipper has a smoother transition between the probably
linear middle region and the clipped parts. for example:

a 3rd order polynomial
f(x) =
-2/3, x < -1
x - x3/3, -1 <= x <= 1
2/3, x > 1

or maybe arctan, or tanh (but polynomials are faster to calculate).

These functions are odd i.e. they are symmetrically f(-x) = -f(x), they
only generate odd harmonics (take to this to the limit and you get a
square wave which is a fundamental and all the odd harmonics). Breaking
this symmetry in any way will add some even harmonics, tubes will create
some even harmonics and as will things like pickups that aren't placed
symmetrically like in the fender rhodes.
Easy ways to make your function asymmetrical are to add a DC offset
into the signal before the nonlinearity so e.g. the top is clipped more
than the bottom, or you could add an even function like a square to your
function.This will change the duty cycle of your waveform i.e. e.g. the
first peak might take up more of the period than second peak. and means
the higher your input signal the more unequal the duty cycle is, i.e.
duty cycle modulation as a function of amplitude.

Now you probably want to filter the signal before and after the
nonlinearity because you want specific frequencies to be distorted more
than others. Distorted low frequencies can sound "flatulent" and
distorted high frequencies sound really "fuzzy". Most likely what you
want is a band pass or high pass before and lowpass after adjusted to
taste.

Problems with this:

Intermodulation,
basically beating of the sum and/or difference between all the
frequencies and harmonics you now have in your signal. Mostly apparent
when you play a chord. This happens in the analog domain too and your
filters will mostly take care of this.

Aliasing,
you may have introduced some frequencies higher than the nyquist. You it
hear mostly when you slide between notes or bend a note (you hear some
frequencies bend or slide in the opposite direction as the frequencies
wrap around). This actually depends on the order of your polynomial. If
your input signal contains no frequencies over fs/2n you can apply an
n-th order polynomial without aliasing.

If your waveshaping function is a polynomial you can bandlimit you
signal in a parallel filter bank with lopass filters with cutoffs at
fs/2n and apply up to an n-th order polynomial to your bandlimited
signals then sum the result and avoid all the aliasing! You can control
the gain of each polynomial term to make any desired polynomial waveshaper.
The problem is that usually you would use a polynomial section and then
clip the after the bounds of the section like in the 3rd order
polynomial example above. This means you no longer have a nice neat
polynomial and will introduce a bunch of aliasing. The solution to this
is to oversample i.e. stick zeros between the samples, bandlimit to
original fs/2, distort, bandlimit to original fs/2, then downsample by
tossing out every other sample. This gives you some space to alias and
then throws out the bad stuff. It won't completely eliminate the
aliasing but will get rid of some of it. How much you oversample is up
to you. People mostly seem to think 2 times oversampling is sufficient
as anything left is obscured by the distortion anyway. Oversampling
tends to be computationally expensive...

to sum up, you probably want:

pre-eq (bandpass) > pre-gain > nonlinear waveshaping function > post-eq
(lowpass) > post-gain
and you may wish to eliminate aliasing using the bandlimited polynomials
or by oversampling.
Smartelectronix - Bram de Jong
2003-12-02 20:22:00 UTC
Permalink
Post by jeffrey traer bernstein
New and improved with stage order switched as per nigel's suggestion
since it doesn't mater floating point but does fixed...
Any other suggestion before I fire it off to mr. repetto?
you might want to note that "emulating" tubes is more difficult and point to
http://www.simulanalog.org/
who have some nice articles about it.

While simple waveshaping is nonlinear and memoryless, tubes *do* have
"memory".

cheerio,


- bram
--
http://www.smartelectronix.com
http://www.musicdsp.org
http://www.ghentsessions.be
mobile: +32486157768
MSN/ICQ : ask me
Loading...