distort1

distort1 --  Modified hyperbolic tangent distortion.

Description

Implementation of modified hyperbolic tangent distortion. distort1 can be used to generate wave shaping distortion based on a modification of the tanh function.

         exp(asig * (pregain + shape1)) - exp(asig*(pregain+shape2))
  aout = -----------------------------------------------------------
         exp(asig*pregain)              + exp(-asig*pregain)
      

Syntax

ar distort1 asig [, ipregain] [, ipostgain] [, ishape1] [, ishape2]

Initialization

ipregain (optional, default=1) -- determines the amount of gain applied to the signal before waveshaping. A value of 1 gives slight distortion.

ipostgain (optional, default=1) -- determines the amount of gain applied to the signal after waveshaping.

ishape1 (optional, default=0) -- determines the shape of the positive part of the curve. A value of 0 gives a flat clip, small positive values give sloped shaping.

ishape2 (optional, default=0) -- determines the shape of the negative part of the curve.

Performance

asig - is the input signal.

All arguments except asig, were made optional in Csound version 3.52.

Examples

Here is an example of the distort1 opcode. It uses the files distort1.orc and distort1.sco.

Example 1. Example of the distort1 opcode.

/* distort1.orc */
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2

gadist  init 0
  
instr 1
  iamp    =        p4
  ifqc    =        cpspch(p5)
  asig    pluck iamp, ifqc, ifqc, 0, 1
  gadist  =       gadist + asig
endin
  
instr 50
  ipre    = p4
  ipost   = p5
  ishap1  = p6
  ishap2  = p7
  aout    distort1 gadist, ipre, ipost, ishap1, ishap2

  outs     aout, aout

  gadist  =        0
endin
/* distort1.orc */
        
/* distort1.sco */
;   Sta  Dur  Amp    Pitch
i1  0.0  3.0  10000  6.00
i1  0.5  2.5  10000  7.00
i1  1.0  2.0  10000  7.07
i1  1.5  1.5  10000  8.00
  
;   Sta  Dur  PreGain PostGain Shape1 Shape2
i50 0    3    2       1        0      0
e
/* distort1.sco */
        

Credits

Author: Hans Mikelson

December 1998 (New in Csound version 3.50)