1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

How do you construct a Waveshaper in Reaktor

Discussion in 'Building With Reaktor' started by Soundkage, Apr 16, 2007.

Thread Status:
Not open for further replies.
  1. Soundkage

    Soundkage New Member

    Messages:
    9
    Hi I'm currently doing honours in Music Technology and i have to do a presentation on waveshaping and i need some help regarding the construction of a waveshaper in Reaktor 4. It's my first time using this program and i have been trying to look for some sort of documentation that can help me, but have had no luck so far. If someone could give me a link or even some info regarding this topic it would be greatly appreciated, thank you :D
     
  2. zonder

    zonder NI Product Owner

    Messages:
    13
    you can use an audio table to map input amplitudes to different output values; you can even draw the mapping function by hand. that's the only method i can claim to have used successfully. have a look at socrates4 by Ernest Meyer if you're lookin for a unique approach to a waveshaping algorithm
     
  3. Soundkage

    Soundkage New Member

    Messages:
    9
    thanx Zonder thats brilliant I'll give it a go
     
  4. CList

    CList Moderator

    Messages:
    3,299
    In theory, most math functions applied to a signal are "wave shapers" because as the input cycles, so the output will cycle. Absolute value |x|, for example, is a very simple wave shaping function all by itself.
    out = |in|

    ...though the output will always be positive, you might want to shift and scale the output so that it's in the same -1...+1 range as the input like so...
    out = (|in| * 2) - 1

    A formula for a simple "parabolic shaper" would be:
    out = in * (4 - |in|) * 0.25

    You can play with all kinds of math functions and look at different results. E.g. ;
    out = in * in * (4 - |in|) * 0.25

    Another parabolic shaper is this (see gif):
    out = ArcTan(4 * in) * 4

    ...and in fact all of the trig functions (cos, sin, etc) can be interesting wave shapers. A fun one (used as one of the waveshapers in the Access Virus) is:

    out = sin(x * in)

    Where x is some constant from .25 to 4. Try it with a knob and check out the results.

    ...or use compare modules for shapers with more non-linearities. A one-sided clipper-type of thing would be:
    out = ((in > .25) * 1) + ((in < .25) * in)

    ...where "in > .25" would be the true output of the compare module and would be either 1 or 0, and "in <.25" would be the false output and would also be 1 or 0.

    A two channel scope (included in attached zip file) is a good choice for comparing the input to the output.

    I agree though, the audio table is nice because it allows you to draw the input to output transfer function, but it's also more CPU and will suffer from worse aliasing (due to the steps involved in the table) than the math functions.

    - CList
     

    Attached Files:

  5. Soundkage

    Soundkage New Member

    Messages:
    9
    Thanx for all the info it's been a huge help, I really appreciate it :D
     
  6. Soundkage

    Soundkage New Member

    Messages:
    9
    Hey guys I've been playing around with the info you have given me and it has been a great help I just have some questions about some of the operations. I'm struggling with what might seem mundane concepts, the first being what part of the wave do the breakpoints control? are they controlling specific harmonics/partials above or below certain points? and do the slope controls affect mainly the amplitude of the soundwave? or am I getting totally confused? :S.
     
  7. CList

    CList Moderator

    Messages:
    3,299
    I think you're getting totally confused :)

    The best thing to do is to look at it on the scope. The "bigger" the wave is vertically - the further it gets away from 0 at any given point, the greater the audible amplitude.

    As for shaping affecting partials - the math for that is very complex. In 99% of the transformations, there is no one-for-one between any of the shaping parameters and the amplitude this or that partial. Remember that if the input wave is a sine wave, then there is only the fundemental partial - there are no higher-order partials, so here you are adding overtones as you shape it in all cases. If the input is a sawtooth then you might be adding some and taking some away. You'd have to do a fourier transform on it to add/remove a set of specific partials and that's not what waveshaping does. In general waveshaping is used for distorting waves and little attention is paid to what or how the partials or changing - except in a very broad sense like; "this adds high-order odd harmonics to loud signals, but leaves quiet signals un-affected". There's nothing "specific" about it.

    - CList
     
  8. Soundkage

    Soundkage New Member

    Messages:
    9
    forgive me I feel that I'm overthinking things here :confused: , so it doesn't matter what the breakpoints or slopes are controling as long as you create a more abrasive sound by changing either the amplitude, frequency or both without changing the pitch, using some math functions? I think I need a vacation.
     
  9. CList

    CList Moderator

    Messages:
    3,299
    I'm not sure what you're imagining when you use words like "frequency" and "pitch". You can't (easily) look at a formula for a wave shaper and make determinations about the effect on frequency or pitch since those effects depend on the incoming signal.

    Additionally, "pitch" and "frequency" can be used interchangeably when talking about the fundamental frequency/harmonic, but "frequency" can also be used to talk about the harmonic spectra (aka "overtones"), and if that's what you mean, then you should use the word "overtones".

    Let's take a really simple case, let's say you have the following function:
    out = (in > 0) ? 1 : -1
    (if input is >0, out = 1, otherwise out = -1)

    If you send a sine wave into this, then the sines wave will turn into a square wave. The fundamental pitch will remain unchanged, the fundamental frequency (which is really the same thing) will remain unchanged. The amplitude of this or that sample might change and the overall "power" of the wave as a whole will change, but (assuming the incoming sine wave is in the range -1 / +1) the "amplitude" as a measure of the peak-to-peak range of the wave will not change. The important thing, however, is that a sine wave has only one "frequency" - the fundamental, while the square wave has a lot of frequencies (the overtones), but still only one fundamental frequency. This can be easily seen in a spectrograph of each one.

    Now if you run a sawtooth wave into that same waveshaper, you'll get the same output. So the harmonic content will change *in a different way* but again, the pitch and *fundamental* frequency will remain the same. Do some searching on the web of "harmonic content of sine sawtooth square waves" if you aren't familiar with this stuff, I'm sure you'll find some sites out there that describe this.

    Now lets say you send in a wave composed of two sine waves added together in equal amounts at different frequencies/pitches. There is no one fundamental here. When it comes out it'll be just like two square waves added together with the same "pitches" as the sine waves, but the harmonic content and overtones will change.

    Getting from the mathematical representation of the above transform function to a math function that could tell you how the harmonic content of an incoming wave will change would require some hardcore math skills that I and 99.99% of the rest of the reaktor community do not possess. That's like graduate level mathematics. You can't really spend too much time worrying about it. You can measure the old and new harmonic spectra on a spectral meter, but doing the math to get the spectra transform isn't something you should worry too much about - because it's going to be different depending on what kinds of waves are coming into the shaper!

    Just remember that you are changing the amplitude and "harmonic content" when you transform the shape of a wave, but you can't really say: "reshaping in this way will change the pitch/frequency like so". Generically speaking, waveshaping has nothing to do with pitch or frequency-shifting. If, OTOH, you know that wave you are shaping will always be, say, a sawtooth wave, then you could build something that will always double or triple the frequency, but that's not a generic "waveshaping" application and usually not what people mean when they talk about it.

    - CList
     
  10. m3m

    m3m NI Product Owner

    Messages:
    536
    Little waveshaper test

    Chris, thanks for the formulas - I'm going to enjoy playing with them later! Inspired by the list (by the 'List) I made a waveshaper instrument in which the summed output of the polyphonic voices is shaped using the formula:

    out = in * |in|

    A screenshot's attached...

    The sound source is a Sine oscillator. When you play a single note, it's obvious that harmonics are added to the sinusoidal input, and the result sounds quite musical. But when you start to play chords, the nature of the extra harmonics immediately starts to get more complex and less musical - dirtier - I suppose because (as in the case of an overdrive pedal) the harmonic content of the input is getting more complex, and harmonic series are being added to harmonics, so the result is harmonically more dissonant...

    I've put an MP3 up at

    http://www.museumoftechno.org/reaktor/waveshaper.mp3

    if you want to have a listen. Putting a "micro scope" macro in the structure showed the effect of the waveshaping on the sine wave.

    OK, back to CList's list... all the best

    Dave
     

    Attached Files:

  11. m3m

    m3m NI Product Owner

    Messages:
    536
    More waveshaping

    Hello

    I couldn't resist a bit more waveshaping... what I love about these things is the way the output gets more crunchy the more complex the harmonics in the input, so that when you put one after an audio voice combiner and start playing chords into it, the chords become dirty where single notes were harmonically pristine.

    So here's a little waveshaper that raises the value at its input to a power (which you specify). It uses a rectify/sign module so that the input to the power module's always +ve, and then multiplies the result by the sign of the input value, so that the output is bipolar. The screenshots show (1) the whole instrument, (2) a simple version of the shaper, then (3) a version with LFO control of the power value - which means the amount and flavour of distortion modulates over time. Playing a mixture of solo notes and chords with gentle, modulating distortion can sound very pretty!

    Dave
     

    Attached Files:

    Last edited: May 7, 2007
  12. kid_sputnik

    kid_sputnik NI Product Owner

    Messages:
    3,552
    to add to what clist said - remember that most audio work, including waveshaping is done in the time domain, and not the frequency domain. this is how audio works. frequency domain involves FFTs or similar, and is always an approximation of the actual waveform.

    anyways, my point is that changes to amplitude-over-time (waveform) will change the frequency content, and viceversa when working in the freq domain. but, as clist said, the frequency/harmionic alterations are not simple, even if the amplitude changes are.
     
  13. bachus

    bachus New Member

    Messages:
    19
    Noob questions here.
    Why would a table lookup cost more than FPU calls?
    Could you not interpolate the table values to avoid aliasing?

    I was planning to do just this this using Simpson's rule. Is the overhead just out of the question? Couldntt you interpolate the table once each time it was drawn/edited ?

    BTW thanks, CList, EventWatcher04 is wonderful!

    Edit:
    Last question made sensible.
     
  14. Soundkage

    Soundkage New Member

    Messages:
    9
    Whoa thanx guys hehe I feel like such an idiot but hey we all have to start somewhere :lol: I really appreciate all the help and I have a much clearer idea of what waveshaping is all about and how it functions, your simplified explanations cleared the mud in my head hehe.

    I have been able to create a waveshaper and I am so impressed with the endless possibilities that Reaktor provides. Once I started getting into it I found that it isn't as overwhelming as I had thought, with a bit of logical thinking and patience (and a forum to help clear things up for you haha) it's a lot of fun :D
     
Thread Status:
Not open for further replies.